-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1375 #1237 #925 #920 Fix DownstreamRoute DangerousAcceptAnyServerCertificateValidator #1377
Changes from all commits
337d014
14a315e
f6da14f
8693163
8fa2809
8305910
e48e04a
da62bc4
6197ae4
72ee0d3
ace178c
80d0f8c
6370c89
6961593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Net.Security; | ||
using System.Net.WebSockets; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Ocelot.WebSockets; | ||
|
||
public class ClientWebSocketOptionsProxy : IClientWebSocketOptions | ||
{ | ||
private readonly ClientWebSocketOptions _real; | ||
|
||
public ClientWebSocketOptionsProxy(ClientWebSocketOptions options) | ||
{ | ||
_real = options; | ||
} | ||
|
||
public Version HttpVersion { get => _real.HttpVersion; set => _real.HttpVersion = value; } | ||
public HttpVersionPolicy HttpVersionPolicy { get => _real.HttpVersionPolicy; set => _real.HttpVersionPolicy = value; } | ||
public bool UseDefaultCredentials { get => _real.UseDefaultCredentials; set => _real.UseDefaultCredentials = value; } | ||
public ICredentials Credentials { get => _real.Credentials; set => _real.Credentials = value; } | ||
public IWebProxy Proxy { get => _real.Proxy; set => _real.Proxy = value; } | ||
public X509CertificateCollection ClientCertificates { get => _real.ClientCertificates; set => _real.ClientCertificates = value; } | ||
public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get => _real.RemoteCertificateValidationCallback; set => _real.RemoteCertificateValidationCallback = value; } | ||
public CookieContainer Cookies { get => _real.Cookies; set => _real.Cookies = value; } | ||
public TimeSpan KeepAliveInterval { get => _real.KeepAliveInterval; set => _real.KeepAliveInterval = value; } | ||
public WebSocketDeflateOptions DangerousDeflateOptions { get => _real.DangerousDeflateOptions; set => _real.DangerousDeflateOptions = value; } | ||
public bool CollectHttpResponseDetails { get => _real.CollectHttpResponseDetails; set => _real.CollectHttpResponseDetails = value; } | ||
|
||
public void AddSubProtocol(string subProtocol) => _real.AddSubProtocol(subProtocol); | ||
|
||
public void SetBuffer(int receiveBufferSize, int sendBufferSize) => _real.SetBuffer(receiveBufferSize, sendBufferSize); | ||
|
||
public void SetBuffer(int receiveBufferSize, int sendBufferSize, ArraySegment<byte> buffer) => _real.SetBuffer(receiveBufferSize, sendBufferSize, buffer); | ||
|
||
public void SetRequestHeader(string headerName, string headerValue) => _real.SetRequestHeader(headerName, headerValue); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Net.WebSockets; | ||
|
||
namespace Ocelot.WebSockets; | ||
|
||
public class ClientWebSocketProxy : WebSocket, IClientWebSocket | ||
{ | ||
// RealSubject (Service) class of Proxy design pattern | ||
private readonly ClientWebSocket _realService; | ||
private readonly IClientWebSocketOptions _options; | ||
|
||
public ClientWebSocketProxy() | ||
{ | ||
_realService = new ClientWebSocket(); | ||
_options = new ClientWebSocketOptionsProxy(_realService.Options); | ||
} | ||
|
||
// ClientWebSocket implementations | ||
public IClientWebSocketOptions Options => _options; | ||
|
||
public Task ConnectAsync(Uri uri, CancellationToken cancellationToken) | ||
=> _realService.ConnectAsync(uri, cancellationToken); | ||
|
||
// WebSocket implementations | ||
public override WebSocketCloseStatus? CloseStatus => _realService.CloseStatus; | ||
|
||
public override string CloseStatusDescription => _realService.CloseStatusDescription; | ||
|
||
public override WebSocketState State => _realService.State; | ||
|
||
public override string SubProtocol => _realService.SubProtocol; | ||
|
||
public override void Abort() => _realService.Abort(); | ||
|
||
public override Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) | ||
=> _realService.CloseAsync(closeStatus, statusDescription, cancellationToken); | ||
|
||
public override Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) | ||
=> _realService.CloseOutputAsync(closeStatus, statusDescription, cancellationToken); | ||
|
||
public override void Dispose() => _realService.Dispose(); | ||
|
||
public override Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer, CancellationToken cancellationToken) | ||
=> _realService.ReceiveAsync(buffer, cancellationToken); | ||
|
||
public override Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) | ||
=> _realService.SendAsync(buffer, messageType, endOfMessage, cancellationToken); | ||
|
||
public WebSocket ToWebSocket() => _realService; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Net.WebSockets; | ||
|
||
namespace Ocelot.WebSockets; | ||
|
||
public interface IClientWebSocket | ||
{ | ||
WebSocket ToWebSocket(); | ||
|
||
// ClientWebSocket definitions | ||
IClientWebSocketOptions Options { get; } | ||
Task ConnectAsync(Uri uri, CancellationToken cancellationToken); | ||
|
||
// WebSocket definitions | ||
WebSocketCloseStatus? CloseStatus { get; } | ||
string CloseStatusDescription { get; } | ||
WebSocketState State { get; } | ||
string SubProtocol { get; } | ||
void Abort(); | ||
Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken); | ||
Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken); | ||
void Dispose(); | ||
Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer, CancellationToken cancellationToken); | ||
Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Net.Security; | ||
using System.Net.WebSockets; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Ocelot.WebSockets; | ||
|
||
public interface IClientWebSocketOptions | ||
{ | ||
Version HttpVersion { get; set; } | ||
HttpVersionPolicy HttpVersionPolicy { get; set; } | ||
void SetRequestHeader(string headerName, string headerValue); | ||
bool UseDefaultCredentials { get; set; } | ||
ICredentials Credentials { get; set; } | ||
IWebProxy Proxy { get; set; } | ||
X509CertificateCollection ClientCertificates { get; set; } | ||
RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; } | ||
CookieContainer Cookies { get; set; } | ||
void AddSubProtocol(string subProtocol); | ||
TimeSpan KeepAliveInterval { get; set; } | ||
WebSocketDeflateOptions DangerousDeflateOptions { get; set; } | ||
void SetBuffer(int receiveBufferSize, int sendBufferSize); | ||
void SetBuffer(int receiveBufferSize, int sendBufferSize, ArraySegment<byte> buffer); | ||
bool CollectHttpResponseDetails { get; set; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Ocelot.WebSockets; | ||
|
||
public interface IWebSocketsFactory | ||
{ | ||
IClientWebSocket CreateClient(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Ocelot.WebSockets; | ||
|
||
public class WebSocketsFactory : IWebSocketsFactory | ||
{ | ||
public IClientWebSocket CreateClient() => new ClientWebSocketProxy(); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.