From d4e16720710de693ac54108864bfd7710c1920cc Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 20 Mar 2019 15:16:52 -0700 Subject: [PATCH] JS: Add initial metadata options API compatibility --- PACKAGE-COMPARISON.md | 1 + packages/grpc-js/src/metadata.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/PACKAGE-COMPARISON.md b/PACKAGE-COMPARISON.md index 2b32adaf..0015d25c 100644 --- a/PACKAGE-COMPARISON.md +++ b/PACKAGE-COMPARISON.md @@ -18,6 +18,7 @@ HTTP Connect Support | :heavy_check_mark: | :x: Retries | :heavy_check_mark: | :x: Stats/tracing/monitoring | :heavy_check_mark: | :x: Load Balancing | :heavy_check_mark: | :x: +Initial Metadata Options | :heavy_check_mark: | :x: Other Properties | `grpc` | `@grpc/grpc-js` -----------------|--------|---------------- diff --git a/packages/grpc-js/src/metadata.ts b/packages/grpc-js/src/metadata.ts index 09a6f883..0114e494 100644 --- a/packages/grpc-js/src/metadata.ts +++ b/packages/grpc-js/src/metadata.ts @@ -44,12 +44,27 @@ function validate(key: string, value?: MetadataValue): void { } } +interface MetadataOptions { + /* Signal that the request is idempotent. Defaults to false */ + idempotentRequest?: boolean; + /* Signal that the call should not return UNAVAILABLE before it has + * started. Defaults to true. */ + waitForReady?: boolean; + /* Signal that the call is cacheable. GRPC is free to use GET verb. + * Defaults to false */ + cacheableRequest?: boolean; + /* Signal that the initial metadata should be corked. Defaults to false. */ + corked?: boolean; +} + /** * A class for storing metadata. Keys are normalized to lowercase ASCII. */ export class Metadata { protected internalRepr: MetadataObject = new Map(); + constructor(private options?: MetadataOptions) {} + /** * Sets the given value for the given key by replacing any other values * associated with that key. Normalizes the key. @@ -160,6 +175,10 @@ export class Metadata { }); } + setOptions(options: MetadataOptions) { + this.options = options; + } + /** * Creates an OutgoingHttpHeaders object that can be used with the http2 API. */