Discard the following HttpContent for preflight request#15941
Conversation
…lass, int) ignores sampling interval
This reverts commit 87531c7
Signed-off-by: skyguard1 <qhdxssm@qq.com>
Signed-off-by: skyguard1 <qhdxssm@qq.com>
Signed-off-by: skyguard1 <qhdxssm@qq.com>
|
hmm... I don't think this is correct. We either need to always pass down a |
However, for preflight requests, the HttpRequest is not being passed down, but the LastHttpContent is. Did I missing something? |
|
@skyguard1 I am just saying we either always need to pass down the request + last content or never.. it always needs to be the combination or none at all. |
|
Preflight (OPTIONS + ACRM) is not a business request; it's merely a control request used internally by the browser to retrieve CORS metadata. Therefore, the business logic should never: receive the preflight HttpRequest receive its HttpContent/LastHttpContent. So, for preflight requests, if you don't pass the HttpRequest, you should also not pass the LastHttpContent. This PR is essentially discarding the LastHttpContent for preflight requests, so I don't know what I'm missing. |
|
@skyguard1 What I am saying is that I don't think this should be configurable at all... |
|
I got it. So you think the flag should be removed, but this fix is valid. Right? |
|
My idea is to first minimize changes through the configuration, and then remove the flag after the release when users have configured and validated the behavior of discarding LastHttpContent. This satisfies the principle of minimal changes. Of course, we could also directly delete the flag to perform this fix. |
|
imho we should just fix it and not have the configuration API. As this is just another API that we need to keep. We could have a system property to fallback to the old behavior but I am not sure this is needed at all. |
|
Agreed. Then I will delete this configuration. |
Signed-off-by: skyguard1 <qhdxssm@qq.com>
|
Done |
…uest is forwarded Signed-off-by: skyguard1 <qhdxssm@qq.com>
Signed-off-by: skyguard1 <qhdxssm@qq.com>
Signed-off-by: skyguard1 <qhdxssm@qq.com>
…HandlerTest.java Co-authored-by: Norman Maurer <norman_maurer@apple.com>
…HandlerTest.java Co-authored-by: Norman Maurer <norman_maurer@apple.com>
…HandlerTest.java Co-authored-by: Norman Maurer <norman_maurer@apple.com>
…HandlerTest.java Co-authored-by: Norman Maurer <norman_maurer@apple.com>
|
|
normanmaurer
left a comment
There was a problem hiding this comment.
Almost there... Please also update the PR description etc to reflect what is actual done now
| } | ||
|
|
||
| @Test | ||
| public void allowPrivateNetwork() { |
There was a problem hiding this comment.
nit: This seems to be not related to the PR
There was a problem hiding this comment.
Yes. But I found this allowPrivateNetwork is missing for unit test, maybe remove this?
There was a problem hiding this comment.
just do it in a separate PR
| assertFalse(ch.writeInbound(preflight)); | ||
| ReferenceCountUtil.release(ch.readOutbound()); | ||
|
|
||
| LastHttpContent first = LastHttpContent.EMPTY_LAST_CONTENT; |
There was a problem hiding this comment.
nit: You might also want to test with one non-empty one as it should be the same behavior
Signed-off-by: skyguard1 <qhdxssm@qq.com>
…nt' into fix_cors_handler_last_http_content
Signed-off-by: skyguard1 <qhdxssm@qq.com>
|
@skyguard1 thanks! |
Motivation: HttpServerCodec always constructs an `EmptyLastHttpContent` and passes it to the Handler chain when processing OPTIONS requests, The `EmptyLastHttpContent` propagate through the handler chain. However, the CORS handler might still propagate the EmptyLastHttpContent to downstream handlers via fireChannelRead(), causing subsequent handlers to receive only this empty content and lose access to the original request URL. Because `CorsHandler` does not consume this message, it calls `ctx.fireChannelRead(msg)` for the EmptyLastHttpContent. Downstream handlers then observe: No HttpRequest A LastHttpContent with empty content This often breaks other handlers that rely on receiving the `HttpRequest` first or expect consistent HTTP message. This PR fixes an issue in `CorsHandler` where, after handling a CORS preflight (OPTIONS) request, the handler still propagates the subsequent `EmptyLastHttpContent` sent by the `HttpServerCodec` to downstream handler. Modification: - `CorsHandler` track handled preflight and consume the following HttpContent, LastHttpContent until the next HttpRequest is forwarded instead of firing it downstream. - Add tests Result: Fixes #15148 It also improves compatibility with application frameworks and routing handlers that expect well-formed HTTP request/response flows. --------- Signed-off-by: skyguard1 <qhdxssm@qq.com> Co-authored-by: xingrufei <xingrufei@yl.com> Co-authored-by: code-xing_wcar <code.xing@wirelesscar.com> Co-authored-by: Norman Maurer <norman_maurer@apple.com>
Motivation: HttpServerCodec always constructs an `EmptyLastHttpContent` and passes it to the Handler chain when processing OPTIONS requests, The `EmptyLastHttpContent` propagate through the handler chain. However, the CORS handler might still propagate the EmptyLastHttpContent to downstream handlers via fireChannelRead(), causing subsequent handlers to receive only this empty content and lose access to the original request URL. Because `CorsHandler` does not consume this message, it calls `ctx.fireChannelRead(msg)` for the EmptyLastHttpContent. Downstream handlers then observe: No HttpRequest A LastHttpContent with empty content This often breaks other handlers that rely on receiving the `HttpRequest` first or expect consistent HTTP message. This PR fixes an issue in `CorsHandler` where, after handling a CORS preflight (OPTIONS) request, the handler still propagates the subsequent `EmptyLastHttpContent` sent by the `HttpServerCodec` to downstream handler. Modification: - `CorsHandler` track handled preflight and consume the following HttpContent, LastHttpContent until the next HttpRequest is forwarded instead of firing it downstream. - Add tests Result: Fixes #15148 It also improves compatibility with application frameworks and routing handlers that expect well-formed HTTP request/response flows. --------- Signed-off-by: skyguard1 <qhdxssm@qq.com> Co-authored-by: xingrufei <xingrufei@yl.com> Co-authored-by: code-xing_wcar <code.xing@wirelesscar.com> Co-authored-by: Norman Maurer <norman_maurer@apple.com>
) Motivation: HttpServerCodec always constructs an `EmptyLastHttpContent` and passes it to the Handler chain when processing OPTIONS requests, The `EmptyLastHttpContent` propagate through the handler chain. However, the CORS handler might still propagate the EmptyLastHttpContent to downstream handlers via fireChannelRead(), causing subsequent handlers to receive only this empty content and lose access to the original request URL. Because `CorsHandler` does not consume this message, it calls `ctx.fireChannelRead(msg)` for the EmptyLastHttpContent. Downstream handlers then observe: No HttpRequest A LastHttpContent with empty content This often breaks other handlers that rely on receiving the `HttpRequest` first or expect consistent HTTP message. This PR fixes an issue in `CorsHandler` where, after handling a CORS preflight (OPTIONS) request, the handler still propagates the subsequent `EmptyLastHttpContent` sent by the `HttpServerCodec` to downstream handler. Modification: - `CorsHandler` track handled preflight and consume the following HttpContent, LastHttpContent until the next HttpRequest is forwarded instead of firing it downstream. - Add tests Result: Fixes #15148 It also improves compatibility with application frameworks and routing handlers that expect well-formed HTTP request/response flows. Signed-off-by: skyguard1 <qhdxssm@qq.com> Co-authored-by: skyguard1 <qhdxssm@qq.com> Co-authored-by: xingrufei <xingrufei@yl.com> Co-authored-by: code-xing_wcar <code.xing@wirelesscar.com>
|
It is my pleasure |
) Motivation: HttpServerCodec always constructs an `EmptyLastHttpContent` and passes it to the Handler chain when processing OPTIONS requests, The `EmptyLastHttpContent` propagate through the handler chain. However, the CORS handler might still propagate the EmptyLastHttpContent to downstream handlers via fireChannelRead(), causing subsequent handlers to receive only this empty content and lose access to the original request URL. Because `CorsHandler` does not consume this message, it calls `ctx.fireChannelRead(msg)` for the EmptyLastHttpContent. Downstream handlers then observe: No HttpRequest A LastHttpContent with empty content This often breaks other handlers that rely on receiving the `HttpRequest` first or expect consistent HTTP message. This PR fixes an issue in `CorsHandler` where, after handling a CORS preflight (OPTIONS) request, the handler still propagates the subsequent `EmptyLastHttpContent` sent by the `HttpServerCodec` to downstream handler. Modification: - `CorsHandler` track handled preflight and consume the following HttpContent, LastHttpContent until the next HttpRequest is forwarded instead of firing it downstream. - Add tests Result: Fixes #15148 It also improves compatibility with application frameworks and routing handlers that expect well-formed HTTP request/response flows. Signed-off-by: skyguard1 <qhdxssm@qq.com> Co-authored-by: skyguard1 <qhdxssm@qq.com> Co-authored-by: xingrufei <xingrufei@yl.com> Co-authored-by: code-xing_wcar <code.xing@wirelesscar.com>
Motivation:
HttpServerCodec always constructs an
EmptyLastHttpContentand passes it to the Handler chain when processing OPTIONS requests, TheEmptyLastHttpContentpropagate through the handler chain.However, the CORS handler might still propagate the EmptyLastHttpContent to downstream handlers via fireChannelRead(), causing subsequent handlers to receive only this empty content and lose access to the original request URL.
Because
CorsHandlerdoes not consume this message, it callsctx.fireChannelRead(msg)for the EmptyLastHttpContent.Downstream handlers then observe:
No HttpRequest
A LastHttpContent with empty content
This often breaks other handlers that rely on receiving the
HttpRequestfirst or expect consistent HTTP message.This PR fixes an issue in
CorsHandlerwhere, after handling a CORS preflight (OPTIONS) request, the handler still propagates the subsequentEmptyLastHttpContentsent by theHttpServerCodecto downstream handler.Modification:
This PR adds option to
CorsHandlerto track when a preflight request has been fully handled.Track handled preflight and consume the following inbound HttpContent,LastHttpContent instead of firing it downstream.
Scope: Only affects CORS preflight flow; keeps normal request forwarding unchanged.
Tests: Added cases to verify empty and non-empty LastHttpContent are discarded after preflight and that normal requests continue to forward HttpRequest and content.
It also improves compatibility with application frameworks and routing handlers that expect well-formed HTTP request/response flows.
Result:
Fixes #15148
CorsHandlertrack handled preflight and consume the following HttpContent, LastHttpContent until the next HttpRequest is forwarded instead of firing it downstream.