-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Jetty 12: Looking for a way to abruptly finish a request, similar to OpenResty's ngx.exit(444) #12305
Comments
Since Jetty 12.0.13 you can do:
Let us know if this does what you're looking for. |
Thanks for the suggestion. I can compare the same test scenario with nginx via curl and I get curl -k -v --http1.1 https://localhost:64881/dep/large-response
On Jetty 12.0.13
The scenario here on both sides is that the HTTP status + headers are written, then "foobar" is written to the response body and then: The 'closing connection' response is what I'm looking for, to indicate to the client that "foobar" is actually a response body that cannot be relied upon |
This is surprising, as PR #12206 recently attempted to restore the harsh abort behavior from Jetty 11 |
This is strange, we have tests that prove that The linked test should be identical to your case: promise 10 bytes, write only 6, |
Thanks both - I'll dig into the test/PR and see if I can replicate the behaviour. |
I did a repo to replicate the sendError(-1) in a little embedded Jetty project. It still doesn't appear to be doing quite what I'm looking for. I'm adding nginx/OpenResty into the repo as a comparison to really dig into the differences. I'll report back with how that pans out. |
Ah.... I found out my error. Turns out nginx was just buffering the response and that was why it looked like it was doing something special. I replicated the situation both in Jetty 12.0.13 and nginx here: https://github.com/paulhilliar/jetty-terminate-connection-replication And when you explicitly flush the response, you get the same behaviour from both Nginx's ngx.exit(444) and Jetty's HttpServletResponse.sendError(-1). Thank you very much for your help - I'll close this question. |
Jetty Version 12.0.9
Jetty Environment ee10
Java Version 21
Question I'm porting a HTTP 1.1/2 proxy server application from OpenResty to Jetty 12.
There is a scenario where we have already sent the response headers and possibly some of the request body, before learning that the remainder of the request is not valid.
In that scenario in OpenResty, we call ngx.exit(444) and Nginx will abruptly close the connection. This is enough of a signal to curl or OkHttp that something has gone wrong. Other HTTP clients like Apache don't notice it but hey you can't have everything.
Please can you explain how can we tell Jetty server to abruptly close the connection, similar to Nginx?
For further explanation, the scenario here is a response caching feature. The headers and body (too big to hold all in memory) from a previous request have been cached (separately) in Redis. The headers have already been read from Redis and sent back to the client. If there is a failure to read a response chunk then we want to let the client know that they can't rely on the contents of the response.
Thanks in advance
The text was updated successfully, but these errors were encountered: