Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 5a4f1af

Browse files
committed
WebSocket fix
1 parent fa449db commit 5a4f1af

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,3 @@ private async Task writeToConsole(string message, ConsoleColor? consoleColor = n
430430
//}
431431
}
432432
}
433-

src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public class SessionEventArgs : SessionEventArgsBase
2525
/// </summary>
2626
private bool reRequest;
2727

28-
private WebSocketDecoder? webSocketDecoder;
28+
private WebSocketDecoder? webSocketDecoderSend;
29+
30+
private WebSocketDecoder? webSocketDecoderReceive;
2931

3032
/// <summary>
3133
/// Is this session a HTTP/2 promise?
@@ -59,7 +61,12 @@ public bool ReRequest
5961
}
6062
}
6163

62-
public WebSocketDecoder WebSocketDecoder => webSocketDecoder ??= new WebSocketDecoder(BufferPool);
64+
[Obsolete("Use [WebSocketDecoderReceive] instead")]
65+
public WebSocketDecoder WebSocketDecoder => WebSocketDecoderReceive;
66+
67+
public WebSocketDecoder WebSocketDecoderSend => webSocketDecoderSend ??= new WebSocketDecoder(BufferPool);
68+
69+
public WebSocketDecoder WebSocketDecoderReceive => webSocketDecoderReceive ??= new WebSocketDecoder(BufferPool);
6370

6471
/// <summary>
6572
/// Occurs when multipart request part sent.

src/Titanium.Web.Proxy/WebSocket/WebSocketDecoder.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public IEnumerable<WebSocketFrame> Decode(byte[] data, int offset, int count)
100100
{
101101
data1[pos + 2] ^= (byte)(mask >> 16);
102102
}
103-
;
104103
}
105104
}
106105

@@ -115,6 +114,19 @@ public IEnumerable<WebSocketFrame> Decode(byte[] data, int offset, int count)
115114
{
116115
copyToBuffer(buffer);
117116
}
117+
118+
if (copied)
119+
{
120+
if (buffer.Length == 0)
121+
{
122+
bufferLength = 0;
123+
}
124+
else
125+
{
126+
buffer.CopyTo(this.buffer);
127+
bufferLength = buffer.Length;
128+
}
129+
}
118130
}
119131

120132
private Memory<byte> copyToBuffer(ReadOnlyMemory<byte> data)

0 commit comments

Comments
 (0)