We are using in our product an
http load balancer which dispatches http messages to remote http agents
that are internally using Jetty 9.3.0. So we have
developed a specific Jetty Connector that extends org.eclipse.jetty.server.AbstractConnector and allows to connect our Jetty based http agent instances to the load balancer.
Now, in the context of HTTP2, we are facing the following issue:
When an HTTP2 client sends an initial request using basic HTTP/1.1
with some upgrade headers ("Connection: Upgrade, HTTP2-Settings",
"Upgrade: h2c" etc ...), then Jetty (that is running in remote http
agents) is first responding with a "101 Switching Protocol" in order to
start communicating over the new HTTP2 protocol.
for technical reasons, when a Jetty Container is about to send the 101
switching protocol, we need to be informed about the 101 message *before*
it is actually sent to the load balancer.
- One option could consist in just simply overriding the "upgrade" method of the org.eclipse.jetty.io.AbstractEndPoint
class (we also have implemented a special EndPoint in each http agent in order to
connect each Jetty container to the load balancer). However, the problem
is that this callback is invoked after the 101 is flushed and sent out.
What we need is to detect that a protocol switch is taking place
*before* the 101 is sent from the http agent towards the load balancer.
So, using the upgrade callback seems to not be an option.
Another option is to parse every messages that are about to be flushed
and sent by jetty. This could be done by parsing all jetty outgoing
messages (http responses) from our EndPoint.flush() method. But we don't
want to do that for sake of performance.
- We also
tried to implement a RequestLogHandler that is supposed to be called
when a request is committed. Unfortunately, our handler is called only
when the HTTP2 200 response is sent out, and is never called with the
initial 101 message is sent.
Interestingly, we noticed that our
RequestLogHandler is called with the 101 message in the context of Web Sockets,
but not in the context of HTTP2.
So, does anyone knows
if there is a way to catch HTTP2 "101" responses before they are sent
out, just before HTTP2 protocol is activated ?