-
Notifications
You must be signed in to change notification settings - Fork 667
[HTTPDecoder] Decode informational http response head correctly #1984
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
Conversation
72a4a72
to
08a71c9
Compare
Sources/NIOHTTP1/HTTPDecoder.swift
Outdated
} | ||
|
||
/// Strategy to use when a HTTPDecoder receives an informal HTTP response (1xx except 101) | ||
public enum InformalResponseStrategy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: these are not informal responses, they are informational responses. All the terminology in this PR should be changed appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, we should probably use an extensible enum for our API design here (i.e. enum
wrapped in struct
with static let
s.
Sources/NIOHTTP1/HTTPDecoder.swift
Outdated
} else if statusCode / 100 == 1 || // 1XX codes | ||
statusCode == 204 || statusCode == 304 { | ||
|
||
if (HTTPResponseStatus.continue.code <= statusCode && statusCode < HTTPResponseStatus.ok.code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to treat these codes as numbers here.
Sources/NIOHTTP1/HTTPDecoder.swift
Outdated
private let kind: HTTPDecoderKind | ||
private var stopParsing = false // set on upgrade or HTTP version error | ||
private var lastHeaderWasInformal = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really mean "header" here, we mean "response".
Sources/NIOHTTP1/HTTPDecoder.swift
Outdated
status: .init(statusCode: statusCode), | ||
headers: HTTPHeaders(self.headers, | ||
keepAliveState: keepAliveState)) | ||
message = NIOAny(HTTPClientResponsePart.head(resHead)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I propose we wrap the common code in this case and the case below into a single helper?
Sources/NIOHTTP1/HTTPDecoder.swift
Outdated
public enum InformalResponseStrategy { | ||
/// Drop the informal response and only forward the "real" response | ||
case drop | ||
/// Forward the informal response and then forward the "real" response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should clarify what this looks like (namely, multiple .head
messages for a single .end
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice. One minor nit, otherwise I’m happy.
Co-authored-by: Cory Benfield <lukasa@apple.com>
e74a0c9
to
6b36c6f
Compare
We should support HTTP requests that are answered with an informational response first, which is followed up by the actual response. See issue: swift-server/async-http-client#461
Motivation:
Modifications:
InformalResponseStrategy
enum that allows the user to specify whether http 1xx responses shall be forwarded or dropped.HTTPDecoder
andBetterHTTPParser
Result:
We will be able to fix swift-server/async-http-client#461