{
foreach (string key in options.RequestHeaders)
{
- request.Headers.Add(key, options.RequestHeaders[key]);
+ request.Headers.TryAddWithoutValidation(key, options.RequestHeaders[key]);
}
}
request.Headers.TryAddWithoutValidation(HttpKnownHeaderNames.SecWebSocketKey, secKey);
if (options._requestedSubProtocols?.Count > 0)
{
- request.Headers.Add(HttpKnownHeaderNames.SecWebSocketProtocol, string.Join(", ", options.RequestedSubProtocols));
+ request.Headers.TryAddWithoutValidation(HttpKnownHeaderNames.SecWebSocketProtocol, string.Join(", ", options.RequestedSubProtocols));
}
}
Assert.Equal(AcceptedProtocol, cws.SubProtocol);
}
}
+
+ [ConditionalFact(nameof(WebSocketsSupported))]
+ public async Task ConnectAsync_NonStandardRequestHeaders_HeadersAddedWithoutValidation()
+ {
+ await LoopbackServer.CreateClientAndServerAsync(async uri =>
+ {
+ using (var clientSocket = new ClientWebSocket())
+ using (var cts = new CancellationTokenSource(TimeOutMilliseconds))
+ {
+ clientSocket.Options.SetRequestHeader("Authorization", "AWS4-HMAC-SHA256 Credential= AKIAXXXXXXXXXXXYSZA /20190301/us-east-2/neptune-db/aws4_request, SignedHeaders=host;x-amz-date, Signature=b8155de54d9faab00000000000000000000000000a07e0d7dda49902e4d9202");
+ await clientSocket.ConnectAsync(uri, cts.Token);
+ }
+ }, server => server.AcceptConnectionAsync(async connection =>
+ {
+ Assert.True(await LoopbackHelper.WebSocketHandshakeAsync(connection));
+ }), new LoopbackServer.Options { WebSocketEndpoint = true });
+ }
}
}