Skip to content

Commit 1415899

Browse files
committed
implement extraHeaders
1 parent eb2b3be commit 1415899

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/SocketIOClient/SocketIOOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public double RandomizationFactor
4949
}
5050
}
5151

52+
public Dictionary<string, string> ExtraHeaders { get; set; }
53+
5254
public bool AutoUpgrade { get; set; }
5355
}
5456
}

src/SocketIOClient/Transport/TransportRouter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public async Task ConnectAsync()
5757
Uri uri = UriConverter.GetHandshakeUri(ServerUri, _options.Path, _options.Query);
5858

5959
var req = new HttpRequestMessage(HttpMethod.Get, uri);
60+
SetHeaders(req);
6061

6162
var resMsg = await _httpClient.SendAsync(req, new CancellationTokenSource(_options.ConnectionTimeout).Token).ConfigureAwait(false);
6263
if (!resMsg.IsSuccessStatusCode)
@@ -90,6 +91,17 @@ public async Task ConnectAsync()
9091
}
9192
}
9293

94+
private void SetHeaders(HttpRequestMessage req)
95+
{
96+
if (_options.ExtraHeaders != null)
97+
{
98+
foreach (var item in _options.ExtraHeaders)
99+
{
100+
req.Headers.Add(item.Key, item.Value);
101+
}
102+
}
103+
}
104+
93105
private async Task WebSocketConnectAsync()
94106
{
95107
Uri uri = UriConverter.GetWebSocketUri(ServerUri, _options.Path, _options.Query, Sid);

0 commit comments

Comments
 (0)