Skip to content

Commit

Permalink
grpc-js-core: ignore reserved headers in fromHttp2Headers()
Browse files Browse the repository at this point in the history
Metadata.fromHttp2Headers() throws if any reserved headers
are passed. Instead of deleting headers before calling the
function, this commit causes the function to ignore reserved
headers.
  • Loading branch information
cjihrig committed Sep 9, 2018
1 parent b7b45e6 commit 0c606f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/grpc-js-core/src/call-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ export class Http2CallStream extends Duplex implements Call {
default:
this.mappedStatusCode = Status.UNKNOWN;
}
delete headers[HTTP2_HEADER_STATUS];
delete headers[HTTP2_HEADER_CONTENT_TYPE];

if (flags & http2.constants.NGHTTP2_FLAG_END_STREAM) {
this.handleTrailers(headers);
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/grpc-js-core/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ export class Metadata {
static fromHttp2Headers(headers: http2.IncomingHttpHeaders): Metadata {
const result = new Metadata();
forOwn(headers, (values, key) => {
// Reserved headers (beginning with `:`) are not valid keys.
if (key.charAt(0) === ':') {
return;
}

if (isBinaryKey(key)) {
if (Array.isArray(values)) {
values.forEach((value) => {
Expand Down

0 comments on commit 0c606f4

Please sign in to comment.