Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send 103 early hints response when only invalid headers are used #3163

Merged
merged 1 commit into from
May 27, 2023

Conversation

MSP-Greg
Copy link
Member

@MSP-Greg MSP-Greg commented May 22, 2023

Description

While reviewing code in test\test_response_header.rb, I noticed that when invalid headers are returned by the app with 'early hints', the first line of an 'early hints' response (HTTP/1.1 103 Early Hints) is sent without any data/headers.

This PR modifies the code in puma/request.rb to only send the 'early hints' response if at least one header is valid.

Note that with the test changes, current master has the following errors:

TestResponseHeader#test_illegal_character_in_key_when_early_hints [test/test_response_header.rb:128]:
Expected # encoding: ASCII-8BIT
#    valid: true
"HTTP/1.1 103 Early Hints\r\n\r\n" to not include "HTTP/1.1 103 Early Hints".

  2) Failure:
TestResponseHeader#test_illegal_character_in_value_when_early_hints [test_response_header.rb:139]:
Expected # encoding: ASCII-8BIT
#    valid: true
"HTTP/1.1 103 Early Hints\r\n\r\nHTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nHello" to not include "HTTP/1.1 103 Early Hints".

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@MSP-Greg MSP-Greg added the bug label May 22, 2023
@@ -77,7 +77,9 @@ def handle_request(client, requests)
if @early_hints
env[EARLY_HINTS] = lambda { |headers|
begin
fast_write_str socket, str_early_hints(headers)
unless (str = str_early_hints headers).empty?
Copy link
Member

Choose a reason for hiding this comment

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

this double negative is messing with me, but I can't see a better alternative

@MSP-Greg MSP-Greg merged commit 7b7774c into puma:master May 27, 2023
@MSP-Greg MSP-Greg deleted the 00-early-hints-invalid branch May 27, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants