Skip to content

Commit

Permalink
Allow mixed-case headers
Browse files Browse the repository at this point in the history
  • Loading branch information
sampajano committed May 14, 2023
1 parent f8fbbe3 commit 1f36f76
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions javascript/net/grpc/web/grpcwebclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,15 @@ class GrpcWebClientReadableStream {
let grpcStatusMessage = '';
const initialMetadata = /** @type {!Metadata} */ ({});

const responseHeaders = self.xhr_.getResponseHeaders();
// Get response headers with lower case keys.
const rawResponseHeaders = self.xhr_.getResponseHeaders();
const responseHeaders = {};
for (const key in rawResponseHeaders) {
if (rawResponseHeaders.hasOwnProperty(key)) {
responseHeaders[key.toLowerCase()] = rawResponseHeaders[key];
}
}

Object.keys(responseHeaders).forEach((header_) => {
if (!(EXCLUDED_RESPONSE_HEADERS.includes(header_))) {
initialMetadata[header_] = responseHeaders[header_];
Expand Down Expand Up @@ -262,9 +270,9 @@ class GrpcWebClientReadableStream {
// Check whethere there are grpc specific response headers
if (GRPC_STATUS in responseHeaders) {
grpcStatusCode = /** @type {!StatusCode} */ (
Number(self.xhr_.getResponseHeader(GRPC_STATUS)));
Number(responseHeaders[GRPC_STATUS]));
if (GRPC_STATUS_MESSAGE in responseHeaders) {
grpcStatusMessage = self.xhr_.getResponseHeader(GRPC_STATUS_MESSAGE);
grpcStatusMessage = responseHeaders[GRPC_STATUS_MESSAGE];
}
if (grpcStatusCode != StatusCode.OK) {
self.handleError_(new RpcError(
Expand Down

0 comments on commit 1f36f76

Please sign in to comment.