/// <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; }
/// <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; }
public void Dispose() { SendEvents(); if (Context != null) { try { Context.Disconnect(System.Net.Sockets.SocketError.Shutdown); } catch { } } Context = null; Request = null; Response = null; }
/// <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; }