jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.84k stars 1.91k forks source link

AsyncMiddleManServlet response flushing #12323

Open iiliev2 opened 17 hours ago

iiliev2 commented 17 hours ago

Jetty 12 ee10

Java 17

Continuing the discussion from https://github.com/jetty/jetty.project/issues/12294#issuecomment-2374287136 as this is a separate topic.

The proxy servlets(in particular AsyncMiddleManServlet, as that is what I am looking at) do not seem to flush responses as the proxy client receives new bytes. Ideally it should auto flush in an optimal way(for ex. if http1.1 and chunked, it should flush on each full chunk). Otherwise there could be huge delays between when the data is available and when it is actually returned to the caller(due to buffering). Since this is a proxy, I expected this to be the default, otherwise I hope to be able to set it up that way.

The ContentTransformer does not seem to provide a way to control this(suggested in the previous github question). That abstraction is about mutating the raw data in some way.

The only way that I can see from the code of AsyncMiddleManServlet is to call flush on the ServletOutputStream right after ProxyWriter calls writeProxyResponseContent. Unfortunatly that method is package private so the only way is to override the entire onWritePossible and flush afterward.

What would you advise is the right way to do this?

sbordet commented 16 hours ago

AsyncMiddleManServlet is a proxy servlet dedicated to mutate content.

If you don't need to mutate content, don't use it, and use instead ProxyHandler (recommended) or AsyncProxyServlet.

As for AsyncMiddleManServlet, did you actually follow the advice I gave in the comment? Does it not work? If it does not work, we need details, because it is supposed to work like you expect.