internal void Send(HttpConnection connection, string protocol, string version) { ServerContext = connection.Server; byte[] data = null; if (Code < 200 || Code == 204 || Code == 304) { Headers.Remove("Content-Type"); Headers["Content-Length"] = "0"; } else { data = GetData(); Headers["Content-Length"] = (data != null) ? data.Length.ToString() : "0"; } if (Code >= 500) { Headers["Connection"] = "close"; } var hdrBuffer = new StringBuilder(); hdrBuffer.AppendFormat("{0}/{1} {2} {3}\r\n", protocol, version, Code, Reason); foreach (string hdr in Headers) { foreach (var value in Headers.GetValues(hdr)) { hdrBuffer.AppendFormat("{0}: {1}\r\n", hdr, value); } } hdrBuffer.Append("\r\n"); connection.Send(Encoding.ASCII, hdrBuffer.ToString()); connection.Send(data); }
internal void Send(HttpConnection connection, string protocol, string version) { ServerContext = connection.Server; byte[] data = null; if (Code < 200 || Code == 204 || Code == 304) { Headers.Remove("Content-Type"); Headers["Content-Length"] = "0"; } else { data = GetData(); Headers["Content-Length"] = (data != null) ? data.Length.ToString() : "0"; } if (Code >= 500) Headers["Connection"] = "close"; var hdrBuffer = new StringBuilder(); hdrBuffer.AppendFormat("{0}/{1} {2} {3}\r\n", protocol, version, Code, Reason); foreach (string hdr in Headers) foreach (var value in Headers.GetValues(hdr)) hdrBuffer.AppendFormat("{0}: {1}\r\n", hdr, value); hdrBuffer.Append("\r\n"); connection.Send(Encoding.ASCII, hdrBuffer.ToString()); connection.Send(data); }