diff options
author | Simone Bordet | 2015-03-12 18:08:09 +0000 |
---|---|---|
committer | Simone Bordet | 2015-03-12 18:08:26 +0000 |
commit | feed8ea1589a0e81a579aa00c00d03837a102902 (patch) | |
tree | 00ab01ce588564a0da078cc7899a25663f6bd4d2 /jetty-http2/http2-common | |
parent | 79fb2a40832f88e08c3fc242a4958cdecf5100ae (diff) | |
download | org.eclipse.jetty.project-feed8ea1589a0e81a579aa00c00d03837a102902.tar.gz org.eclipse.jetty.project-feed8ea1589a0e81a579aa00c00d03837a102902.tar.xz org.eclipse.jetty.project-feed8ea1589a0e81a579aa00c00d03837a102902.zip |
Small refactoring of HTTP/2 upgrade code.
Diffstat (limited to 'jetty-http2/http2-common')
3 files changed, 52 insertions, 4 deletions
diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java index aab2dc9191..731d27ded4 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java @@ -56,7 +56,7 @@ public class HTTP2Connection extends AbstractConnection implements Connection.Up this.executionStrategy = ExecutionStrategy.Factory.instanceFor(producer, executor); } - protected ISession getSession() + public ISession getSession() { return session; } diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index 9eec0cda2f..dfbd839caa 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -217,6 +217,12 @@ public abstract class HTTP2Session implements ISession, Parser.Listener @Override public void onSettings(SettingsFrame frame) { + // SPEC: SETTINGS frame MUST be replied. + onSettings(frame, true); + } + + public void onSettings(SettingsFrame frame, boolean reply) + { if (frame.isReply()) return; @@ -287,9 +293,11 @@ public abstract class HTTP2Session implements ISession, Parser.Listener } notifySettings(this, frame); - // SPEC: SETTINGS frame MUST be replied. - SettingsFrame reply = new SettingsFrame(Collections.<Integer, Integer>emptyMap(), true); - settings(reply, Callback.Adapter.INSTANCE); + if (reply) + { + SettingsFrame replyFrame = new SettingsFrame(Collections.<Integer, Integer>emptyMap(), true); + settings(replyFrame, Callback.Adapter.INSTANCE); + } } @Override diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java index 2d7c3a43d1..0a68522c39 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.http2.parser; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.http2.ErrorCode; import org.eclipse.jetty.http2.Flags; @@ -165,6 +166,45 @@ public class SettingsBodyParser extends BodyParser return true; } + public static SettingsFrame parseBody(final ByteBuffer buffer) + { + final int bodyLength = buffer.remaining(); + final AtomicReference<SettingsFrame> frameRef = new AtomicReference<>(); + SettingsBodyParser parser = new SettingsBodyParser(null, null) + { + @Override + protected int getStreamId() + { + return 0; + } + + @Override + protected int getBodyLength() + { + return bodyLength; + } + + @Override + protected boolean onSettings(Map<Integer, Integer> settings) + { + frameRef.set(new SettingsFrame(settings, false)); + return true; + } + + @Override + protected boolean connectionFailure(ByteBuffer buffer, int error, String reason) + { + frameRef.set(null); + return false; + } + }; + if (bodyLength == 0) + parser.emptyBody(buffer); + else + parser.parse(buffer); + return frameRef.get(); + } + private enum State { PREPARE, SETTING_ID, SETTING_ID_BYTES, SETTING_VALUE, SETTING_VALUE_BYTES |