From ea9f7ecc156ffa3304cdad733702978a190a30c5 Mon Sep 17 00:00:00 2001 From: Andrzej Wielski Date: Sat, 2 Oct 2021 02:43:13 +0300 Subject: [PATCH 1/3] update parseTrailer function to support empty trailers & trailers with colon in content --- packages/grpcweb-transport/src/grpc-web-format.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/grpcweb-transport/src/grpc-web-format.ts b/packages/grpcweb-transport/src/grpc-web-format.ts index f0dfee66..32241c9f 100644 --- a/packages/grpcweb-transport/src/grpc-web-format.ts +++ b/packages/grpcweb-transport/src/grpc-web-format.ts @@ -300,7 +300,10 @@ function parseMetadata(headers: HttpHeaders): RpcMetadata { function parseTrailer(trailerData: Uint8Array): HttpHeaders { let headers: HttpHeaders = {}; for (let chunk of String.fromCharCode.apply(String, trailerData as unknown as number[]).trim().split("\r\n")) { - let [key, value] = chunk.split(":", 2); + if (chunk == "") + continue; + let [key, ...val] = chunk.split(":"); + let value = val.join(":") key = key.trim(); value = value.trim(); let e = headers[key]; From 6d4b9dad93bf2d862a80e2aa2945a00d7c1415dd Mon Sep 17 00:00:00 2001 From: Andrzej Wielski Date: Sat, 2 Oct 2021 03:11:49 +0300 Subject: [PATCH 2/3] fix typo --- packages/grpcweb-transport/src/grpc-web-format.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grpcweb-transport/src/grpc-web-format.ts b/packages/grpcweb-transport/src/grpc-web-format.ts index 32241c9f..84f14d93 100644 --- a/packages/grpcweb-transport/src/grpc-web-format.ts +++ b/packages/grpcweb-transport/src/grpc-web-format.ts @@ -303,7 +303,7 @@ function parseTrailer(trailerData: Uint8Array): HttpHeaders { if (chunk == "") continue; let [key, ...val] = chunk.split(":"); - let value = val.join(":") + let value = val.join(":"); key = key.trim(); value = value.trim(); let e = headers[key]; From ced38d7818b6356e9d798305f3ee05f19e84928f Mon Sep 17 00:00:00 2001 From: Andrzej Wielski Date: Sun, 3 Oct 2021 04:44:10 +0300 Subject: [PATCH 3/3] Combine join & trim operations in one line Co-authored-by: James Wyatt Cready-Pyle --- packages/grpcweb-transport/src/grpc-web-format.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/grpcweb-transport/src/grpc-web-format.ts b/packages/grpcweb-transport/src/grpc-web-format.ts index 84f14d93..b435e3e6 100644 --- a/packages/grpcweb-transport/src/grpc-web-format.ts +++ b/packages/grpcweb-transport/src/grpc-web-format.ts @@ -303,9 +303,8 @@ function parseTrailer(trailerData: Uint8Array): HttpHeaders { if (chunk == "") continue; let [key, ...val] = chunk.split(":"); - let value = val.join(":"); + const value = val.join(":").trim(); key = key.trim(); - value = value.trim(); let e = headers[key]; if (typeof e == "string") headers[key] = [e, value];