Skip to content

Commit

Permalink
Update README to add WS data intercept.
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchax committed Sep 26, 2024
1 parent bb9d6d4 commit ef2bf59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public class MyController : Controller
private WsProxyOptions _wsOptions = WsProxyOptionsBuilder.Instance
.WithBufferSize(8192)
.WithIntercept(context => new ValueTask<bool>(context.WebSockets.WebSocketRequestedProtocols.Contains("interceptedProtocol")))
.WithDataIntercept((data, direction, type) =>
{
if(direction == WsProxyDataDirection.Downstream && System.Text.Encoding.Default.GetString(data.Array).StartsWith("BAD"))
data.Array[0] = (byte)'M';

return Task.CompletedTask;
})
.WithBeforeConnect((context, wso) =>
{
wso.AddSubProtocol("myRandomProto");
Expand Down
3 changes: 2 additions & 1 deletion src/Test/Ws/WsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ internal static Task RunWsServers(CancellationToken token)
.UseWs("ws://localhost:5002/", options => options
.WithBufferSize(8192)
.WithIntercept(context => new ValueTask<bool>(context.WebSockets.WebSocketRequestedProtocols.Contains("interceptedProtocol")))
.WithDataIntercept((data, direction, type) => {
.WithDataIntercept((data, direction, type) =>
{
if(direction == WsProxyDataDirection.Downstream && System.Text.Encoding.Default.GetString(data.Array).StartsWith("[should_be_intercepted]"))
data.Array[0] = (byte)']';

Expand Down

0 comments on commit ef2bf59

Please sign in to comment.