Skip to content

Discard the following HttpContent for preflight request (#15941)#15962

Merged
chrisvest merged 1 commit into
4.1from
cors41
Dec 3, 2025
Merged

Discard the following HttpContent for preflight request (#15941)#15962
chrisvest merged 1 commit into
4.1from
cors41

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

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.

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>
@normanmaurer normanmaurer added this to the 4.1.129.Final milestone Dec 3, 2025
@chrisvest chrisvest merged commit 11346d6 into 4.1 Dec 3, 2025
18 checks passed
@chrisvest chrisvest deleted the cors41 branch December 3, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants