mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-10 18:56:50 +02:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user