@@ -131,6 +131,9 @@ public static class ClientOptions {
131
131
/** Client for metrics reporting. */
132
132
private final Scope metricsScope ;
133
133
134
+ /** Optional TChannel transport headers */
135
+ private final Map <String , String > transportHeaders ;
136
+
134
137
private ClientOptions (Builder builder ) {
135
138
this .rpcTimeoutMillis = builder .rpcTimeoutMillis ;
136
139
if (builder .clientAppName == null ) {
@@ -149,6 +152,11 @@ private ClientOptions(Builder builder) {
149
152
builder .metricsScope = NoopScope .getInstance ();
150
153
}
151
154
this .metricsScope = builder .metricsScope ;
155
+ if (builder .transportHeaders != null ) {
156
+ this .transportHeaders = builder .transportHeaders ;
157
+ } else {
158
+ this .transportHeaders = ImmutableMap .of ();
159
+ }
152
160
}
153
161
154
162
/** @return Returns the rpc timeout value in millis. */
@@ -179,6 +187,10 @@ public Scope getMetricsScope() {
179
187
return metricsScope ;
180
188
}
181
189
190
+ public Map <String , String > getTransportHeaders () {
191
+ return transportHeaders ;
192
+ }
193
+
182
194
/**
183
195
* Builder is the builder for ClientOptions.
184
196
*
@@ -193,6 +205,7 @@ public static class Builder {
193
205
public long rpcQueryTimeoutMillis = DEFAULT_QUERY_RPC_TIMEOUT_MILLIS ;
194
206
public String serviceName ;
195
207
private Scope metricsScope ;
208
+ private Map <String , String > transportHeaders ;
196
209
197
210
/**
198
211
* Sets the rpc timeout value for non query and non long poll calls. Default is 1000.
@@ -262,6 +275,17 @@ public Builder setMetricsScope(Scope metricsScope) {
262
275
return this ;
263
276
}
264
277
278
+ /**
279
+ * Sets additional transport headers for tchannel client.
280
+ *
281
+ * @param transportHeaders Map with additional transport headers
282
+ * @return Builder for ClentOptions
283
+ */
284
+ public Builder setTransportHeaders (Map <String , String > transportHeaders ) {
285
+ this .transportHeaders = transportHeaders ;
286
+ return this ;
287
+ }
288
+
265
289
/**
266
290
* Builds and returns a ClientOptions object.
267
291
*
@@ -380,6 +404,9 @@ private <T> ThriftRequest<T> buildThriftRequest(String apiName, T body, Long rpc
380
404
} else {
381
405
builder .setTimeout (this .options .getRpcTimeoutMillis ());
382
406
}
407
+ for (Map .Entry <String , String > header : this .options .getTransportHeaders ().entrySet ()) {
408
+ builder .setTransportHeader (header .getKey (), header .getValue ());
409
+ }
383
410
builder .setBody (body );
384
411
return builder .build ();
385
412
}
0 commit comments