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.
---
OpenSim/Framework/Servers/OSHttpResponse.cs | 200 ++++++++--------------------
1 file changed, 52 insertions(+), 148 deletions(-)
(limited to 'OpenSim/Framework/Servers/OSHttpResponse.cs')
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