public override void Clear() { _request = null; EndUploads (); if (_uploadManager != null) { _uploadManager.Clean (); _uploadManager = null; } if (_httpServer.Mode == ServerMode.FastCGI) FcgiInterpreter.Clear (); }
protected virtual void ContinueRequestBuilding(byte[] buffer, int offset, int length) { _rbm.RefreshWorkingBuffer (buffer, offset, length); if (_rbm.Count == 0) return; if (_request == null) { _request = InitRequest (); _request.CreateHeaders (_rbm); } if (_rbm.Count > 0 && _request.IsMulitpart) { int eolIndex = _rbm.IndexOfEol (); while (eolIndex != -1 || _rbm.Count > 0) { if (_endOfPart) { if (_currFileName == null) { eolIndex = _rbm.IndexOfEol (); _request.AddMethodParam (_currParamName, _rbm.PopString (eolIndex, 2), false); eolIndex = _rbm.IndexOfEol (); _endOfPart = false; } else { if (_uploadStarted) { if(_currFileName != "") StartUploads(); _uploadStarted = false; } int boundaryIndex = -1; int amountToWrite = 0; eolIndex = _rbm.LastIndexOfEol (); if (eolIndex == -1) amountToWrite = _rbm.Count; else { boundaryIndex = _rbm.IndexOfArray (_request.MulitpartBoundaryBytes, eolIndex); if (boundaryIndex == -1) amountToWrite = (eolIndex - _rbm.StartIndex) + 2; else amountToWrite = boundaryIndex - 2 - _rbm.StartIndex; } if (amountToWrite > 0 && _currFileName != "") { _uploadManager.WriteChunck (_currFileName, _rbm.WorkingBuffer, _rbm.StartIndex, amountToWrite); } _rbm.MarkAsTreated (amountToWrite); if (boundaryIndex != -1) { _rbm.MarkAsTreated (2); eolIndex = _rbm.IndexOfEol (); _endOfPart = false; if (_currFileName != "") _uploadManager.FileUploadEnded (_currFileName); } else return; } } if (eolIndex != -1) { BuildMultipartData (_rbm.PopString (eolIndex, 2)); eolIndex = _rbm.IndexOfEol (); } } } }
protected void SendResponse() { EndUploads (); _Logger.DebugFormat ("Data received: {0} bytes", SocketAsyncManager.TotalReceived); bool closeConnectionAfterSend = true; if (_request != null) { Handler = InitHandler (); if (Handler != null) { _Logger.InfoFormat ("{0} /{1} {2}", _request.Method, _request.Resource, _request.Protocol); HttpResponse response = Handler.Handle (_request); if (response != null) { byte[] responseData = response.Data; if (_httpServer.Mode == ServerMode.FastCGI) responseData = _fcgiInterpreter.TranslateToFCGIResponse (responseData); SocketAsyncManager.SendAsync (responseData, 0, responseData.Length); SocketAsyncManager.Clear (); _request = null; closeConnectionAfterSend = !response.ConnectionKeepAlive; } else { byte[] h404 = Encoding.Default.GetBytes (string.Format ("HTTP/1.1 {0}\r\n\r\n", HttpResponseStatus._404.ToResponseHeaderText ())); if (_httpServer.Mode == ServerMode.FastCGI) h404 = _fcgiInterpreter.TranslateToFCGIResponse (h404); SocketAsyncManager.SendAsync (h404, 0, h404.Length, true); } } } SocketAsyncManager.ShouldCloseConnection = closeConnectionAfterSend; }
public HttpResponse Handle(HttpRequest request) { return Handle (request as BadrRequest); }