@@ -24,13 +24,15 @@ internal class DefaultClientIO : IClientIO
24
24
private readonly HttpClient client ;
25
25
private readonly AuthenticationHeaderValue authHeader ;
26
26
27
+ private readonly IReadOnlyDictionary < string , string > customHeaders ;
28
+
27
29
private LastSeen lastSeen ;
28
30
private Version httpVersion ;
29
31
30
32
public const string StreamingPath = "stream" ;
31
33
public const HttpMethodKind StreamingHttpMethod = HttpMethodKind . Post ;
32
34
33
- internal DefaultClientIO ( HttpClient client , AuthenticationHeaderValue authHeader , LastSeen lastSeen , Uri endpoint , TimeSpan ? timeout , Version httpVersion )
35
+ internal DefaultClientIO ( HttpClient client , AuthenticationHeaderValue authHeader , LastSeen lastSeen , Uri endpoint , TimeSpan ? timeout , Version httpVersion , IReadOnlyDictionary < string , string > customHeaders )
34
36
{
35
37
client . AssertNotNull ( nameof ( client ) ) ;
36
38
authHeader . AssertNotNull ( nameof ( authHeader ) ) ;
@@ -42,19 +44,20 @@ internal DefaultClientIO(HttpClient client, AuthenticationHeaderValue authHeader
42
44
this . lastSeen = lastSeen ;
43
45
this . endpoint = endpoint ;
44
46
this . clientTimeout = timeout ;
47
+ this . customHeaders = customHeaders ;
45
48
#if NETSTANDARD2_1
46
49
this . httpVersion = httpVersion == null ? new Version ( 2 , 0 ) : httpVersion ;
47
50
#else
48
51
this . httpVersion = httpVersion == null ? new Version ( 1 , 1 ) : httpVersion ;
49
52
#endif
50
53
}
51
54
52
- public DefaultClientIO ( string secret , Uri endpoint , TimeSpan ? timeout = null , HttpClient httpClient = null , Version httpVersion = null )
53
- : this ( httpClient ?? CreateClient ( ) , AuthHeader ( secret ) , new LastSeen ( ) , endpoint , timeout , httpVersion )
55
+ public DefaultClientIO ( string secret , Uri endpoint , TimeSpan ? timeout = null , HttpClient httpClient = null , Version httpVersion = null , IReadOnlyDictionary < string , string > customHeaders = null )
56
+ : this ( httpClient ?? CreateClient ( ) , AuthHeader ( secret ) , new LastSeen ( ) , endpoint , timeout , httpVersion , customHeaders )
54
57
{ }
55
58
56
59
public IClientIO NewSessionClient ( string secret ) =>
57
- new DefaultClientIO ( client , AuthHeader ( secret ) , lastSeen , endpoint , clientTimeout , httpVersion ) ;
60
+ new DefaultClientIO ( client , AuthHeader ( secret ) , lastSeen , endpoint , clientTimeout , httpVersion , customHeaders ) ;
58
61
59
62
public Task < RequestResult > DoRequest ( HttpMethodKind method , string path , string data , IReadOnlyDictionary < string , string > query = null , TimeSpan ? queryTimeout = null ) =>
60
63
DoRequestAsync ( method , path , data , query , queryTimeout ) ;
@@ -82,6 +85,15 @@ private async Task<RequestResult> DoRequestAsync(HttpMethodKind method, string p
82
85
message . Headers . Add ( "X-Driver-Env" , RuntimeEnvironmentHeader . Construct ( EnvironmentEditor . Create ( ) ) ) ;
83
86
message . Version = httpVersion ;
84
87
88
+ // adding custom headers provided during the client creation
89
+ if ( customHeaders != null )
90
+ {
91
+ foreach ( KeyValuePair < string , string > header in customHeaders )
92
+ {
93
+ message . Headers . Add ( header . Key , header . Value ) ;
94
+ }
95
+ }
96
+
85
97
var last = lastSeen . Txn ;
86
98
if ( last . HasValue )
87
99
{
@@ -141,6 +153,15 @@ private async Task<StreamingRequestResult> DoStreamingRequestAsync(string data,
141
153
message . Version = httpVersion ;
142
154
message . SetTimeout ( Timeout . InfiniteTimeSpan ) ;
143
155
156
+ // adding custom headers provided during the client creation
157
+ if ( customHeaders != null )
158
+ {
159
+ foreach ( KeyValuePair < string , string > header in customHeaders )
160
+ {
161
+ message . Headers . Add ( header . Key , header . Value ) ;
162
+ }
163
+ }
164
+
144
165
var last = lastSeen . Txn ;
145
166
if ( last . HasValue )
146
167
{
0 commit comments