grpc-swift icon indicating copy to clipboard operation
grpc-swift copied to clipboard

Duplicate content_type headers

Open ialimz opened this issue 4 years ago • 2 comments

Describe the bug

If we set content_type header in custom_metadata (application/grpc), the library itself adds content_type header too. So the request contains duplicate content_type headers and this could be lead to failure if the server doesn't handle duplication.

ialimz avatar Aug 10 '21 09:08 ialimz

We should certainly handle this -- and other user provided headers -- better than we do now. I'm undecided whether in the general case we should defer to user provided values or remove duplicates. It probably depends on the header name (i.e. "content-type" feels like one we should add only if the user didn't provide one yet something like ":path" should be ignored or emit an error if a user provides it).

Out of curiosity, why do you set a custom content-type header?

glbrntt avatar Aug 11 '21 14:08 glbrntt

Thanks @glbrntt.

Since we use other protocols for our requests(like HTTP and octet-stream types), we have defined a RequestHeaderProtocol in our app which services(containing gRPC service) get their headers from there. One of the headers this protocol puts in headers is content-type. After found that this issue exists, I removed this header from GRPCHeader: RequestHeaderProtocol, and the problem was solved.

I saw many gRPC clients on mac don't allow the user to set duplicate headers. So I agree with you that any pre-defined header set in custom metadata should be ignored before the request happens.

ialimz avatar Aug 11 '21 16:08 ialimz