-
Notifications
You must be signed in to change notification settings - Fork 419
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
Add a gRPC Web to HTTP/2 codec #1047
Conversation
) -> GRPCWebToHTTP2ServerCodec.StateMachine.Action { | ||
switch self { | ||
case .idle: | ||
var headers = HPACKHeaders(httpHeaders: head.headers, normalizeHTTPHeaders: true) |
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.
Should we reserve capacity here?
case .idle: | ||
var headers = HPACKHeaders(httpHeaders: head.headers, normalizeHTTPHeaders: true) | ||
headers.add(name: ":path", value: head.uri) | ||
headers.add(name: ":method", value: head.method.rawValue) |
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.
These pseudo-headers are surely not going to be in the right place in the block, right? And I think we're missing two: :authority
and :scheme
are both expected as well.
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 didn't think the order mattered given these will only be read by the HTTP/2 to gRPC codec? Easy enough to change though.
I wasn't sure about including :authority
and :scheme
; they're also not required but I suppose they might be expected by a user in e.g. an interceptor. WDYT?
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'm inclined to suggest that we should do the right thing here. It reduces the risk that we might accidentally introduce a component that doesn't expect this and get issues down the road. The same applies to adding the extra headers.
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.
That seems wise. Done!
self.init() | ||
self.reserveCapacity(headers.count) | ||
// Don't add any pseudo-headers. | ||
for (name, value, _) in headers where name.utf8.first != .some(UInt8(ascii: ":")) { |
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.
There's a mild perf improvement available here: well-formatted HTTP/2 header blocks must have all their pseudo-headers first. You can therefore do a dropFirst(where:)
to only look at the minimal number of headers and then just do add(contentsOf:)
or similar to reduce the amount of unnecessary checking you do.
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.
Oh, smart thinking, I like it!
Motivation: Following from grpc#1041, we'd like to switch our currency type on the server from HTTP/1 to HTTP/2. This means that to retain support for gRPC Web we need a codec to convert between HTTP/1 and HTTP/2 in the opposite direction to the codecs provided by NIO HTTP/2. Modifications: - Add a gRPC Web to HTTP2 codec Result: - Nothing yet, as this remains unused.
Motivation:
Following from #1041, we'd like to switch our currency type on the
server from HTTP/1 to HTTP/2. This means that to retain support for gRPC
Web we need a codec to convert between HTTP/1 and HTTP/2 in the opposite
direction to the codecs provided by NIO HTTP/2.
Modifications:
Result: