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
HttpClient#doOnRequest doesnt execute BEFORE request is sent #558
Comments
This additional step lets listeners react before a request body is sent, since once the CONFIGURED state is reached, it triggers sending the request over the wire.
Hi, my project has a need for this fix. I've been allotted a small amount of time to look into this and started with this failing test. If I revert the observer reordering from this commit, my test passes. Any thoughts on this? I'm still new to this, so I'm not entirely sure how to proceed, but I'll do the best in the time I've got! |
I should note that other tests, unsurprisingly, fail when I change that back. If I apply this diff to my branch:
I get the following failing tests: Note that my newly added |
Adapt reactor.netty.http.client.WebsocketTest to the change: as the I/O handler is applied as the last observer, the availability of NettyPipeline.WsCompressionHandler cannot be check using doOnConnected, because the compression handler is applied as part of the I/O handler, however the test check whether the corresponding compression handler is available so it can be checked in the handle method.
@crankydillo Thanks for the analysis. Please check this PR #701 |
Thanks @violetagg ! |
Expected behavior
HttpClient#doOnRequest
listener should be invoked before the request is sent, allowing to mutate it (eg. add a basic set of headers on every request).Actual behavior
It seems to be invoked AFTER the request is sent. In the listener:
req.requestHeaders().set("foo", "bar")
mutates the headers but is never usedreq.header("foo", "bar")
throws anjava.lang.IllegalStateException: Status and headers already sent
Steps to reproduce
Analysis
HttpClientConnect
is always added as the first observer, afterdoOnRequest
'sHttpClientDoOn
has set itself as observer, resulting if I understand correctly in HCC calling the handler and sending the request before the doOnRequest is invoked.Both react to the
CONFIGURED
state, and due to the orderHttpClientConnect
"wins".The workaround would be to add a new intermediate state, eg.
CONFIGURING
, letting some observers alter the request beforeHttpClientConnect
does its thing. For instance,doOnRequest
would match on this one.CONFIGURING
would be fired right beforeCONFIGURED
everywhere the later is currently fired.Reactor Netty version
0.8.x
The text was updated successfully, but these errors were encountered: