mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-17 22:50:05 +02:00
.
This commit is contained in:
@@ -28,6 +28,8 @@ using Next = Microsoft.Owin.OwinMiddleware;
|
|||||||
using OwinMiddleware = System.Object;
|
using OwinMiddleware = System.Object;
|
||||||
using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
||||||
using Next = Microsoft.AspNetCore.Http.RequestDelegate;
|
using Next = Microsoft.AspNetCore.Http.RequestDelegate;
|
||||||
|
using HandlebarsDotNet;
|
||||||
|
using WireMock.Org.Abstractions;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace WireMock.Owin
|
namespace WireMock.Owin
|
||||||
@@ -169,6 +171,20 @@ namespace WireMock.Owin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_ASPNETCORE && NET8_0_OR_GREATER
|
||||||
|
if (ctx.WebSockets.IsWebSocketRequest)
|
||||||
|
{
|
||||||
|
// Accept WebSocket upgrade
|
||||||
|
var webSocket = await ctx.WebSockets.AcceptWebSocketAsync();
|
||||||
|
|
||||||
|
// Get and invoke handler
|
||||||
|
var provider = targetMapping.Provider as WireMock.WebSockets.ResponseProviders.WebSocketResponseProvider;
|
||||||
|
await provider.HandleWebSocketAsync(webSocket, request);
|
||||||
|
|
||||||
|
return; // Don't process as HTTP
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
logRequest = targetMapping.LogMapping;
|
logRequest = targetMapping.LogMapping;
|
||||||
|
|
||||||
if (targetMapping.IsAdminInterface && _options.AuthenticationMatcher != null && request.Headers != null)
|
if (targetMapping.IsAdminInterface && _options.AuthenticationMatcher != null && request.Headers != null)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace WireMock.WebSockets.ResponseProviders;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Response provider for handling WebSocket connections.
|
/// Response provider for handling WebSocket connections.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class WebSocketResponseProvider : IResponseProvider
|
public class WebSocketResponseProvider : IResponseProvider
|
||||||
{
|
{
|
||||||
private readonly Func<WebSocketHandlerContext, Task>? _handler;
|
private readonly Func<WebSocketHandlerContext, Task>? _handler;
|
||||||
private readonly Func<WebSocketMessage, Task<WebSocketMessage?>>? _messageHandler;
|
private readonly Func<WebSocketMessage, Task<WebSocketMessage?>>? _messageHandler;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class WebSocketTests
|
|||||||
// Act
|
// Act
|
||||||
using var client = new ClientWebSocket();
|
using var client = new ClientWebSocket();
|
||||||
await client.ConnectAsync(
|
await client.ConnectAsync(
|
||||||
new Uri($"ws://localhost:{server.Port}/echo"),
|
new Uri($"ws://{server.Url}/echo"),
|
||||||
CancellationToken.None);
|
CancellationToken.None);
|
||||||
|
|
||||||
var message = Encoding.UTF8.GetBytes("Hello WebSocket!");
|
var message = Encoding.UTF8.GetBytes("Hello WebSocket!");
|
||||||
|
|||||||
Reference in New Issue
Block a user