mirror of https://github.com/grpc/grpc-node.git
Merge pull request #2305 from murgatroid99/grpc-js_trailers_only_default_headers
grpc-js: Add HTTP status and content type headers to trailers-only responses
This commit is contained in:
commit
fbfa73cdc8
|
@ -63,11 +63,13 @@ const deadlineUnitsToMs: DeadlineUnitIndexSignature = {
|
||||||
u: 0.001,
|
u: 0.001,
|
||||||
n: 0.000001,
|
n: 0.000001,
|
||||||
};
|
};
|
||||||
const defaultResponseHeaders = {
|
const defaultCompressionHeaders = {
|
||||||
// TODO(cjihrig): Remove these encoding headers from the default response
|
// TODO(cjihrig): Remove these encoding headers from the default response
|
||||||
// once compression is integrated.
|
// once compression is integrated.
|
||||||
[GRPC_ACCEPT_ENCODING_HEADER]: 'identity,deflate,gzip',
|
[GRPC_ACCEPT_ENCODING_HEADER]: 'identity,deflate,gzip',
|
||||||
[GRPC_ENCODING_HEADER]: 'identity',
|
[GRPC_ENCODING_HEADER]: 'identity',
|
||||||
|
}
|
||||||
|
const defaultResponseHeaders = {
|
||||||
[http2.constants.HTTP2_HEADER_STATUS]: http2.constants.HTTP_STATUS_OK,
|
[http2.constants.HTTP2_HEADER_STATUS]: http2.constants.HTTP_STATUS_OK,
|
||||||
[http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'application/grpc+proto',
|
[http2.constants.HTTP2_HEADER_CONTENT_TYPE]: 'application/grpc+proto',
|
||||||
};
|
};
|
||||||
|
@ -500,7 +502,7 @@ export class Http2ServerCallStream<
|
||||||
this.metadataSent = true;
|
this.metadataSent = true;
|
||||||
const custom = customMetadata ? customMetadata.toHttp2Headers() : null;
|
const custom = customMetadata ? customMetadata.toHttp2Headers() : null;
|
||||||
// TODO(cjihrig): Include compression headers.
|
// TODO(cjihrig): Include compression headers.
|
||||||
const headers = { ...defaultResponseHeaders, ...custom };
|
const headers = { ...defaultResponseHeaders, ...defaultCompressionHeaders, ...custom };
|
||||||
this.stream.respond(headers, defaultResponseOptions);
|
this.stream.respond(headers, defaultResponseOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,9 +727,11 @@ export class Http2ServerCallStream<
|
||||||
this.stream.end();
|
this.stream.end();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Trailers-only response
|
||||||
const trailersToSend = {
|
const trailersToSend = {
|
||||||
[GRPC_STATUS_HEADER]: statusObj.code,
|
[GRPC_STATUS_HEADER]: statusObj.code,
|
||||||
[GRPC_MESSAGE_HEADER]: encodeURI(statusObj.details),
|
[GRPC_MESSAGE_HEADER]: encodeURI(statusObj.details),
|
||||||
|
...defaultResponseHeaders,
|
||||||
...statusObj.metadata?.toHttp2Headers(),
|
...statusObj.metadata?.toHttp2Headers(),
|
||||||
};
|
};
|
||||||
this.stream.respond(trailersToSend, {endStream: true});
|
this.stream.respond(trailersToSend, {endStream: true});
|
||||||
|
|
Loading…
Reference in New Issue