public void Send()
{
if (!_headersSent)
SendHeaders();
if (_sent)
throw new InvalidOperationException("Everyting have already been sent.");
if (Body.Length == 0)
{
if (Connection == ConnectionType.Close)
_context.Disconnect(SocketError.Success);
return;
}
Body.Flush();
Body.Seek(0, SeekOrigin.Begin);
byte[] 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;
}