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 — Implement Early hints response status, do not poll the encoding with HTTP 1xx codes by cavallium · Pull Request #12918 · netty/netty

Conversation

@cavallium

@cavallium cavallium commented Oct 20, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation:

  • 103 Early Hints response status is missing
  • Http 1xx codes should expect another response next

Modifications:

  • Add 103 Early Hints response status
  • Replace code == 100 with code == 1xx

Result:

Fixes #12904 and eclipse-vertx/vert.x#4508

Sorry, something went wrong.

Uh oh!

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

All reactions
@cavallium
Do not poll the encoding with HTTP 1xx codes
a7c9e46
Motivation:

Http 1xx codes should expect another response next

Modifications:

Replace code == 100 with code == 1xx

Result:

Fixes netty#12904
@cavallium

cavallium commented Oct 20, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

I didn't modify the http2 codec because I currently can't test it and I don't know the HTTP2 protocol very well, someone else should take a look at it.

This issue also affects netty 5, should I open another PR?

All reactions

Sorry, something went wrong.

Uh oh!

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

@cavallium
Fix max line length
e3eee79
@normanmaurer

normanmaurer commented Oct 20, 2022

Copy link
Copy Markdown
Member

@cavallium can you please add a unit test ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@cavallium cavallium changed the title Do not poll the encoding with HTTP 1xx codes Implement Early hints response status, do not poll the encoding with HTTP 1xx codes Oct 26, 2022
cavallium added 2 commits October 26, 2022 14:00
@cavallium
Add 103 Early hints response status
72927b4
@cavallium
Add unit test for issue netty#12904
0d126ef
@cavallium

cavallium commented Oct 26, 2022

Copy link
Copy Markdown
Contributor Author

@cavallium can you please add a unit test ?

Done.
Now I still need to check the HTTP2 code.

All reactions

Sorry, something went wrong.

Uh oh!

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

cavallium added 2 commits October 26, 2022 14:37
@cavallium
Implement 1xx Informational Response codes properly
d557ee2
RFC7540:
An informational response using a 1xx status code other than 101 is
   transmitted as a HEADERS frame, followed by zero or more CONTINUATION
   frames.

   Trailing header fields are sent as a header block after both the
   request or response header block and all the DATA frames have been
   sent.  The HEADERS frame starting the trailers header block has the
   END_STREAM flag set.
@cavallium
Test 103 Early Hints
8f947e2
@cavallium

cavallium commented Oct 26, 2022

Copy link
Copy Markdown
Contributor Author

I implemented the HTTP/2 code

All reactions

Sorry, something went wrong.

Uh oh!

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

normanmaurer
normanmaurer approved these changes Oct 31, 2022
View reviewed changes
@normanmaurer
normanmaurer requested review from chrisvest and idelpivnitskiy October 31, 2022 09:53
@normanmaurer

normanmaurer commented Oct 31, 2022

Copy link
Copy Markdown
Member

@idelpivnitskiy @chrisvest PTAL as well

All reactions

Sorry, something went wrong.

Uh oh!

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

chrisvest
chrisvest reviewed Nov 1, 2022
View reviewed changes
Comment thread codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java Resolved

Uh oh!

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

@cavallium
Test 103 Early Hints in a dedicated test
cb56e7d
chrisvest
chrisvest approved these changes Nov 1, 2022
View reviewed changes
@chrisvest

chrisvest commented Nov 1, 2022

Copy link
Copy Markdown
Member

This issue also affects netty 5, should I open another PR?

Yeah, please make this a separate PR for Netty 5. There are enough differences between the two versions that it'd be good to get a PR build before integrating.

All reactions

Sorry, something went wrong.

Uh oh!

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

idelpivnitskiy
idelpivnitskiy approved these changes Nov 2, 2022
View reviewed changes
Comment thread codec-http/src/main/java/io/netty/handler/codec/http/HttpContentEncoder.java Resolved

Uh oh!

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

cavallium added 2 commits November 2, 2022 23:51
@cavallium
Use HttpStatusClass when possible
c8d1ae2
@cavallium
Fix indentation
d3488fb
@cavallium

cavallium commented Nov 2, 2022

Copy link
Copy Markdown
Contributor Author

I've replaced the code range with HttpStatusClass when needed

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer merged commit de8a7ef into netty:4.1 Nov 3, 2022
@normanmaurer

normanmaurer commented Nov 3, 2022

Copy link
Copy Markdown
Member

@cavallium thanks a lot!

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.1.85.Final milestone Nov 3, 2022
normanmaurer pushed a commit that referenced this pull request Nov 3, 2022
@cavallium @normanmaurer
Implement Early hints response status, do not poll the encoding with …
37ce73e
…HTTP 1xx codes (#12918)

Motivation:

Http 1xx codes should expect another response next

Modifications:

Replace code == 100 with code == 1xx

Result:

Fixes #12904
This was referenced Aug 1, 2026
HttpServerCodec: 1xx interim responses consume the HEAD method queue, misaligning subsequent responses #17181
Closed
HttpServerCodec: do not consume the method queue for 1xx interim responses #17182
Merged
normanmaurer added a commit that referenced this pull request Aug 3, 2026
@HwangRock @normanmaurer
HttpServerCodec: do not consume the method queue for 1xx interim re…
ae41417
…sponses (#17182)

### Motivation

Resolves #17181.

#12918 stopped 1xx interim responses from consuming a queue entry in
`HttpClientCodec` and `HttpContentEncoder`, but `HttpServerCodec` was
left out.

`isContentAlwaysEmpty(HttpResponse)` in `HttpServerCodec` polls the
request method queue for every response it encodes:

```java
@OverRide
protected boolean isContentAlwaysEmpty(HttpResponse msg) {
    methodFlag = pollMethod();
    return methodFlag == METHOD_FLAG_HEAD || super.isContentAlwaysEmpty(msg);
}
```

It is invoked for every `HttpResponse` on both encoder paths —
`encodeFullHttpMessage()` and `encodeInitHttpMessage()` in
`HttpObjectEncoder`. An interim response is not the final response to
the queued request, so consuming an entry shifts the queue by one and
the wrong method gets paired with the final response.

Both failure modes are reachable from first-party handlers:
`HttpServerExpectContinueHandler` and `HttpObjectAggregator` write `100
Continue` through this encoder.

### Modification

Skip `pollMethod()` when the response status class is `INFORMATIONAL`
and delegate to the super method, mirroring the guard already present in
`isContentAlwaysEmpty(HttpMessage)` in `HttpClientCodec`.

`methodFlag` is intentionally left untouched on the interim path.
`sanitizeHeadersBeforeEncode()` reads it for the CONNECT check, but that
branch also requires `codeClass() == SUCCESS`, which a 1xx response
never satisfies.

### Result

Interim responses no longer shift the method queue, so HEAD and CONNECT
are paired with their own final response.

Encoder output for the two broken cases, measured with the tests added
here:

| scenario | before | after |
|---|---|---|
| `HEAD /a`, then `103`, then final `200 OK` with content | `HTTP/1.1
200 OK\r\ncontent-length: 4\r\n\r\nbody` | `HTTP/1.1 200
OK\r\ncontent-length: 4\r\n\r\n` |
| pipelined `GET /a` + `HEAD /b`, then `103`, then `/a`'s `200 OK` with
content | `HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\n` | `HTTP/1.1 200
OK\r\ncontent-length: 6\r\n\r\nbody-a` |
| `HEAD /` with `Upgrade`, then `101` | `HTTP/1.1 101 Switching
Protocols\r\nconnection: upgrade\r\nupgrade: websocket\r\n\r\n` |
unchanged |

The first row is a HEAD response carrying a body, which per RFC 9110
section 9.3.2 must never happen — on a keep-alive connection the peer
reads those bytes as the start of the next response. The second is a
non-HEAD response losing its body while keeping `Content-Length`,
leaving the peer waiting for six bytes that never arrive.

Sequential request/response traffic recovers on its own, since an empty
queue falls back to `METHOD_FLAG_OTHER`. Corruption needs either a 1xx
preceding a HEAD response, or pipelining combined with a 1xx.

101 is included in `INFORMATIONAL` and is therefore covered by the
guard, with no change on the wire. After switching protocols the codec
is removed from the pipeline — by `upgradeFrom()` in `HttpServerCodec`
for h2c, and by `WebSocketServerHandshaker` for WebSocket — so the entry
left behind is discarded together with the handler. The third row above
pins this.

This also corrects CONNECT: previously a 1xx could consume the CONNECT
entry, so the final 2xx response missed the `Transfer-Encoding`
stripping in `sanitizeHeadersBeforeEncode()`.

`codec-http` passes in full: 8973 tests, 0 failures.

Co-authored-by: Norman Maurer <[email protected]>
@netty-project-bot netty-project-bot mentioned this pull request Aug 3, 2026
Auto-port 5.0: HttpServerCodec: do not consume the method queue for 1xx interim responses #17202
Merged
chrisvest added a commit that referenced this pull request Aug 3, 2026
@netty-project-bot @HwangRock
@normanmaurer @chrisvest
Auto-port 5.0: HttpServerCodec: do not consume the method queue for…
c6e285e
… 1xx interim responses (#17202)

Auto-port of #17182 to 5.0
Cherry-picked commit: ae41417

---
### Motivation

Resolves #17181.

#12918 stopped 1xx interim responses from consuming a queue entry in
`HttpClientCodec` and `HttpContentEncoder`, but `HttpServerCodec` was
left out.

`isContentAlwaysEmpty(HttpResponse)` in `HttpServerCodec` polls the
request method queue for every response it encodes:

```java
@OverRide
protected boolean isContentAlwaysEmpty(HttpResponse msg) {
    methodFlag = pollMethod();
    return methodFlag == METHOD_FLAG_HEAD || super.isContentAlwaysEmpty(msg);
}
```

It is invoked for every `HttpResponse` on both encoder paths —
`encodeFullHttpMessage()` and `encodeInitHttpMessage()` in
`HttpObjectEncoder`. An interim response is not the final response to
the queued request, so consuming an entry shifts the queue by one and
the wrong method gets paired with the final response.

Both failure modes are reachable from first-party handlers:
`HttpServerExpectContinueHandler` and `HttpObjectAggregator` write `100
Continue` through this encoder.

### Modification

Skip `pollMethod()` when the response status class is `INFORMATIONAL`
and delegate to the super method, mirroring the guard already present in
`isContentAlwaysEmpty(HttpMessage)` in `HttpClientCodec`.

`methodFlag` is intentionally left untouched on the interim path.
`sanitizeHeadersBeforeEncode()` reads it for the CONNECT check, but that
branch also requires `codeClass() == SUCCESS`, which a 1xx response
never satisfies.

### Result

Interim responses no longer shift the method queue, so HEAD and CONNECT
are paired with their own final response.

Encoder output for the two broken cases, measured with the tests added
here:

| scenario | before | after |
|---|---|---|
| `HEAD /a`, then `103`, then final `200 OK` with content | `HTTP/1.1
200 OK\r\ncontent-length: 4\r\n\r\nbody` | `HTTP/1.1 200
OK\r\ncontent-length: 4\r\n\r\n` |
| pipelined `GET /a` + `HEAD /b`, then `103`, then `/a`'s `200 OK` with
content | `HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\n` | `HTTP/1.1 200
OK\r\ncontent-length: 6\r\n\r\nbody-a` |
| `HEAD /` with `Upgrade`, then `101` | `HTTP/1.1 101 Switching
Protocols\r\nconnection: upgrade\r\nupgrade: websocket\r\n\r\n` |
unchanged |

The first row is a HEAD response carrying a body, which per RFC 9110
section 9.3.2 must never happen — on a keep-alive connection the peer
reads those bytes as the start of the next response. The second is a
non-HEAD response losing its body while keeping `Content-Length`,
leaving the peer waiting for six bytes that never arrive.

Sequential request/response traffic recovers on its own, since an empty
queue falls back to `METHOD_FLAG_OTHER`. Corruption needs either a 1xx
preceding a HEAD response, or pipelining combined with a 1xx.

101 is included in `INFORMATIONAL` and is therefore covered by the
guard, with no change on the wire. After switching protocols the codec
is removed from the pipeline — by `upgradeFrom()` in `HttpServerCodec`
for h2c, and by `WebSocketServerHandshaker` for WebSocket — so the entry
left behind is discarded together with the handler. The third row above
pins this.

This also corrects CONNECT: previously a 1xx could consume the CONNECT
entry, so the final 2xx response missed the `Transfer-Encoding`
stripping in `sanitizeHeadersBeforeEncode()`.

`codec-http` passes in full: 8973 tests, 0 failures.

---------

Co-authored-by: HwangRock <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Co-authored-by: Chris Vest <[email protected]>
@He-Pin He-Pin mentioned this pull request Nov 17, 2026
Handle informational HTTP/2 responses before the final response apache/pekko-http#1450
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chrisvest chrisvest chrisvest approved these changes
@normanmaurer normanmaurer normanmaurer approved these changes
@idelpivnitskiy idelpivnitskiy idelpivnitskiy approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.85.Final

Development

Successfully merging this pull request may close these issues.

Exception when using other "1xx Informational Response" codes

Uh oh!

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

4 participants

@cavallium @normanmaurer @chrisvest @idelpivnitskiy
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.