From 642dd28b61c484b66a1125ebc4c58471b4eeb6fa Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 26 Feb 2021 20:00:03 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Net/ChunkStream.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/websocket-sharp/Net/ChunkStream.cs b/websocket-sharp/Net/ChunkStream.cs index 204608cc..ff875633 100644 --- a/websocket-sharp/Net/ChunkStream.cs +++ b/websocket-sharp/Net/ChunkStream.cs @@ -162,11 +162,15 @@ namespace WebSocketSharp.Net return InputChunkState.None; } - private InputChunkState setChunkSize (byte[] buffer, ref int offset, int length) + private InputChunkState setChunkSize ( + byte[] buffer, ref int offset, int length + ) { byte b = 0; + while (offset < length) { b = buffer[offset++]; + if (_sawCr) { if (b != 10) throwProtocolViolation ("LF is expected."); @@ -176,6 +180,7 @@ namespace WebSocketSharp.Net if (b == 13) { _sawCr = true; + continue; } @@ -196,9 +201,12 @@ namespace WebSocketSharp.Net return InputChunkState.None; _chunkRead = 0; + try { _chunkSize = Int32.Parse ( - removeChunkExtension (_saved.ToString ()), NumberStyles.HexNumber); + removeChunkExtension (_saved.ToString ()), + NumberStyles.HexNumber + ); } catch { throwProtocolViolation ("The chunk size cannot be parsed."); @@ -206,6 +214,7 @@ namespace WebSocketSharp.Net if (_chunkSize == 0) { _trailerState = 2; + return InputChunkState.Trailer; }