Allow mixed-case headers (#1334)

This commit is contained in:
Eryu Xia 2023-05-14 03:12:19 -07:00 committed by GitHub
parent f8fbbe32f9
commit c4f0905288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -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_];
@ -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(