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

Verify header field names #191

Merged
merged 2 commits into from
Apr 1, 2020
Merged

Verify header field names #191

merged 2 commits into from
Apr 1, 2020

Conversation

fabianfett
Copy link
Member

This pr builds on top of #189 and will need a rebase once the former is merged.

Motivation

Having spent about four hours today debugging AsyncHTTPClient just to find out I had a whitespace instead of a dash in my http header field name, I decided I want to save somebody else's time – probably future me.

User Agent vs User-Agent

Changes

  • Added a method: HTTPHeaders.validateFieldNames() throws
  • Added an error .invalidHeaderFieldNames([String])

Result

Hours of time saved. Karma for me.

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@weissi weissi requested review from artemredkin and Lukasa March 31, 2020 17:34
@weissi weissi added the 🆕 semver/minor Adds new public API. label Mar 31, 2020
@weissi weissi added this to the 1.2.0 milestone Mar 31, 2020
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

One minor note

//
// The presence of a message-body in a request is signaled by the inclusion of a
// Content-Length or Transfer-Encoding header field in the request's message-headers.
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

RFC 2616 is dead, let's stop citing it. It's RFC 7230 section 3.3. However, this change is not cautious enough: if there's no body, but the request verb is POST, "Content-Length: 0" is mandatory. Content-Length: 0 is also harmless on all request types that do not define a body. A patch that users this escape hatch on only GET, HEAD, DELETE, CONNECT, and TRACE would be acceptable though, so long as it sends C-L 0 everywhere else.

@fabianfett fabianfett requested a review from Lukasa April 1, 2020 06:58
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Love it. If we fix up the compile errors this should be good to go.

@fabianfett
Copy link
Member Author

@Lukasa Compile errors are fixed. There are some failing tests though (nothing I touched).

@artemredkin
Copy link
Collaborator

@fabianfett it seems that most tests fail due to change in behaviour, Content-Length: 0 was expected in those tests, but now it's missing

@fabianfett
Copy link
Member Author

@artemredkin ow shoot. fixed.

@artemredkin
Copy link
Collaborator

awesome, thanks! there is one failing test, but this one is flaky (#175), I'll try to run tests again

@artemredkin
Copy link
Collaborator

@swift-server-bot test this please

@weissi
Copy link
Contributor

weissi commented Apr 1, 2020

@fabianfett From what I can tell, we're good but would you mind checking if we have a test case which covers this #146 ? If yes, we're all good, if no we might want to add it here?

@artemredkin
Copy link
Collaborator

@swift-server-bot test this please

2 similar comments
@artemredkin
Copy link
Collaborator

@swift-server-bot test this please

@artemredkin
Copy link
Collaborator

@swift-server-bot test this please

@artemredkin
Copy link
Collaborator

thank you @fabianfett !

@artemredkin artemredkin merged commit 2d88de3 into swift-server:master Apr 1, 2020
@fabianfett fabianfett deleted the ff-verify-header-field-names branch April 1, 2020 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants