protected internal override void OnDataReceived(byte[] buffer, int offset, int length) { //#if DUMP_REQUEST_BYTES // // string reqDumpFile = string.Format("curr_request.{0}.dump", DateTime.Now.Ticks); // using (var stream = new System.IO.FileStream(reqDumpFile, System.IO.FileMode.Append)) // { // stream.Write (buffer, offset, length); // } //#endif try { if (length > 0) { if (_request == null) { if (_rbm == null) _rbm = new ReceiveBufferManager (NetServer.BUFFER_SIZE); else _rbm.Reset (); } if (_httpServer.Mode == ServerMode.FastCGI) { length = FcgiInterpreter.TranslateToHttpData (buffer, offset, length); if (FcgiInterpreter.AbortRequest) { SocketAsyncManager.CloseConnection (); return; } } ContinueRequestBuilding (buffer, offset, length); } if (_request != null && (_request.TotalLength == SocketAsyncManager.TotalReceived || (_httpServer.Mode == ServerMode.FastCGI && FcgiInterpreter.EndOfRequest))) { _request.RefreshFiles (_uploadManager); SendResponse (); } } catch (Exception ex) { byte[] hError; HttpStatusException hsEx = ex as HttpStatusException; if(hsEx != null) hError = Encoding.Default.GetBytes (string.Format ("HTTP/1.1 {0}\r\n\r\n", hsEx.ResponseCode)); else hError = Encoding.Default.GetBytes (string.Format ("HTTP/1.1 500\r\n\r\n")); if (_httpServer.Mode == ServerMode.FastCGI) hError = _fcgiInterpreter.TranslateToFCGIResponse (hError); SocketAsyncManager.SendAsync (hError, 0, hError.Length, true); } }
protected internal virtual void CreateHeaders(ReceiveBufferManager rbm) { if (rbm.Count > 0) { bool isFirstLine = true; int eolIndex = rbm.IndexOfEol(); while (eolIndex != -1 && _headersStatus != 2) { ParseLine(rbm.PopString(eolIndex, 2), isFirstLine); eolIndex = rbm.IndexOfEol(); isFirstLine = false; } HeaderLength = rbm.StartIndex; ValidateHeaders(); if (!IsMulitpart) ParseUrlEncodedParams(rbm.PopString()); } }