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

Refactor Request Validation #391

Merged

Conversation

fabianfett
Copy link
Member

Motivation

Currently the request validation (mainly checking for correct headers is sprinkled around). This makes reuse in new code hard.

Changes

  • Refactored code from TaskHandler into new method HTTPClient.Request.createRequestHead that creates an HTTPRequestHead and matching RequestFramingMetadata
  • Added required property requestFramingMetadata to HTTPExecutingRequest
  • Added property requestFramingMetadata to RequestBag

@fabianfett fabianfett added the semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Jul 7, 2021
@fabianfett fabianfett force-pushed the ff-refactor-request-validation branch from 6e1fa34 to 0d47360 Compare July 7, 2021 13:01
struct RequestFramingMetadata {
enum Body {
struct RequestFramingMetadata: Equatable {
enum Body: Equatable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make these Hashable: Equatable by itself is rarely sensible.

// This assert can go away when (if ever!) the above `if` correctly handles other HTTP versions. For example
// in HTTP/1.0, we need to treat the absence of a 'connection: keep-alive' as a close too.
assert(head.version == HTTPVersion(major: 1, minor: 1),
"Sending a request in HTTP version \(head.version) which is unsupported by the above `if`")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this assert is meaningfully enforcing here, is it? You (rightly) kept the original, but this one seems superfluous.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I still don't think this assertion is useful. We literally set the HTTP version to a hardcoded constant just above.

Sources/AsyncHTTPClient/RequestValidation.swift Outdated Show resolved Hide resolved
@fabianfett fabianfett added this to the HTTP/2 support milestone Jul 7, 2021
@fabianfett fabianfett force-pushed the ff-refactor-request-validation branch from 6a6fd09 to f9f1050 Compare July 7, 2021 17:02
@fabianfett fabianfett merged commit bccb075 into swift-server:main Jul 7, 2021
@fabianfett fabianfett deleted the ff-refactor-request-validation branch July 7, 2021 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants