@@ -131,6 +131,9 @@ public static class ClientOptions {
131131 /** Client for metrics reporting. */
132132 private final Scope metricsScope ;
133133
134+ /** Optional TChannel transport headers */
135+ private final Map <String , String > transportHeaders ;
136+
134137 private ClientOptions (Builder builder ) {
135138 this .rpcTimeoutMillis = builder .rpcTimeoutMillis ;
136139 if (builder .clientAppName == null ) {
@@ -149,6 +152,11 @@ private ClientOptions(Builder builder) {
149152 builder .metricsScope = NoopScope .getInstance ();
150153 }
151154 this .metricsScope = builder .metricsScope ;
155+ if (builder .transportHeaders != null ) {
156+ this .transportHeaders = builder .transportHeaders ;
157+ } else {
158+ this .transportHeaders = ImmutableMap .of ();
159+ }
152160 }
153161
154162 /** @return Returns the rpc timeout value in millis. */
@@ -179,6 +187,10 @@ public Scope getMetricsScope() {
179187 return metricsScope ;
180188 }
181189
190+ public Map <String , String > getTransportHeaders () {
191+ return transportHeaders ;
192+ }
193+
182194 /**
183195 * Builder is the builder for ClientOptions.
184196 *
@@ -193,6 +205,7 @@ public static class Builder {
193205 public long rpcQueryTimeoutMillis = DEFAULT_QUERY_RPC_TIMEOUT_MILLIS ;
194206 public String serviceName ;
195207 private Scope metricsScope ;
208+ private Map <String , String > transportHeaders ;
196209
197210 /**
198211 * 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) {
262275 return this ;
263276 }
264277
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+
265289 /**
266290 * Builds and returns a ClientOptions object.
267291 *
@@ -380,6 +404,9 @@ private <T> ThriftRequest<T> buildThriftRequest(String apiName, T body, Long rpc
380404 } else {
381405 builder .setTimeout (this .options .getRpcTimeoutMillis ());
382406 }
407+ for (Map .Entry <String , String > header : this .options .getTransportHeaders ().entrySet ()) {
408+ builder .setTransportHeader (header .getKey (), header .getValue ());
409+ }
383410 builder .setBody (body );
384411 return builder .build ();
385412 }
0 commit comments