/// <summary> /// Send headers and body to the browser. /// </summary> /// <exception cref="InvalidOperationException">If content have already been sent.</exception> public void Send() { if (!HeadersSent) { SendHeaders(); } if (Sent) { throw new InvalidOperationException("Everything have already been sent."); } if (Body.Length == 0) { if (Connection == ConnectionType.Close) { _context.Disconnect(SocketError.Success); } return; } Body.Flush(); Body.Seek(0, SeekOrigin.Begin); var buffer = new byte[4196]; int bytesRead = Body.Read(buffer, 0, 4196); while (bytesRead > 0) { _context.Send(buffer, 0, bytesRead); bytesRead = Body.Read(buffer, 0, 4196); } if (Connection == ConnectionType.Close && !_context.EndWhenDone) { _context.Disconnect(SocketError.Success); } Sent = true; }
/// <summary> /// Send headers and body to the browser. /// </summary> public void Send() { if (!HeadersSent) { SendHeaders(); } if (Sent) { return; } if (Body.Length == 0) { if (Connection == ConnectionType.Close) { _context.Disconnect(SocketError.Success); } return; } Body.Flush(); Body.Seek(0, SeekOrigin.Begin); var buffer = new byte[4196]; int bytesRead = Body.Read(buffer, 0, 4196); while (bytesRead > 0) { _context.Send(buffer, 0, bytesRead); bytesRead = Body.Read(buffer, 0, 4196); } if (Connection == ConnectionType.Close) { _context.Disconnect(SocketError.Success); } Sent = true; }
/// <summary> /// Send headers and body to the browser. /// </summary> /// <exception cref="InvalidOperationException">If content have already been sent.</exception> public void SendOri() { if (Sent) { throw new InvalidOperationException("Everything have already been sent."); } m_context.ReqResponseAboutToSend(requestID); if (m_context.MAXRequests == 0 || _keepAlive == 0) { Connection = ConnectionType.Close; m_context.TimeoutKeepAlive = 0; } else { if (_keepAlive > 0) { m_context.TimeoutKeepAlive = _keepAlive * 1000; } } if (!HeadersSent) { if (!SendHeaders()) { _body.Dispose(); Sent = true; return; } } if (RawBuffer != null) { if (RawBufferStart >= 0 && RawBufferLen > 0) { if (RawBufferStart > RawBuffer.Length) { RawBufferStart = 0; } if (RawBufferLen + RawBufferStart > RawBuffer.Length) { RawBufferLen = RawBuffer.Length - RawBufferStart; } /* * int curlen; * while(RawBufferLen > 0) * { * curlen = RawBufferLen; * if(curlen > 8192) * curlen = 8192; * if (!_context.Send(RawBuffer, RawBufferStart, curlen)) * { * RawBuffer = null; * RawBufferStart = -1; * RawBufferLen = -1; * Body.Dispose(); * return; * } * RawBufferLen -= curlen; * RawBufferStart += curlen; * } */ if (RawBufferLen > 0) { if (!m_context.Send(RawBuffer, RawBufferStart, RawBufferLen)) { RawBuffer = null; RawBufferStart = -1; RawBufferLen = -1; if (_body != null) { _body.Dispose(); } Sent = true; return; } } } RawBuffer = null; RawBufferStart = -1; RawBufferLen = -1; } if (_body != null && _body.Length > 0) { _body.Flush(); _body.Seek(0, SeekOrigin.Begin); var buffer = new byte[8192]; int bytesRead = _body.Read(buffer, 0, 8192); while (bytesRead > 0) { if (!m_context.Send(buffer, 0, bytesRead)) { break; } bytesRead = _body.Read(buffer, 0, 8192); } _body.Dispose(); } Sent = true; m_context.ReqResponseSent(requestID, Connection); }
/// <summary> /// Send headers and body to the browser. /// </summary> /// <exception cref="InvalidOperationException">If content have already been sent.</exception> public void Send() { if (!HeadersSent) { SendHeaders(); } if (Sent) { throw new InvalidOperationException("Everything have already been sent."); } if (Body.Length == 0) { if (Connection == ConnectionType.Close) { _context.Disconnect(SocketError.Success); } return; } Body.Flush(); Body.Seek(0, SeekOrigin.Begin); var buffer = new byte[4196]; int bytesRead = Body.Read(buffer, 0, buffer.Length); while (bytesRead > 0) { if (Chunked == true) { _context.Send(Encoding.ASCII.GetBytes(Convert.ToString(bytesRead, 16))); _context.Send(_chunkSuffix); _context.Send(buffer, 0, bytesRead); _context.Send(_chunkSuffix); } else { _context.Send(buffer, 0, bytesRead); } bytesRead = Body.Read(buffer, 0, buffer.Length); } if (Chunked == true) { _context.Send(_chunkEnd); } if (Connection == ConnectionType.Close) { _context.Disconnect(SocketError.Success); } Sent = true; }