From ad04626737c164138d6d15d5e06eb20ff5b5f859 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Mon, 6 Oct 2008 21:59:43 +0000 Subject: cleaning up OSHttpResponse: note that read access to extra header fields is GONE (HttpServer does not support that), you can read the "normal" HTTP headers available via properties, and you can add headers. also, it is now possible to set a timeout for KeepAlive (for those clients that pay attention to it). this also fixes the broken REST inventory/assets/appearance services, they should be working again. testcase for OSHttpResponse will follow. --- .../Rest/Inventory/RequestData.cs | 72 ++++---- OpenSim/Framework/Servers/BaseHttpServer.cs | 9 +- OpenSim/Framework/Servers/OSHttpRequest.cs | 20 ++- OpenSim/Framework/Servers/OSHttpResponse.cs | 200 ++++++--------------- 4 files changed, 101 insertions(+), 200 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs index 12caf81..081327e 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RequestData.cs @@ -1213,7 +1213,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory response.ContentLength64 = buffer.Length; - if (response.Headers.Get("Content-Encoding") == null) + if (response.ContentEncoding == null) response.ContentEncoding = encoding; response.SendChunked = chunked; @@ -1256,7 +1256,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory handled = true; - DumpHeaders(); + // DumpHeaders(); // if (request.InputStream != null) // { @@ -1273,8 +1273,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory // Closing the outputstream should complete the transmission process - Rest.Log.DebugFormat("{0} Closing output stream", MsgId); - response.OutputStream.Close(); + Rest.Log.DebugFormat("{0} Sending response", MsgId); + // response.OutputStream.Close(); + response.Send(); } @@ -1292,44 +1293,35 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory internal void AddHeader(string hdr, string data) { - if (Rest.DEBUG) - { - Rest.Log.DebugFormat("{0} Adding header: <{1}: {2}>", - MsgId, hdr, data); - if (response.Headers.Get(hdr) != null) - { - Rest.Log.DebugFormat("{0} Multipe {1} headers will be generated>", - MsgId, hdr); - } - } - response.Headers.Add(hdr, data); - } - - internal void RemoveHeader(string hdr) - { - if (Rest.DEBUG) - { - Rest.Log.DebugFormat("{0} Removing header: <{1}>", MsgId, hdr); - if (response.Headers.Get(hdr) == null) - { - Rest.Log.DebugFormat("{0} No such header existed", - MsgId, hdr); - } - } - response.Headers.Remove(hdr); + if (Rest.DEBUG) Rest.Log.DebugFormat("{0} Adding header: <{1}: {2}>", MsgId, hdr, data); + response.AddHeader(hdr, data); } - internal void DumpHeaders() - { - if (Rest.DEBUG) - { - for (int i=0;i", MsgId, hdr); + // if (response.Headers.Get(hdr) == null) + // { + // Rest.Log.DebugFormat("{0} No such header existed", + // MsgId, hdr); + // } + // } + // response.Headers.Remove(hdr); + // } + + // internal void DumpHeaders() + // { + // if (Rest.DEBUG) + // { + // for (int i=0;i /// Internal whiteboard for handlers to store temporary stuff @@ -151,11 +157,9 @@ namespace OpenSim.Framework.Servers private Dictionary _whiteboard = new Dictionary(); - public OSHttpRequest() - { - } + public OSHttpRequest() {} - public OSHttpRequest(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest req) + public OSHttpRequest(IHttpClientContext context, IHttpRequest req) { _request = req; _context = context; diff --git a/OpenSim/Framework/Servers/OSHttpResponse.cs b/OpenSim/Framework/Servers/OSHttpResponse.cs index 24bf340..6b20bf3 100644 --- a/OpenSim/Framework/Servers/OSHttpResponse.cs +++ b/OpenSim/Framework/Servers/OSHttpResponse.cs @@ -38,19 +38,8 @@ namespace OpenSim.Framework.Servers /// OSHttpResponse is the OpenSim representation of an HTTP /// response. /// - /// - /// OSHttpResponse is currently dual "homed" in that it support - /// both the .NET HttpListenerResponse and the HttpServer - /// HttpResponse (similar to OSHttpRequest); this duality is only - /// temporary and the .NET usage will disappear once the switch to - /// HttpServer is completed. - /// public class OSHttpResponse { - - // property code below is a bit messy, will all resolve to - // harmony once we've completed the switch - /// /// Content type property. /// @@ -62,22 +51,12 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.ContentType; - else - return _httpListenerResponse.ContentType; + return _httpResponse.ContentType; } + set { - if (HttpServer) - { - _httpResponse.ContentType = value; - } - else - { - _httpListenerResponse.ContentType = value; - _contentTypeSet = true; - } + _httpResponse.ContentType = value; } } @@ -102,17 +81,12 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.ContentLength; - else - return _httpListenerResponse.ContentLength64; + return _httpResponse.ContentLength; } + set { - if (HttpServer) - _httpResponse.ContentLength = value; - else - _httpListenerResponse.ContentLength64 = value; + _httpResponse.ContentLength = value; } } @@ -132,59 +106,55 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.Encoding; - else - return _httpListenerResponse.ContentEncoding; + return _httpResponse.Encoding; } set { - if (HttpServer) - _httpResponse.Encoding = value; - else - _httpListenerResponse.ContentEncoding = value; + _httpResponse.Encoding = value; } } - /// - /// Headers of the response. - /// - public WebHeaderCollection Headers + public bool KeepAlive { - get + get + { + return _httpResponse.Connection == ConnectionType.KeepAlive; + } + + set { - if (HttpServer) - return null; + if (value) + _httpResponse.Connection = ConnectionType.KeepAlive; else - return _httpListenerResponse.Headers; + _httpResponse.Connection = ConnectionType.Close; } } /// - /// Get or set the keep alive property. + /// Get or set the keep alive timeout property (default is + /// 20). Setting this to 0 also disables KeepAlive. Setting + /// this to something else but 0 also enable KeepAlive. /// - public bool KeepAlive + public int KeepAliveTimeout { get { - if (HttpServer) - return _httpResponse.Connection == ConnectionType.KeepAlive; - else - return _httpListenerResponse.KeepAlive; + return _httpResponse.KeepAlive; } set { - if (HttpServer) + if (value == 0) { - if (value == true) - _httpResponse.Connection = ConnectionType.KeepAlive; - else - _httpResponse.Connection = ConnectionType.Close; + _httpResponse.Connection = ConnectionType.Close; + _httpResponse.KeepAlive = 0; } else - _httpListenerResponse.KeepAlive = value; + { + _httpResponse.Connection = ConnectionType.KeepAlive; + _httpResponse.KeepAlive = value; + } } } @@ -198,10 +168,7 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.Body; - else - return _httpListenerResponse.OutputStream; + return _httpResponse.Body; } } @@ -209,18 +176,12 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.ProtocolVersion; - else - return _httpListenerResponse.ProtocolVersion.ToString(); + return _httpResponse.ProtocolVersion; } + set { - if (HttpServer) - _httpResponse.ProtocolVersion = value; - else - _httpListenerResponse.ProtocolVersion = new Version(value); ; - + _httpResponse.ProtocolVersion = value; } } @@ -231,9 +192,7 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.Body; - throw new Exception("[OSHttpResponse] mixed .NET and HttpServer access"); + return _httpResponse.Body; } } @@ -245,10 +204,7 @@ namespace OpenSim.Framework.Servers // get { return _redirectLocation; } set { - if (HttpServer) - _httpResponse.Redirect(value); - else - _httpListenerResponse.RedirectLocation = value; + _httpResponse.Redirect(value); } } @@ -260,18 +216,12 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) return _httpResponse.Chunked; - else - return _httpListenerResponse.SendChunked; } set { - if (HttpServer) - _httpResponse.Chunked = value; - else - _httpListenerResponse.SendChunked = value; + _httpResponse.Chunked = value; } } @@ -282,18 +232,12 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return (int)_httpResponse.Status; - else - return _httpListenerResponse.StatusCode; + return (int)_httpResponse.Status; } set { - if (HttpServer) - _httpResponse.Status = (HttpStatusCode)value; - else - _httpListenerResponse.StatusCode = value; + _httpResponse.Status = (HttpStatusCode)value; } } @@ -305,64 +249,35 @@ namespace OpenSim.Framework.Servers { get { - if (HttpServer) - return _httpResponse.Reason; - else - return _httpListenerResponse.StatusDescription; + return _httpResponse.Reason; } set { - if (HttpServer) - _httpResponse.Reason = value; - else - _httpListenerResponse.StatusDescription = value; + _httpResponse.Reason = value; } } - internal bool HttpServer - { - get { return null != _httpResponse; } - } - private HttpResponse _httpResponse; - private HttpListenerResponse _httpListenerResponse; + protected IHttpResponse _httpResponse; - internal HttpResponse HttpResponse - { - get { return _httpResponse; } - } - - public OSHttpResponse() - { - } + public OSHttpResponse() {} - /// - /// Instantiate an OSHttpResponse object based on an - /// underlying .NET HttpListenerResponse. - /// - /// - /// Almost deprecated; will go west to make once HttpServer - /// base takes over. - /// - public OSHttpResponse(HttpListenerResponse resp) - { - _httpListenerResponse = resp; - } - public OSHttpResponse(HttpServer.HttpResponse resp) + public OSHttpResponse(IHttpResponse resp) { _httpResponse = resp; } + /// /// Instantiate an OSHttpResponse object from an OSHttpRequest /// object. /// Incoming OSHttpRequest to which we are /// replying - // public OSHttpResponse(OSHttpRequest req) - // { - // _httpResponse = new HttpResponse(req.HttpClientContext, req.HttpRequest); - // } + public OSHttpResponse(OSHttpRequest req) + { + _httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest); + } /// /// Add a header field and content to the response. @@ -373,10 +288,7 @@ namespace OpenSim.Framework.Servers /// value public void AddHeader(string key, string value) { - if (HttpServer) - _httpResponse.AddHeader(key, value); - else - _httpListenerResponse.Headers.Add(key, value); + _httpResponse.AddHeader(key, value); } /// @@ -384,16 +296,8 @@ namespace OpenSim.Framework.Servers /// public void Send() { - if (HttpServer) - { - _httpResponse.Body.Flush(); - _httpResponse.Send(); - - } - else - { - OutputStream.Close(); - } + _httpResponse.Body.Flush(); + _httpResponse.Send(); } } } -- cgit v1.1