@@ -96,6 +96,7 @@ public final class GrpcCallContext implements ApiCallContext {
96
96
private final ImmutableMap <String , List <String >> extraHeaders ;
97
97
private final ApiCallContextOptions options ;
98
98
private final EndpointContext endpointContext ;
99
+ private final boolean isDirectPath ;
99
100
100
101
/** Returns an empty instance with a null channel and default {@link CallOptions}. */
101
102
public static GrpcCallContext createDefault () {
@@ -144,6 +145,36 @@ private GrpcCallContext(
144
145
@ Nullable RetrySettings retrySettings ,
145
146
@ Nullable Set <StatusCode .Code > retryableCodes ,
146
147
@ Nullable EndpointContext endpointContext ) {
148
+ this (
149
+ channel ,
150
+ credentials ,
151
+ callOptions ,
152
+ timeout ,
153
+ streamWaitTimeout ,
154
+ streamIdleTimeout ,
155
+ channelAffinity ,
156
+ extraHeaders ,
157
+ options ,
158
+ retrySettings ,
159
+ retryableCodes ,
160
+ endpointContext ,
161
+ false );
162
+ }
163
+
164
+ private GrpcCallContext (
165
+ Channel channel ,
166
+ @ Nullable Credentials credentials ,
167
+ CallOptions callOptions ,
168
+ @ Nullable java .time .Duration timeout ,
169
+ @ Nullable java .time .Duration streamWaitTimeout ,
170
+ @ Nullable java .time .Duration streamIdleTimeout ,
171
+ @ Nullable Integer channelAffinity ,
172
+ ImmutableMap <String , List <String >> extraHeaders ,
173
+ ApiCallContextOptions options ,
174
+ @ Nullable RetrySettings retrySettings ,
175
+ @ Nullable Set <StatusCode .Code > retryableCodes ,
176
+ @ Nullable EndpointContext endpointContext ,
177
+ boolean isDirectPath ) {
147
178
this .channel = channel ;
148
179
this .credentials = credentials ;
149
180
this .callOptions = Preconditions .checkNotNull (callOptions );
@@ -159,6 +190,7 @@ private GrpcCallContext(
159
190
// a valid EndpointContext with user configurations after the client has been initialized.
160
191
this .endpointContext =
161
192
endpointContext == null ? EndpointContext .getDefaultInstance () : endpointContext ;
193
+ this .isDirectPath = isDirectPath ;
162
194
}
163
195
164
196
/**
@@ -210,7 +242,20 @@ public GrpcCallContext withTransportChannel(TransportChannel inputChannel) {
210
242
"Expected GrpcTransportChannel, got " + inputChannel .getClass ().getName ());
211
243
}
212
244
GrpcTransportChannel transportChannel = (GrpcTransportChannel ) inputChannel ;
213
- return withChannel (transportChannel .getChannel ());
245
+ return new GrpcCallContext (
246
+ transportChannel .getChannel (),
247
+ credentials ,
248
+ callOptions ,
249
+ timeout ,
250
+ streamWaitTimeout ,
251
+ streamIdleTimeout ,
252
+ channelAffinity ,
253
+ extraHeaders ,
254
+ options ,
255
+ retrySettings ,
256
+ retryableCodes ,
257
+ endpointContext ,
258
+ transportChannel .isDirectPath ());
214
259
}
215
260
216
261
@ Override
@@ -535,7 +580,9 @@ public Channel getChannel() {
535
580
536
581
/** The {@link CallOptions} set on this context. */
537
582
public CallOptions getCallOptions () {
538
- return callOptions ;
583
+ if (!isDirectPath ) return callOptions ;
584
+ // Remove the CallCredentials attached to the callOptions if it's DirectPath.
585
+ return callOptions .withCallCredentials (null );
539
586
}
540
587
541
588
/** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */
0 commit comments