diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpResponse.cs index eab6f013f4..2c1a0bdf7e 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpResponse.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpResponse.cs @@ -154,7 +154,6 @@ namespace OSHttpServer /// /// Size of the body. MUST be specified before sending the header, - /// unless property Chunked is set to true. /// public long ContentLength { @@ -163,7 +162,7 @@ namespace OSHttpServer } /// - /// Kind of content in the body + /// Kind of content /// /// Default type is "text/html" public string ContentType @@ -215,217 +214,6 @@ namespace OSHttpServer m_headers[name] = value; } - /// - /// Send headers and body to the browser. - /// - /// If content have already been sent. - public void SendOri() - { - if (Sent) - throw new InvalidOperationException("Everything have already been sent."); - - m_context.ReqResponseAboutToSend(requestID); - if (m_context.MAXRequests == 0 || m_keepAlive == 0) - { - Connection = ConnectionType.Close; - m_context.TimeoutKeepAlive = 0; - } - else - { - if (m_keepAlive > 0) - m_context.TimeoutKeepAlive = m_keepAlive * 1000; - } - - if (!HeadersSent) - { - if (!SendHeaders()) - { - m_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(m_body != null) - m_body.Dispose(); - Sent = true; - return; - } - } - } - - RawBuffer = null; - RawBufferStart = -1; - RawBufferLen = -1; - } - - if(m_body != null && m_body.Length > 0) - { - m_body.Seek(0, SeekOrigin.Begin); - - var buffer = new byte[8192]; - int bytesRead = m_body.Read(buffer, 0, 8192); - while (bytesRead > 0) - { - if (!m_context.Send(buffer, 0, bytesRead)) - break; - bytesRead = m_body.Read(buffer, 0, 8192); - } - - m_body.Dispose(); - } - Sent = true; - m_context.ReqResponseSent(requestID, Connection); - } - - - /// - /// Make sure that you have specified and sent the headers first. - /// - /// - /// If headers have not been sent. - /// - /// offset of first byte to send - /// number of bytes to send. - /// - /// - /// This method can be used if you want to send body contents without caching them first. This - /// is recommended for larger files to keep the memory usage low. - public bool SendBody(byte[] buffer, int offset, int count) - { - if (!HeadersSent) - throw new InvalidOperationException("Send headers, and remember to specify ContentLength first."); - - bool sent = m_context.Send(buffer, offset, count); - Sent = true; - if (sent) - m_context.ReqResponseSent(requestID, Connection); - return sent; - } - - /// - /// Make sure that you have specified and sent the headers first. - /// - /// - /// If headers have not been sent. - /// - /// - /// - /// This method can be used if you want to send body contents without caching them first. This - /// is recommended for larger files to keep the memory usage low. - public bool SendBody(byte[] buffer) - { - if (!HeadersSent) - throw new InvalidOperationException("Send headers, and remember to specify ContentLength first."); - - bool sent = m_context.Send(buffer); - if (sent) - m_context.ReqResponseSent(requestID, Connection); - Sent = true; - return sent; - } - - /// - /// Send headers to the client. - /// - /// If headers already been sent. - /// - /// - /// - public bool SendHeaders() - { - if (HeadersSent) - throw new InvalidOperationException("Header have already been sent."); - - HeadersSent = true; - - if (m_headers["Date"] == null) - m_headers["Date"] = DateTime.Now.ToString("r"); - if (m_headers["Content-Length"] == null) - { - int len = (int)m_contentLength; - if(len == 0) - { - if(m_body != null) - len = (int)m_body.Length; - if(RawBuffer != null) - len += RawBufferLen; - } - m_headers["Content-Length"] = len.ToString(); - } - if (m_headers["Content-Type"] == null) - m_headers["Content-Type"] = m_contentType ?? DefaultContentType; - if (m_headers["Server"] == null) - m_headers["Server"] = "Tiny WebServer"; - - int keepaliveS = m_context.TimeoutKeepAlive / 1000; - if (Connection == ConnectionType.KeepAlive && keepaliveS > 0 && m_context.MAXRequests > 0) - { - m_headers["Keep-Alive"] = "timeout=" + keepaliveS + ", max=" + m_context.MAXRequests; - m_headers["Connection"] = "Keep-Alive"; - } - else - m_headers["Connection"] = "close"; - - var sb = new StringBuilder(); - sb.AppendFormat("{0} {1} {2}\r\n", m_httpVersion, (int)Status, - string.IsNullOrEmpty(Reason) ? Status.ToString() : Reason); - - for (int i = 0; i < m_headers.Count; ++i) - { - string headerName = m_headers.AllKeys[i]; - string[] values = m_headers.GetValues(i); - if (values == null) continue; - foreach (string value in values) - sb.AppendFormat("{0}: {1}\r\n", headerName, value); - } - - foreach (ResponseCookie cookie in Cookies) - sb.AppendFormat("Set-Cookie: {0}\r\n", cookie); - - sb.Append("\r\n"); - - m_headers.Clear(); - - return m_context.Send(Encoding.GetBytes(sb.ToString())); - } - public byte[] GetHeaders() { HeadersSent = true; diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpResponse.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpResponse.cs index 3256ccfd42..0d0093af65 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpResponse.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/IHttpResponse.cs @@ -125,41 +125,6 @@ namespace OSHttpServer /// /// If content have already been sent. void Send(); - - /// - /// Make sure that you have specified ContentLength and sent the headers first. - /// - /// - /// If headers have not been sent. - /// - /// offest of first byte to send - /// number of bytes to send. - /// - /// - /// This method can be used if you want to send body contents without caching them first. This - /// is recommended for larger files to keep the memory usage low. - bool SendBody(byte[] buffer, int offset, int count); - - /// - /// Make sure that you have specified ContentLength and sent the headers first. - /// - /// - /// If headers have not been sent. - /// - /// - /// - /// This method can be used if you want to send body contents without caching them first. This - /// is recommended for larger files to keep the memory usage low. - bool SendBody(byte[] buffer); - - /// - /// Send headers to the client. - /// - /// If headers already been sent. - /// - /// - /// - bool SendHeaders(); } ///