diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java index 1a5304f1d70..053591b6db2 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java @@ -125,4 +125,10 @@ public class HTTP2Stream implements IStream }); return true; } + + @Override + public String toString() + { + return String.format("%s@%x", getClass().getSimpleName(), hashCode()); + } } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/Frame.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/Frame.java index 7a58eb21841..782b6480c98 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/Frame.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/Frame.java @@ -34,4 +34,10 @@ public abstract class Frame { return type; } + + @Override + public String toString() + { + return String.format("%s@%x", getClass().getSimpleName(), hashCode()); + } } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/FrameType.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/FrameType.java index f46855d0eaa..a84898bd2b8 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/FrameType.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/frames/FrameType.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.http2.frames; +import java.util.HashMap; +import java.util.Map; + public enum FrameType { DATA(0), @@ -33,15 +36,26 @@ public enum FrameType ALTSVC(10), BLOCKED(11); + public static FrameType from(int type) + { + return Types.types.get(type); + } + private final int type; private FrameType(int type) { this.type = type; + Types.types.put(type, this); } public int getType() { return type; } + + private static class Types + { + private static final Map types = new HashMap<>(); + } } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java index b1d7f843d39..b6012e41b0f 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/Parser.java @@ -71,6 +71,8 @@ public class Parser public boolean parse(ByteBuffer buffer) { + LOG.debug("Parsing {}", buffer); + while (true) { switch (state) @@ -114,10 +116,14 @@ public class Parser { // The content will be processed asynchronously, stop parsing; // the asynchronous operation will eventually resume parsing. + if (LOG.isDebugEnabled()) + LOG.debug("Parsed {} frame, asynchronous processing", FrameType.from(type)); return true; } case COMPLETE: { + if (LOG.isDebugEnabled()) + LOG.debug("Parsed {} frame, synchronous processing", FrameType.from(type)); reset(); break; } diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HTTP2ServerConnectionFactory.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HTTP2ServerConnectionFactory.java index 80439b175b9..fe656685a49 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HTTP2ServerConnectionFactory.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HTTP2ServerConnectionFactory.java @@ -81,11 +81,11 @@ public class HTTP2ServerConnectionFactory extends AbstractConnectionFactory @Override public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) { - LOG.debug("Received {} on {}", frame, stream); + LOG.debug("Processing {} on {}", frame, stream); HttpTransportOverHTTP2 transport = new HttpTransportOverHTTP2((IStream)stream, frame); HttpInputOverHTTP2 input = new HttpInputOverHTTP2(); - HttpChannelOverHTTP2 channel = new HttpChannelOverHTTP2(connector, httpConfiguration, endPoint, transport, input); + HttpChannelOverHTTP2 channel = new HttpChannelOverHTTP2(connector, httpConfiguration, endPoint, transport, input, stream); stream.setAttribute(CHANNEL_ATTRIBUTE, channel); channel.requestHeaders(frame); @@ -96,6 +96,8 @@ public class HTTP2ServerConnectionFactory extends AbstractConnectionFactory @Override public void onData(Stream stream, DataFrame frame, Callback callback) { + LOG.debug("Processing {} on {}", frame, stream); + HttpChannelOverHTTP2 channel = (HttpChannelOverHTTP2)stream.getAttribute(CHANNEL_ATTRIBUTE); channel.requestContent(frame, callback); } diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java index f64005f2697..bd23ace1fd6 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpChannelOverHTTP2.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.http2.api.Stream; import org.eclipse.jetty.http2.frames.DataFrame; import org.eclipse.jetty.http2.frames.HeadersFrame; import org.eclipse.jetty.http2.hpack.MetaData; @@ -37,12 +38,18 @@ import org.eclipse.jetty.server.HttpInput; import org.eclipse.jetty.server.HttpTransport; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; public class HttpChannelOverHTTP2 extends HttpChannel { - public HttpChannelOverHTTP2(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput input) + private static final Logger LOG = Log.getLogger(HttpChannelOverHTTP2.class); + private final Stream stream; + + public HttpChannelOverHTTP2(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput input, Stream stream) { super(connector, configuration, endPoint, transport, input); + this.stream = stream; } public void requestHeaders(HeadersFrame frame) @@ -84,6 +91,17 @@ public class HttpChannelOverHTTP2 extends HttpChannel messageComplete(); } + if (LOG.isDebugEnabled()) + { + StringBuilder headers = new StringBuilder(); + for (HttpField field : fields) + { + headers.append(field).append(System.lineSeparator()); + } + LOG.debug("HTTP2 Request #{}:{}{} {} {}{}{}", + stream.getId(), System.lineSeparator(), method, uri, version, System.lineSeparator(), headers); + } + // TODO: pending refactoring of HttpChannel API. // Here we "cheat", knowing that headerComplete() will always return true // and that content() and messageComplete() will always return false. diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java index 1af79a57305..50e52278912 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.http.HttpGenerator; import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http2.IStream; import org.eclipse.jetty.http2.frames.DataFrame; import org.eclipse.jetty.http2.frames.HeadersFrame; @@ -30,9 +31,13 @@ import org.eclipse.jetty.http2.hpack.MetaData; import org.eclipse.jetty.server.HttpTransport; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; public class HttpTransportOverHTTP2 implements HttpTransport { + private static final Logger LOG = Log.getLogger(HttpTransportOverHTTP2.class); + private final AtomicBoolean commit = new AtomicBoolean(); private final IStream stream; private final HeadersFrame request; @@ -89,6 +94,12 @@ public class HttpTransportOverHTTP2 implements HttpTransport private void commit(HttpGenerator.ResponseInfo info, boolean endStream, Callback callback) { + if (LOG.isDebugEnabled()) + { + LOG.debug("HTTP2 Response #{}:{}{} {}{}{}", + stream.getId(), System.lineSeparator(), HttpVersion.HTTP_2_0, info.getStatus(), System.lineSeparator(), info.getHttpFields()); + } + MetaData metaData = new MetaData.Response(info.getStatus(), info.getHttpFields()); HeadersFrame frame = new HeadersFrame(stream.getId(), metaData, null, endStream); stream.headers(frame, callback); @@ -97,6 +108,12 @@ public class HttpTransportOverHTTP2 implements HttpTransport @Override public void send(ByteBuffer content, boolean lastContent, Callback callback) { + if (LOG.isDebugEnabled()) + { + LOG.debug("HTTP2 Response #{}: {} {}content bytes", + stream.getId(), lastContent ? "last " : "", content.remaining()); + } + DataFrame frame = new DataFrame(stream.getId(), content, lastContent); stream.data(frame, callback); } diff --git a/jetty-http2/http2-server/src/test/resources/jetty-logging.properties b/jetty-http2/http2-server/src/test/resources/jetty-logging.properties index 9e22652e722..292f2fc6550 100644 --- a/jetty-http2/http2-server/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -org.eclipse.jetty.client.LEVEL=DEBUG +org.eclipse.jetty.http2.LEVEL=DEBUG org.eclipse.jetty.spdy.server.LEVEL=DEBUG