Skip to content

Respond with 414 when a line exceeds the maximum line length - #238

Open
trevorturk wants to merge 1 commit into
socketry:mainfrom
trevorturk:graceful-line-length-response
Open

Respond with 414 when a line exceeds the maximum line length#238
trevorturk wants to merge 1 commit into
socketry:mainfrom
trevorturk:graceful-line-length-response

Conversation

@trevorturk

Copy link
Copy Markdown
Contributor

Fixes #237.

Previously, when a request line or header line exceeded maximum_line_length, LineLengthError propagated past next_request (it doesn't include the BadRequest marker), so the server closed the connection without writing anything and the peer saw an unexplained EOF.

This PR rescues LineLengthError in next_request and uses the existing fail_request path to respond with 414 before re-raising, matching the existing BadRequest → 400 handling. The request-line and header-line cases can't be distinguished at the rescue site, so both get 414 as the more common case — happy to split the error by phase in protocol-http1 and map 414/431 instead if you'd prefer that precision.

Types of Changes

  • Bug fix.

Contribution

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves HTTP/1 server behavior when an incoming request line or header line exceeds maximum_line_length, ensuring the peer receives a proper HTTP response (414) instead of an unexplained EOF caused by LineLengthError escaping next_request.

Changes:

  • Rescue Protocol::HTTP1::LineLengthError in Async::HTTP::Protocol::HTTP1::Server#next_request and send a 414 via fail_request before re-raising.
  • Add HTTP/1.1 server specs asserting 414 for over-long request lines and header lines.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/async/http/protocol/http1/server.rb Catch LineLengthError during request parsing and write a 414 response before re-raising to avoid silent connection close.
test/async/http/protocol/http11.rb Add regression tests for 414 responses when request line or header lines exceed the configured maximum length.

Comment thread test/async/http/protocol/http11.rb

@ioquatix ioquatix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See feedback.

@trevorturk
trevorturk force-pushed the graceful-line-length-response branch from 77a168e to 278606c Compare August 1, 2026 13:02
@trevorturk

Copy link
Copy Markdown
Contributor Author

Good idea, updated, force pushed back into a single commit.

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.

HTTP/1 server closes the connection without a response when a line exceeds maximum_line_length

3 participants