Skip to content

Commit

Permalink
Fixes #7608 - Jetty-12 MetaData cleanup needed (#9618)
Browse files Browse the repository at this point in the history
* Removed unnecessary constructors from MetaData, MetaData.Request and MetaData.Response.
* Removed MetaData.Request.getURIString() (available as getHttpURI().toString()).
* Renamed MetaData.getFields() -> getHttpFields(), as they can be headers or trailers.
* Renamed MetaData.Request.getURI() -> getHttpURI().
* Normalized handling of contentLength, now always -1 (rather than Long.MIN_VALUE) if unknown.
* Permutated MetaData.Response constructor parameters to be consistent with MetaData.Request.
* MetaData.Request's method and httpURI must be non-null.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Apr 7, 2023
1 parent 110e092 commit 744b37f
Show file tree
Hide file tree
Showing 72 changed files with 381 additions and 378 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void onHeaders(Stream stream, HeadersFrame frame)
}
else
{
System.getLogger("http2").log(INFO, "Received trailers {0}", metaData.getFields());
System.getLogger("http2").log(INFO, "Received trailers {0}", metaData.getHttpFields());
}
}

Expand Down Expand Up @@ -328,9 +328,9 @@ public Stream.Listener onPush(Stream pushedStream, PushPromiseFrame frame)
// The "request" the client would make for the pushed resource.
MetaData.Request pushedRequest = frame.getMetaData();
// The pushed "request" URI.
HttpURI pushedURI = pushedRequest.getURI();
HttpURI pushedURI = pushedRequest.getHttpURI();
// The pushed "request" headers.
HttpFields pushedRequestHeaders = pushedRequest.getFields();
HttpFields pushedRequestHeaders = pushedRequest.getHttpFields();

// If needed, retrieve the primary stream that triggered the push.
Stream primaryStream = pushedStream.getSession().getStream(frame.getStreamId());
Expand All @@ -347,7 +347,7 @@ public void onHeaders(Stream stream, HeadersFrame frame)
if (metaData.isResponse())
{
// The pushed "response" headers.
HttpFields pushedResponseHeaders = metaData.getFields();
HttpFields pushedResponseHeaders = metaData.getHttpFields();

// Typically a pushed stream has data, so demand for data.
stream.demand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void respond(Stream stream, MetaData.Request request)
// Prepare the response HEADERS frame.

// The response HTTP status and HTTP headers.
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, HttpFields.EMPTY);
MetaData.Response response = new MetaData.Response(HttpStatus.OK_200, null, HttpVersion.HTTP_2, HttpFields.EMPTY);

if (HttpMethod.GET.is(request.getMethod()))
{
Expand Down Expand Up @@ -322,17 +322,17 @@ public void onSettings(Session session, SettingsFrame frame)
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
{
MetaData.Request request = (MetaData.Request)frame.getMetaData();
if (pushEnabled && request.getURIString().endsWith("/index.html"))
if (pushEnabled && request.getHttpURI().toString().endsWith("/index.html"))
{
// Push the favicon.
HttpURI pushedURI = HttpURI.build(request.getURI()).path("/favicon.ico");
HttpURI pushedURI = HttpURI.build(request.getHttpURI()).path("/favicon.ico");
MetaData.Request pushedRequest = new MetaData.Request("GET", pushedURI, HttpVersion.HTTP_2, HttpFields.EMPTY);
PushPromiseFrame promiseFrame = new PushPromiseFrame(stream.getId(), 0, pushedRequest);
stream.push(promiseFrame, null)
.thenCompose(pushedStream ->
{
// Send the favicon "response".
MetaData.Response pushedResponse = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, HttpFields.EMPTY);
MetaData.Response pushedResponse = new MetaData.Response(HttpStatus.OK_200, null, HttpVersion.HTTP_2, HttpFields.EMPTY);
return pushedStream.headers(new HeadersFrame(pushedStream.getId(), pushedResponse, null, false))
.thenCompose(pushed -> pushed.data(new DataFrame(pushed.getId(), faviconBuffer, true)));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void respond(Stream.Server stream, MetaData.Request request)
// Prepare the response HEADERS frame.

// The response HTTP status and HTTP headers.
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_3, HttpStatus.OK_200, HttpFields.EMPTY);
MetaData.Response response = new MetaData.Response(HttpStatus.OK_200, null, HttpVersion.HTTP_3, HttpFields.EMPTY);

if (HttpMethod.GET.is(request.getMethod()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onHeaders()
{
String pathQuery = URIUtil.addPathQuery(_path, _query);
// TODO https?
MetaData.Request request = new MetaData.Request(_method, HttpScheme.HTTP.asString(), hostPort, pathQuery, HttpVersion.fromString(_version), _headers, Long.MIN_VALUE);
MetaData.Request request = new MetaData.Request(_method, HttpScheme.HTTP.asString(), hostPort, pathQuery, HttpVersion.fromString(_version), _headers, -1);
Runnable task = _httpChannel.onRequest(request);
_allHeaders.forEach(field -> _httpChannel.getRequest().setAttribute(field.getName(), field.getValue()));
// TODO: here we just execute the task.
Expand Down Expand Up @@ -258,7 +258,7 @@ private void commit(MetaData.Response info, boolean head, boolean last, ByteBuff

_committed = true;

boolean shutdown = _shutdown = info.getFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString());
boolean shutdown = _shutdown = info.getHttpFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString());

ByteBufferPool bufferPool = _generator.getByteBufferPool();
ByteBufferPool.Accumulator accumulator = new ByteBufferPool.Accumulator();
Expand Down Expand Up @@ -290,7 +290,7 @@ private void commit(MetaData.Response info, boolean head, boolean last, ByteBuff

private void generateResponseHeaders(ByteBufferPool.Accumulator accumulator, MetaData.Response info)
{
_generator.generateResponseHeaders(accumulator, _id, info.getStatus(), info.getReason(), info.getFields());
_generator.generateResponseHeaders(accumulator, _id, info.getStatus(), info.getReason(), info.getHttpFields());
}

private void generateResponseContent(ByteBufferPool.Accumulator accumulator, boolean last, ByteBuffer buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public class HttpGenerator
public static final boolean __STRICT = Boolean.getBoolean("org.eclipse.jetty.http.HttpGenerator.STRICT");

private static final byte[] __colon_space = new byte[]{':', ' '};
public static final MetaData.Response CONTINUE_100_INFO = new MetaData.Response(HttpVersion.HTTP_1_1, 100, null, HttpFields.EMPTY, -1);
public static final MetaData.Response PROGRESS_102_INFO = new MetaData.Response(HttpVersion.HTTP_1_1, 102, null, HttpFields.EMPTY, -1);
public static final MetaData.Response CONTINUE_100_INFO = new MetaData.Response(100, null, HttpVersion.HTTP_1_1, HttpFields.EMPTY);
public static final MetaData.Response PROGRESS_102_INFO = new MetaData.Response(102, null, HttpVersion.HTTP_1_1, HttpFields.EMPTY);
public static final MetaData.Response RESPONSE_400_INFO =
new MetaData.Response(HttpVersion.HTTP_1_1, HttpStatus.BAD_REQUEST_400, null, HttpFields.build().add(HttpFields.CONNECTION_CLOSE), 0);
new MetaData.Response(HttpStatus.BAD_REQUEST_400, null, HttpVersion.HTTP_1_1, HttpFields.build().add(HttpFields.CONNECTION_CLOSE), 0);
public static final MetaData.Response RESPONSE_500_INFO =
new MetaData.Response(HttpVersion.HTTP_1_1, INTERNAL_SERVER_ERROR_500, null, HttpFields.build().add(HttpFields.CONNECTION_CLOSE), 0);
new MetaData.Response(INTERNAL_SERVER_ERROR_500, null, HttpVersion.HTTP_1_1, HttpFields.build().add(HttpFields.CONNECTION_CLOSE), 0);

// states
public enum State
Expand Down Expand Up @@ -224,7 +224,7 @@ public Result generateRequest(MetaData.Request info, ByteBuffer header, ByteBuff

generateHeaders(header, content, last);

boolean expect100 = info.getFields().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
boolean expect100 = info.getHttpFields().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());

if (expect100)
{
Expand Down Expand Up @@ -527,7 +527,7 @@ private void generateRequestLine(MetaData.Request request, ByteBuffer header)
{
header.put(StringUtil.getBytes(request.getMethod()));
header.put((byte)' ');
header.put(StringUtil.getBytes(request.getURIString()));
header.put(StringUtil.getBytes(request.getHttpURI().toString()));
header.put((byte)' ');
header.put(request.getHttpVersion().toBytes());
header.put(HttpTokens.CRLF);
Expand Down Expand Up @@ -591,7 +591,7 @@ private void generateHeaders(ByteBuffer header, ByteBuffer content, boolean last
if (LOG.isDebugEnabled())
{
LOG.debug("generateHeaders {} last={} content={}", _info, last, BufferUtil.toDetailString(content));
LOG.debug(_info.getFields().toString());
LOG.debug(_info.getHttpFields().toString());
}

// default field values
Expand All @@ -605,7 +605,7 @@ private void generateHeaders(ByteBuffer header, ByteBuffer content, boolean last
boolean contentLengthField = false;

// Generate fields
HttpFields fields = _info.getFields();
HttpFields fields = _info.getHttpFields();
if (fields != null)
{
int n = fields.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public String getReason()
@Override
public MetaData.Response getInfo()
{
return new MetaData.Response(_version, _status, _reason, this, _content == null ? -1 : _content.size());
return new MetaData.Response(_status, _reason, _version, this, _content == null ? -1 : _content.size());
}

@Override
Expand Down
Loading

0 comments on commit 744b37f

Please sign in to comment.