Discussion:
[jetty-users] Dumping the headers
Martin Grajcar
2017-12-20 08:39:56 UTC
Permalink
Many thanks you for the answer... some more questions follow...
I'm not sure about the exact meaning of setDelayDispatchUntilContent. It's
documented with
Whether to delay the application dispatch until content is available
which may mean it waits until all or some content is available.
I guess, it means the former, as with many requests, nearly nothing can
be
done, until they're fully available. Am I right?
No, it means to wait to call the application until the first chunk of
content, if any, is available.
This is done because typically the first thing that applications do is
to read the content, and there would be no point in calling the
application to have it block because there is no content available
yet.
Actually, my application always needs the *full* content. I'd gladly trade
the stream for a byte[] anytime. I guess, there's no out of the box
solution for this and I need to use request.startAsync, right?

Slightly related: Can I get the headers as text just like they were sent? I
want to do a full dump of some requests and dumping exactly what arrived
would be best.
Anyway, is it possible to obtain the time when the request started? I'd
need
it for my statistics.
Yes. If you only need the request start time you can call
Request.getTimeStamp().
Otherwise I suggest you use the more generic HttpChannel.Listener
ServerConnector connector = ...;
connector.addBean(new HttpChannel.Listener() {
@Override
public void onRequestBegin(Request request) {
...
}
});
which exposes many more events.
Nice!

Regards,
Martin.
Simone Bordet
2017-12-20 10:41:19 UTC
Permalink
Hi,
Actually, my application always needs the full content. I'd gladly trade the
stream for a byte[] anytime. I guess, there's no out of the box solution for
this and I need to use request.startAsync, right?
You don't *need* to call startAsync().
You just read from the ServletInputStream.
Slightly related: Can I get the headers as text just like they were sent?
No.
I want to do a full dump of some requests and dumping exactly what arrived
would be best.
What arrives are bytes, not text.
The bytes that represent the HTTP headers can be fragmented by the
sender or by TCP.
The bytes may contain both HTTP headers and content.
We would need to parse the bytes to understand where the headers finish.

Have a look at https://github.com/eclipse/jetty.project/blob/jetty-9.4.8.v20171121/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java
if you want to intercept the bytes that arrive at the connector; but
then you're on your own and you need to parse them.
--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Loading...