Skip to content

Commit c963bf7

Browse files
committed
Started analysis for HTTP/2.
Signed-off-by: Simone Bordet <[email protected]>
1 parent 4567627 commit c963bf7

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

jetty-core/jetty-http2/jetty-http2-server/src/main/java/org/eclipse/jetty/http2/server/internal/HttpStreamOverHTTP2.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public void send(MetaData.Request request, MetaData.Response response, boolean l
306306
sendContent(request, content, last, callback);
307307
}
308308

309-
private void sendHeaders(MetaData.Request request, MetaData.Response response, ByteBuffer content, boolean last, Callback callback)
309+
private void sendHeaders(MetaData.Request request, MetaData.Response response, ByteBuffer byteBuffer, boolean last, Callback callback)
310310
{
311311
_responseMetaData = response;
312312

@@ -315,7 +315,9 @@ private void sendHeaders(MetaData.Request request, MetaData.Response response, B
315315
HeadersFrame trailersFrame = null;
316316

317317
boolean isHeadRequest = HttpMethod.HEAD.is(request.getMethod());
318-
boolean hasContent = BufferUtil.hasContent(content) && !isHeadRequest;
318+
Object content = byteBuffer == Content.Sink.TRANSFER ? response.getContentSource() : byteBuffer;
319+
long contentLength = byteBuffer == Content.Sink.TRANSFER ? response.getContentSource().getLength() : BufferUtil.length(byteBuffer);
320+
boolean hasContent = contentLength > 0 && !isHeadRequest;
319321
int streamId = _stream.getId();
320322
if (HttpStatus.isInterim(response.getStatus()))
321323
{
@@ -334,20 +336,19 @@ private void sendHeaders(MetaData.Request request, MetaData.Response response, B
334336
committed = true;
335337
if (last)
336338
{
337-
long realContentLength = BufferUtil.length(content);
338-
long contentLength = response.getContentLength();
339-
if (contentLength < 0)
339+
long responseContentLength = response.getContentLength();
340+
if (responseContentLength < 0)
340341
{
341342
_responseMetaData = new MetaData.Response(
342343
response.getStatus(), response.getReason(), response.getHttpVersion(),
343344
response.getHttpFields(),
344-
realContentLength,
345+
contentLength,
345346
response.getTrailersSupplier()
346347
);
347348
}
348-
else if (hasContent && contentLength != realContentLength)
349+
else if (hasContent && responseContentLength != contentLength)
349350
{
350-
callback.failed(new HttpException.RuntimeException(HttpStatus.INTERNAL_SERVER_ERROR_500, String.format("Incorrect Content-Length %d!=%d", contentLength, realContentLength)));
351+
callback.failed(new HttpException.RuntimeException(HttpStatus.INTERNAL_SERVER_ERROR_500, String.format("Incorrect Content-Length %d!=%d", responseContentLength, contentLength)));
351352
return;
352353
}
353354
}
@@ -360,17 +361,17 @@ else if (hasContent && contentLength != realContentLength)
360361
HttpFields trailers = retrieveTrailers();
361362
if (trailers == null)
362363
{
363-
dataFrame = new DataFrame(streamId, content, true);
364+
dataFrame = new DataFrame(streamId, byteBuffer, true);
364365
}
365366
else
366367
{
367-
dataFrame = new DataFrame(streamId, content, false);
368+
dataFrame = new DataFrame(streamId, byteBuffer, false);
368369
trailersFrame = new HeadersFrame(streamId, new MetaData(HttpVersion.HTTP_2, trailers), null, true);
369370
}
370371
}
371372
else
372373
{
373-
dataFrame = new DataFrame(streamId, content, false);
374+
dataFrame = new DataFrame(streamId, byteBuffer, false);
374375
}
375376
}
376377
else

jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SocketChannelEndPoint.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ protected void onIdleExpired(TimeoutException timeout)
9797
super.onIdleExpired(timeout);
9898
}
9999

100+
// TODO: override onFail()
101+
100102
@Override
101103
public SocketAddress getRemoteSocketAddress()
102104
{

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpChannelState.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,7 @@ public void setTrailersSupplier(Supplier<HttpFields> trailers)
12561256
@Override
12571257
public void write(boolean last, ByteBuffer content, Callback callback)
12581258
{
1259-
long length = BufferUtil.length(content);
1260-
if (length == 0 && _source != null)
1261-
length = _source.getLength();
1259+
long length = content == Content.Sink.TRANSFER ? _source.getLength() : BufferUtil.length(content);
12621260

12631261
HttpChannelState httpChannelState;
12641262
HttpStream stream;

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/HttpConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ public Action process() throws Exception
945945
default:
946946
Content.Source source = _info.getContentSource();
947947
if (source != null)
948-
Content.copy(source, source.getLength(), _lastContent, getEndPoint(), this);
948+
Content.transfer(source, source.getLength(), getEndPoint(), this);
949949
else
950950
succeeded();
951951
}

jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport/ResponseContentSourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public boolean handle(Request request, Response response, Callback callback)
6464

6565
ContentResponse response = new CompletableResponseListener(client.newRequest(newURI(transportType)), contentLength)
6666
.send()
67-
.get(5, TimeUnit.SECONDS);
67+
.get(555, TimeUnit.SECONDS);
6868

6969
assertEquals(HttpStatus.OK_200, response.getStatus());
7070
assertEquals(contentLength, response.getContent().length);

0 commit comments

Comments
 (0)