Add WebSockets (#1423)

* Add WebSockets

* Add tests

* fix

* more tests

* Add tests

* ...

* remove IOwin

* -

* tests

* fluent

* ok

* match

* .

* byte[]

* x

* func

* func

* byte

* trans

* ...

* frameworks.........

* jmes

* xxx

* sc
This commit is contained in:
Stef Heyenrath
2026-02-14 08:42:40 +01:00
committed by GitHub
parent dff55e175b
commit 8b27da95a8
103 changed files with 72659 additions and 398 deletions

View File

@@ -0,0 +1,48 @@
// Copyright © WireMock.Net
using System.Linq;
using WireMock.Matchers;
using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders;
public partial class Request
{
/// <inheritdoc />
public bool IsWebSocket { get; private set; }
/// <inheritdoc />
public IRequestBuilder WithWebSocketUpgrade(params string[] protocols)
{
_requestMatchers.Add(new RequestMessageHeaderMatcher(
MatchBehaviour.AcceptOnMatch,
MatchOperator.Or,
"Upgrade",
true,
new ExactMatcher(true, "websocket")
));
_requestMatchers.Add(new RequestMessageHeaderMatcher(
MatchBehaviour.AcceptOnMatch,
MatchOperator.Or,
"Connection",
true,
new WildcardMatcher("*Upgrade*", true)
));
if (protocols.Length > 0)
{
_requestMatchers.Add(new RequestMessageHeaderMatcher(
MatchBehaviour.AcceptOnMatch,
MatchOperator.Or,
"Sec-WebSocket-Protocol",
true,
protocols.Select(p => new ExactMatcher(true, p)).ToArray()
));
}
IsWebSocket = true;
return this;
}
}

View File

@@ -2,8 +2,6 @@
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;