Skip to content

Commit

Permalink
fix auth header bug and pass request metadata to interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
anitarua committed Aug 14, 2024
1 parent 077a2ae commit 8a23641
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {StatusObject} from '@grpc/grpc-js';
import {Metadata, StatusObject} from '@grpc/grpc-js';
import {ClientMethodDefinition} from '@grpc/grpc-js/build/src/make-client';

export interface EligibleForRetryProps {
grpcStatus: StatusObject;
grpcRequest: ClientMethodDefinition<unknown, unknown>;
requestMetadata?: Metadata;
}

export interface EligibilityStrategy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {StatusObject} from '@grpc/grpc-js';
import {Metadata, StatusObject} from '@grpc/grpc-js';
import {ClientMethodDefinition} from '@grpc/grpc-js/build/src/make-client';

export interface DeterminewhenToRetryRequestProps {
grpcStatus: StatusObject;
grpcRequest: ClientMethodDefinition<unknown, unknown>;
attemptNumber: number;
requestMetadata?: Metadata;
}

export interface RetryStrategy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class HeaderInterceptorProvider {
return (options, nextCall) => {
return new InterceptingCall(nextCall(options), {
start: (metadata, listener, next) => {
this.headersToAddEveryTime.forEach(h =>
metadata.add(h.name, h.value)
);
this.headersToAddEveryTime.forEach(h => {
metadata.set(h.name, h.value);
});
if (!this.areOnlyOnceHeadersSent) {
this.areOnlyOnceHeadersSent = true;
this.headersToAddOnce.forEach(h => metadata.add(h.name, h.value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class RetryInterceptor {
grpcStatus: status,
grpcRequest: options.method_definition,
attemptNumber: attempts,
requestMetadata: metadata,
});

if (whenToRetry === null) {
Expand Down

0 comments on commit 8a23641

Please sign in to comment.