grpc-js-core: ignore reserved headers in fromHttp2Headers()

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.
This commit is contained in:
cjihrig 2018-09-09 14:57:33 -04:00
parent b7b45e6dd7
commit 0c606f4408
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 6 additions and 2 deletions

View File

@ -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 {

View File

@ -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) => {