grpc / grpc-swift

The Swift language implementation of gRPC.
Apache License 2.0
2.04k stars 420 forks source link

Setting CallOptions.customMetadata doesn't lowercase the set headers #722

Closed davidpasztor closed 4 years ago

davidpasztor commented 4 years ago

Question Checklist

Question Subject

Call headers should be lowercased by the framework.

Question Description

On the nio branch, setting customMetadata on CallOptions doesn't lowercase the headers when we set them using customMetadata.add(name: "myHeader", value: "VALUE") even though the HTTP2 standard specifies that all HTTP2 headers must be lowercase (and gRPC uses HTTP2).

This can easily lead to issues when a consumer of grpc-swift sends headers in their uppercased form, since HTTP1 headers were case-insensitive, but HTTP2 headers aren't. In my opinion, it would be a good if grpc-swift handled this internally and hence wouldn't require consumers of the library to know about the inner workings of HTTP2 headers. Is this a known issue/viable change request?

MrMage commented 4 years ago

CC @lukasa

Lukasa commented 4 years ago

swift-nio-http2 doesn't automatically lowercase the headers. This is deliberate: we wanted to avoid pushing the cost of lowercasing the headers onto every user of NIOHTTP2 even when their applications are already HTTP/2 aware and generating lowercase headers.

This seems like something gRPC should be willing to offer for user-supplied headers. It shouldn't be hard to add, the surface area is not large.

weissi commented 4 years ago

if you use the 2to1 server codec, you can ask NIO to normalise the headers for you: https://apple.github.io/swift-nio-http2/docs/current/NIOHTTP2/Classes/HTTP2ToHTTP1ServerCodec.html#/s:8NIOHTTP223HTTP2ToHTTP1ServerCodecC8streamID20normalizeHTTPHeadersAcA0b6StreamH0V_Sbtcfc

glbrntt commented 4 years ago

This was fixed in #730