diff --git a/src/Listener/PodeHttpRequest.cs b/src/Listener/PodeHttpRequest.cs index 142d24355..1329480cc 100644 --- a/src/Listener/PodeHttpRequest.cs +++ b/src/Listener/PodeHttpRequest.cs @@ -50,18 +50,13 @@ public PodeHttpRequest(Socket socket) protected override bool ValidateInput(byte[] bytes) { - Console.WriteLine($"hmm1"); if (bytes.Length == 0) { - Console.WriteLine("nop1"); return false; } - Console.WriteLine($"TMP BYTES: {bytes.Length}"); - Console.WriteLine($"FIRST: {bytes[0]}"); if (AwaitingBody) { - Console.WriteLine($"CONTENT: {ContentLength - RawBody.Length}"); return (bytes.Length >= (ContentLength - RawBody.Length)); } @@ -70,21 +65,17 @@ protected override bool ValidateInput(byte[] bytes) var index = Array.IndexOf(bytes, lf); // req line - Console.WriteLine($"hmm2 -- {index}"); if (index == -1) { - Console.WriteLine("nop2"); return false; } // headers - Console.WriteLine($"hmm3"); while (true) { previousIndex = index; index = Array.IndexOf(bytes, lf, index + 1); - // Console.WriteLine($"hmm2 -- {index} -- {bytes.Length}"); if (index - previousIndex <= 2) { if (index - previousIndex == 1) @@ -105,12 +96,10 @@ protected override bool ValidateInput(byte[] bytes) if (index == -1) { - Console.WriteLine("nop3"); return false; } } - Console.WriteLine("yup1"); return true; } @@ -145,9 +134,9 @@ protected override bool Parse(byte[] bytes) // cleanup reqLines = default(string[]); - Console.WriteLine($"ContentLength: {ContentLength}"); - Console.WriteLine($"RawBody: {RawBody.Length}"); - Console.WriteLine($"Awaiting: {AwaitingBody}"); + // Console.WriteLine($"ContentLength: {ContentLength}"); + // Console.WriteLine($"RawBody: {RawBody.Length}"); + // Console.WriteLine($"Awaiting: {AwaitingBody}"); return (!AwaitingBody); } diff --git a/src/Listener/PodeRequest.cs b/src/Listener/PodeRequest.cs index e41cb5f88..3eaf53215 100644 --- a/src/Listener/PodeRequest.cs +++ b/src/Listener/PodeRequest.cs @@ -78,7 +78,7 @@ private bool ValidateCertificateCallback(object sender, X509Certificate certific private byte[] _buffer; private MemoryStream _bufferStream; - private const int _bufferSize = 16384; //8192; + private const int _bufferSize = 16384; protected AsyncCallback AsyncReadCallback; private void ReadCallback(IAsyncResult ares) @@ -86,10 +86,6 @@ private void ReadCallback(IAsyncResult ares) var req = (PodeRequest)ares.AsyncState; var read = InputStream.EndRead(ares); - if (read < _bufferSize - 29) { - Console.WriteLine($"READ: {read} -- {_bufferStream.ToArray().Length} -- {_bufferStream.ToArray().LastOrDefault()}"); - } - if (read == 0) { _bufferStream.Dispose(); @@ -102,27 +98,18 @@ private void ReadCallback(IAsyncResult ares) _bufferStream.Write(_buffer, 0, read); } - // System.Threading.Thread.Sleep(10); - // System.Threading.Thread.Sleep(10); - // System.Threading.Thread.Sleep(10); - // System.Threading.Thread.Sleep(10); - // if (read == _bufferSize || Socket.Available > 0) if (Socket.Available > 0 || !ValidateInput(_bufferStream.ToArray())) { - // InputStream.BeginRead(_buffer, 0, _bufferSize, AsyncReadCallback, this); - Console.WriteLine($"BR1 -- {Socket.Available}"); BeginRead(); } else { var bytes = _bufferStream.ToArray(); - Console.WriteLine($"BYTES: {bytes.Length}"); if (!Parse(bytes)) { bytes = default(byte[]); _bufferStream.Dispose(); _bufferStream = new MemoryStream(); - Console.WriteLine("BR2"); BeginRead(); } else @@ -150,52 +137,9 @@ public void Receive() { Error = default(HttpRequestException); - _buffer = new byte[_bufferSize]; _bufferStream = new MemoryStream(); - Console.WriteLine("RECEIVING!"); - // AsyncReadCallback = new AsyncCallback(ReadCallback); - // InputStream.BeginRead(_buffer, 0, _bufferSize, AsyncReadCallback, this); BeginRead(); - - - - - // var allBytes = default(byte[]); - // var task = default(Task); - // var bytes = default(byte[]); - // var count = 0; - - // using (var buffer = new MemoryStream()) - // { - // while ((count = Socket.Available) > 0) - // { - // if (count > 8192) - // { - // count = 8192; - // } - - // bytes = new byte[count]; - // task = InputStream.ReadAsync(bytes, 0, count); - // task.Wait(Context.Listener.CancellationToken); - - // Console.WriteLine($"COUNT: {count}"); - // Console.WriteLine($"READ: {task.Result}"); - - // buffer.WriteAsync(bytes, 0, task.Result).Wait(Context.Listener.CancellationToken); - // } - - // allBytes = buffer.GetBuffer(); - - // if (allBytes[allBytes.Length - 1] == (byte)0) - // { - // var index = Array.IndexOf(allBytes, (byte)0); - // allBytes = allBytes.Take(index).ToArray(); - // } - // } - - // Parse(allBytes); - // allBytes = default(byte[]); } catch (HttpRequestException httpex) { diff --git a/src/Listener/PodeSocket.cs b/src/Listener/PodeSocket.cs index 13a9ac804..528ad7a0c 100644 --- a/src/Listener/PodeSocket.cs +++ b/src/Listener/PodeSocket.cs @@ -207,61 +207,7 @@ private void ProcessReceive(SocketAsyncEventArgs args) try { - // add context to be processed? - // var process = true; - - // deal with context context.Receive(); - - // if we need to exit now, dispose and exit - // if (context.CloseImmediately) - // { - // PodeHelpers.WriteException(context.Request.Error, Listener); - // context.Dispose(true); - // process = false; - // } - - // if it's a websocket, upgrade it, then add context back for re-receiving - // else if (context.IsWebSocket && !context.IsWebSocketUpgraded) - // { - // context.UpgradeWebSocket(); - // process = false; - // context.Dispose(); - // } - - // if it's an email, re-receive unless processable - // else if (context.IsSmtp) - // { - // if (!context.SmtpRequest.CanProcess) - // { - // process = false; - // context.Dispose(); - // } - // } - - // if it's http and awaiting the body - // else if (context.IsHttp) - // { - // if (context.HttpRequest.AwaitingBody) - // { - // process = false; - // context.Dispose(); - // } - // } - - // add the context for processing - // if (process) - // { - // if (context.IsWebSocket) - // { - // Listener.AddClientSignal(context.WsRequest.NewClientSignal()); - // context.Dispose(); - // } - // else - // { - // Listener.AddContext(context); - // } - // } } catch (Exception ex) {