jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

AsyncMiddleManServlet removes content-length header if the client doesn't send Expect: 100-Continue

Open mtheos opened this issue 2 years ago • 5 comments
trafficstars

Jetty version 10.0.15 Java version 17.0.3 Question

Hi Jetty,

The AsyncMiddleManServlet.ProxyReader removes the content-length header and switches to chunked encoding when proxying.

I initially thought this was because you don't know the length of the transformed request, but I noticed that it only does this when the client doesn't send Expect: 100-Continue and otherwise keeps the content length header.

Do you know why this difference in behaviour exists? It would be possible to change the headers in copyRequestHeaders myself if the content length is unknown without enforcing it in the reader.

I can extend the ProxyReader impl to change this behaviour, but it's a significant amount of code that needs to be copied to make a very small behaviour change.

mtheos avatar May 11 '23 01:05 mtheos

It is a bug that we keep the Content-Length header when the client request has Expect: 100-Continue because we do not know the size of the transformed request content.

With that fixed, the behavior will be the same: if the proxy can read the whole client request content in one read, then the proxy request to the server will have Content-Length, otherwise it will be chunked.

Would that solve this issue? I ask because I'm not sure I understand what you are asking in the last part of your comment above.

sbordet avatar Aug 01 '23 09:08 sbordet

Hi Simone,

In our use case, we know the size of the transformed request up front since we're only adding metadata to the body, so we can add the content-length header before we've read the client request.

The issue we faced is that the downstream expects the content-length header so it can adjust how it handles the request based on the size.

We worked around the issue by copying the code and modifying it.

mtheos avatar Aug 01 '23 14:08 mtheos

Can you detail what code you have modified? It may be that we can add an overridable method that will make your life simpler rather than copying large chunks of code.

sbordet avatar Aug 01 '23 14:08 sbordet

I copied the AsyncMiddleManServlet and removed that line. That was the only change needed.

We were looking at the middle man servlet as an option, but we've since moved to reactor netty with webflux so I wouldn't worry about changing this for us unless you think it's the right change.

mtheos avatar Aug 01 '23 23:08 mtheos

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 01 '24 00:08 github-actions[bot]

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 05 '25 00:08 github-actions[bot]

Closing as Jetty 10 is no longer supported.

joakime avatar Aug 05 '25 14:08 joakime

Reopening, as this may still be an issue/enhancement in 12.

sbordet avatar Aug 12 '25 15:08 sbordet