GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Discard the following HttpContent for preflight request by skyguard1 · Pull Request #15941 · netty/netty

Conversation

@skyguard1

@skyguard1 skyguard1 commented Nov 29, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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:

This PR adds option to CorsHandler to 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

CorsHandler track handled preflight and consume the following HttpContent, LastHttpContent until the next HttpRequest is forwarded instead of firing it downstream.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
xingrufei and others added 11 commits June 30, 2020 19:21
xingrufei
Fix netty#10378,ResourceLeakDetectorFactory.newResourceLeakDetector(C…
aac7a96
…lass, int) ignores  sampling interval
xingrufei
format code
87531c7
xingrufei
Revert "format code"
0f04075
This reverts commit 87531c7
xingrufei
Verify that the samplingInterval parameter is positive
d7b6d67
@skyguard1
Merge branch 'netty:4.1' into 4.1
4ca4309
@skyguard1
Merge branch 'netty:4.1' into 4.1
8ee614a
@skyguard1
Merge branch '4.1' of https://github.com/skyguard1/netty into 4.1
994ed46
@code-xing-wcar
Merge remote-tracking branch 'upstream/4.1' into 4.1
173ffde
@skyguard1
Allow user to discard the lastHttpContent for preflight request
f80be2d
Signed-off-by: skyguard1 <[email protected]>
@skyguard1
Fix checkstyle issue
a0adc6b
Signed-off-by: skyguard1 <[email protected]>
@skyguard1
Remove channelInactive in CorsHandler
ee678ea
Signed-off-by: skyguard1 <[email protected]>
@normanmaurer

normanmaurer commented Dec 1, 2025

Copy link
Copy Markdown
Member

hmm... I don't think this is correct. We either need to always pass down a HttpRequest + LastHttpContent or non of these at all. I don't think there should be any configuration be involved at all.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1

skyguard1 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

hmm... I don't think this is correct. We either need to always pass down a HttpRequest + LastHttpContent or non of these at all. I don't think there should be any configuration be involved at all.

However, for preflight requests, the HttpRequest is not being passed down, but the LastHttpContent is. Did I missing something?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Dec 1, 2025

Copy link
Copy Markdown
Member

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1

skyguard1 commented Dec 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Dec 1, 2025

Copy link
Copy Markdown
Member

@skyguard1 What I am saying is that I don't think this should be configurable at all...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1

skyguard1 commented Dec 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I got it. So you think the flag should be removed, but this fix is ​​valid. Right?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1

skyguard1 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer

normanmaurer commented Dec 1, 2025

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1

skyguard1 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

Agreed. Then I will delete this configuration.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

skyguard1 added 2 commits December 1, 2025 18:40
@skyguard1
Merge remote-tracking branch 'upstream/4.2' into fix_cors_handler_las…
f365d1d
…t_http_content
@skyguard1
Remove discardNextEmptyLast in CorsHandler
56e06cf
Signed-off-by: skyguard1 <[email protected]>
@skyguard1 skyguard1 changed the title Allow user to discard the lastHttpContent for preflight request Discard the lastHttpContent for preflight request Dec 1, 2025
@skyguard1

skyguard1 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

Done

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer normanmaurer added this to the 4.2.8.Final milestone Dec 1, 2025
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Dec 1, 2025
normanmaurer
normanmaurer requested changes Dec 1, 2025
View reviewed changes
Comment thread codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1
Discard following HttpContent, LastHttpContent until the next HttpReq…
38d0832
…uest is forwarded

Signed-off-by: skyguard1 <[email protected]>
normanmaurer
normanmaurer requested changes Dec 1, 2025
View reviewed changes
Comment thread codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

skyguard1 and others added 4 commits December 2, 2025 10:02
@skyguard1 @normanmaurer
Update codec-http/src/test/java/io/netty/handler/codec/http/cors/Cors…
cdd2b41
…HandlerTest.java

Co-authored-by: Norman Maurer <[email protected]>
@skyguard1 @normanmaurer
Update codec-http/src/test/java/io/netty/handler/codec/http/cors/Cors…
5fd3579
…HandlerTest.java

Co-authored-by: Norman Maurer <[email protected]>
@skyguard1 @normanmaurer
Update codec-http/src/test/java/io/netty/handler/codec/http/cors/Cors…
b8c2d20
…HandlerTest.java

Co-authored-by: Norman Maurer <[email protected]>
@skyguard1 @normanmaurer
Update codec-http/src/test/java/io/netty/handler/codec/http/cors/Cors…
98c16ea
…HandlerTest.java

Co-authored-by: Norman Maurer <[email protected]>
@skyguard1

skyguard1 commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

AutoScalingEventExecutorChooserFactoryTest.testScaleUp. It seems that the failure of this test case is not related to this PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer requested a review from yawkat December 2, 2025 07:40
@normanmaurer

normanmaurer commented Dec 2, 2025

Copy link
Copy Markdown
Member

@yawkat @vietj PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer reviewed Dec 2, 2025
View reviewed changes
Comment thread codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer
normanmaurer requested changes Dec 2, 2025
View reviewed changes

@normanmaurer normanmaurer left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there... Please also update the PR description etc to reflect what is actual done now

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsConfigTest.java Outdated
}

@Test
public void allowPrivateNetwork() {

@normanmaurer normanmaurer Dec 2, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This seems to be not related to the PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@skyguard1 skyguard1 Dec 2, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But I found this allowPrivateNetwork is missing for unit test, maybe remove this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@normanmaurer normanmaurer Dec 2, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do it in a separate PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java
assertFalse(ch.writeInbound(preflight));
ReferenceCountUtil.release(ch.readOutbound());

LastHttpContent first = LastHttpContent.EMPTY_LAST_CONTENT;

@normanmaurer normanmaurer Dec 2, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You might also want to test with one non-empty one as it should be the same behavior

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@skyguard1 skyguard1 changed the title Discard the lastHttpContent for preflight request Discard the following HttpContent for preflight request Dec 2, 2025
skyguard1 added 4 commits December 2, 2025 18:53
@skyguard1
Update by review
7af403e
Signed-off-by: skyguard1 <[email protected]>
@skyguard1
Merge remote-tracking branch 'origin' into fix_cors_handler_last_http…
1ea49ce
…_content
@skyguard1
Merge remote-tracking branch 'upstream/4.2' into fix_cors_handler_las…
11016c5
…t_http_content
@skyguard1
Merge remote-tracking branch 'origin/fix_cors_handler_last_http_conte…
c197123
…nt' into fix_cors_handler_last_http_content
chrisvest
chrisvest reviewed Dec 2, 2025
View reviewed changes
Comment thread codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@skyguard1
Add preflightEmptyLastDiscardedThenNewRequestForwarded test case
8e3034f
Signed-off-by: skyguard1 <[email protected]>
chrisvest
chrisvest approved these changes Dec 3, 2025
View reviewed changes
@normanmaurer
normanmaurer merged commit 28e8017 into netty:4.2 Dec 3, 2025
@normanmaurer

normanmaurer commented Dec 3, 2025

Copy link
Copy Markdown
Member

@skyguard1 thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer added a commit that referenced this pull request Dec 3, 2025
@skyguard1 xingrufei
@code-xing-wcar @normanmaurer
Discard the following HttpContent for preflight request (#15941)
e502b39
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 <[email protected]>
Co-authored-by: xingrufei <[email protected]>
Co-authored-by: code-xing_wcar <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Dec 3, 2025
@skyguard1 xingrufei
@code-xing-wcar @normanmaurer
Discard the following HttpContent for preflight request (#15941)
cf8280b
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 <[email protected]>
Co-authored-by: xingrufei <[email protected]>
Co-authored-by: code-xing_wcar <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
chrisvest pushed a commit that referenced this pull request Dec 3, 2025
@normanmaurer @skyguard1
xingrufei @code-xing-wcar
Discard the following HttpContent for preflight request (#15941) (#15962
11346d6
)

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 <[email protected]>
Co-authored-by: skyguard1 <[email protected]>
Co-authored-by: xingrufei <[email protected]>
Co-authored-by: code-xing_wcar <[email protected]>
@skyguard1

skyguard1 commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

It is my pleasure

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

normanmaurer added a commit that referenced this pull request Dec 4, 2025
@normanmaurer @skyguard1
xingrufei @code-xing-wcar
Discard the following HttpContent for preflight request (#15941) (#15963
8296b7c
)

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 <[email protected]>
Co-authored-by: skyguard1 <[email protected]>
Co-authored-by: xingrufei <[email protected]>
Co-authored-by: code-xing_wcar <[email protected]>
@chrisvest chrisvest removed needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Jun 29, 2026
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
suspend race fix #17588
Closed
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
child5 #17695
Closed
This was referenced Oct 20, 2026
fix iouring zerocopy iov overwrite #17936
Closed
crisp nova cceda091 #18109
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer requested changes
@chrisvest chrisvest chrisvest approved these changes
@yawkat yawkat Awaiting requested review from yawkat

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.8.Final

Development

Successfully merging this pull request may close these issues.

HttpServerCodec always constructs an "EmptyLastHttpContent" and passes it to the Handler chain when processing OPTIONS requests

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@skyguard1 @normanmaurer @chrisvest @code-xing-wcar
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.