-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…tificateValidator (#1377) * Fix/1375 fix DownstreamRoute DangerousAcceptAnyServerCertificateValidator does not work * Fix the exception when RoundRobin services is empty * Fix build errors * IDE0063 'using' statement can be simplified * IDE0051 Private member 'StreamCopyBufferSize' is unused * Use nameof() in string interpolations * @RaynaldM code review * Code review. Refactor method * Organize folders for WebSockets feature * Add unit tests class for WebSockets feature * Refactor middleware to make it suitable for unit testing * Add unit test * Review current acceptance tests for WebSockets * Review --------- Co-authored-by: raman-m <[email protected]>
- Loading branch information
Showing
17 changed files
with
495 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Ocelot.WebSockets; | ||
|
||
public interface IWebSocketsFactory | ||
{ | ||
IClientWebSocket CreateClient(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...re/WebSocketsProxyMiddlewareExtensions.cs → ...ts/WebSocketsProxyMiddlewareExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.