-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supported chunked behavior for responses #176
Conversation
Server send events are send as chunked responses. The expectation is that the chunks are immediately send and not buffered until the whole response is done. If a response is detected, the chunks are normally read and each read chunk is immediately flushed, replicating the upstream behavior downstream.
Wouldn't it be the job of the HttpEntity to do this in writeto() if indeed this is any better/faster? Put differently, maybe you should take this up with Apache Httpcomponents? |
The change does not make it faster, indeed it may be slower, as smaller packets are send. The important part is, that for server send events the packets need to be forwarded immediately, else the stream degenerates to a normal http request and just blocks the browser. This is a special case, that is only valid for the proxy use-case. If the stream is for example a download with an unknown length and is streamed to a file a flush is not necessary. So I would argue, that the proxy servlet is the special case here. |
Comments.
Can you add a test please? AFAICT the existing tests don't exercise this code. |
For the test: Sure, but how far can I go? httpunit is not adequate for this check. If I understand correctly, it emulates a servlet container and this emulation is leaky. A response is only created/made accessible, after a request is finished executing. A test in this case becomes absurd, as the hole point is reading data before service finishes. So can I add jetty to the test dependencies? |
Yes, let's add Jetty. The existing test infrastructure has been holding back testing some things that need a real webserver (like Jetty). Also I'm willing to change the project dependencies to Java 1.8+ if that helps. |
Supporting changes: - add jetty as a test dependency used as servlet execution engine - bump javax.servlet-api to version 3.1.0 which is required by jetty Jetty 9.4 requires java 8 as minimum version.
I pushed an update with a unittest. I verified, that the test fails without the change and runs clean with it. |
Thanks for writing this test! |
Thanks for taking time to get this in and maintaining the proxy servlet 👍 |
Server send events are send as chunked responses. The expectation is
that the chunks are immediately send and not buffered until the whole
response is done.
If a response is detected, the chunks are normally read and each read
chunk is immediately flushed, replicating the upstream behavior
downstream.