Skip to content

Verify header field names#191

Merged
artemredkin merged 2 commits into
swift-server:masterfrom
fabianfett:ff-verify-header-field-names
Apr 1, 2020
Merged

Verify header field names#191
artemredkin merged 2 commits into
swift-server:masterfrom
fabianfett:ff-verify-header-field-names

Conversation

@fabianfett

Copy link
Copy Markdown
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.

@weissi weissi left a comment

Copy link
Copy Markdown
Contributor

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 Lukasa and artemredkin 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

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Member Author

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

@artemredkin

Copy link
Copy Markdown
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
Copy Markdown
Member Author

@artemredkin ow shoot. fixed.

@artemredkin

Copy link
Copy Markdown
Collaborator

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

@artemredkin

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

Comment thread Tests/AsyncHTTPClientTests/RequestValidationTests.swift Outdated
@weissi

weissi commented Apr 1, 2020

Copy link
Copy Markdown
Contributor

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

Comment thread Tests/AsyncHTTPClientTests/RequestValidationTests.swift
@artemredkin

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

2 similar comments
@artemredkin

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

@artemredkin

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

@artemredkin

Copy link
Copy Markdown
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