-
Notifications
You must be signed in to change notification settings - Fork 698
Support users opting-out of us setting framing headers. #2508
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
Motivation: Right now we always set the framing headers in HTTP requests and responses that we send. This is a good practice for most users, but it can cause issues, most notably in responses to CONNECT requests which requires that we do not set framing headers. Unfortunately, in NIO's current HTTP/1.1 design it is not possible for us to suppress these headers. This is because the HTTP encoders come _earlier_ in the pipeline than the decoders, so the HTTP encoders do not know structurally what requests they are responding to. While we could merge the encoders/decoders, that's a fairly substantial change. A better short-term change is to offer users the ability to turn off the NIO header manipulation feature. In this circumstance, users take on full responsibility for appropriately framing their HTTP messages. Modifications - Add config to HTTPRequestEncoder and HTTPResponseEncoder. - Plumb this config through. - Add a bunch of tests. Result Users have way more control of HTTP/1.1 messages.
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.
Looks good! Left a couple of nits inline.
Sources/NIOHTTP1/HTTPEncoder.swift
Outdated
/// encoding, when needed. | ||
private func messageIsChunked(headers: HTTPHeaders, version: HTTPVersion) -> Bool { | ||
if version.major == 1 && version.minor >= 1 { | ||
return headers["transfer-encoding"].first == "chunked" ? true : 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.
nit: headers.first(name: "transfer-encoding")
Sources/NIOHTTP1/HTTPEncoder.swift
Outdated
self.isChunked = correctlyFrameTransportHeaders(hasBody: response.status.mayHaveResponseBody ? .yes : .no, | ||
headers: &response.headers, version: response.version) == .chunked | ||
|
||
if configuration.automaticallySetFramingHeaders { |
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.
if configuration.automaticallySetFramingHeaders { | |
if self.configuration.automaticallySetFramingHeaders { |
Support users opting-out of us setting framing headers. (apple#2508)
Motivation:
Right now we always set the framing headers in HTTP requests and responses that we send. This is a good practice for most users, but it can cause issues, most notably in responses to CONNECT requests which requires that we do not set framing headers.
Unfortunately, in NIO's current HTTP/1.1 design it is not possible for us to suppress these headers. This is because the HTTP encoders come earlier in the pipeline than the decoders, so the HTTP encoders do not know structurally what requests they are responding to.
While we could merge the encoders/decoders, that's a fairly substantial change. A better short-term change is to offer users the ability to turn off the NIO header manipulation feature. In this circumstance, users take on full responsibility for appropriately framing their HTTP messages.
Modifications
Result
Users have way more control of HTTP/1.1 messages.