void ProcessResponse(HttpConnection conn, IHttpRequest req, HttpResponseHeader header, object result, ref bool keepAlive, ref bool header_sent) { byte[] rawBody = null; if (result is Stream) { try { header[HttpHeaderNames.ContentLength] = (result as Stream).Length.ToString(); } catch { } } else { rawBody = ResponseBodyToBytes(result); header[HttpHeaderNames.ContentLength] = rawBody.Length.ToString(); } if (keepAlive && header.GetNotNullValue(HttpHeaderNames.ContentLength).Length == 0 && !header.GetNotNullValue(HttpHeaderNames.TransferEncoding).ToLower().Equals("chunked")) { keepAlive = false; header[HttpHeaderNames.Connection] = "close"; } else if (header[HttpHeaderNames.Connection] == "close") { keepAlive = false; } byte[] raw = header.CreateResponseHeaderBytes(); header_sent = true; conn.Send(raw); if (req.HttpMethod == HttpMethod.HEAD) { return; } if (rawBody != null) { conn.Send(rawBody); } else { // TODO: impelements to send stream data throw new NotImplementedException(); } }