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.86k stars 1.91k forks source link

AsyncMiddleManServlet chunked transfer passthrough #12294

Closed iiliev2 closed 1 month ago

iiliev2 commented 1 month ago

Jetty Version 10.0.21 Java Version zulu 11

I am trying to setup a transparent proxy. Does this servlet support chunked transfer(streaming of data) between the two connections?

So far I was not able to get it to work. The call goes through, but completes right away. It passes over the content up until the point of invocation and completes the request.

The servlet is setup in jetty server.

sbordet commented 1 month ago

Jetty 10 is at end of community support, see #10485.

Please upgrade to Jetty 12 and report back if it works.

However, yes, AsyncMiddleManServlet supports Transfer-Encoding: chunked, so you're probably not using it correctly.

If you provide a reproducible project with Jetty 12 that shows the issue, we can take a look.

iiliev2 commented 1 month ago

Thanks. Will the jetty 12 version of this servlet work on jetty server 10, or everything must be upgraded?

sbordet commented 1 month ago

You have to upgrade to Jetty 12, and likely use the ee8, ee9 or ee10 version of AsyncMiddleManServlet shipped with Jetty 12, and also update to Java 17.

You cannot take classes from Jetty 12 and make them run in previous Jetty versions, in general.

iiliev2 commented 1 month ago

Does this unit test verify this use case?

sbordet commented 1 month ago

@iiliev2 you did not specify what use case, so I cannot tell. That test tests a particular condition, I have no idea whether it applies to you or not.

As I told you, chunked content is fully supported by AsyncMiddleManServlet.

iiliev2 commented 1 month ago

so you're probably not using it correctly

I found the issue. I was not rewriting the target correctly (rewriteTarget). Then I also needed finer-grained control of when to flush the response.

sbordet commented 1 month ago

Glad it's working for you.

I also needed finer-grained control of when to flush the response.

This should be available out of the box.

iiliev2 commented 1 month ago

This should be available out of the box.

Could you please elaborate a bit? AFAICT I should override https://github.com/jetty/jetty.project/blob/04fd45d94e60e5c6b0e5330edfc85b51214837d5/jetty-ee10/jetty-ee10-proxy/src/main/java/org/eclipse/jetty/ee10/proxy/AsyncMiddleManServlet.java#L617 (jetty 12). Is there a better way?

sbordet commented 1 month ago

You do not want to override ProxyWriter.onWritePossible().

IIUC, you want to be able to perform some transformation to the content, so you have to implement ContentTransformer. The javadocs should be clear enough.

You receive content, you transform it, and what you want to be flushed you add it to the output list.