aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs49
1 files changed, 46 insertions, 3 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs b/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs
index 6342983..41aa19b 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseStreamHandler.cs
@@ -26,17 +26,60 @@
26 */ 26 */
27 27
28using System.IO; 28using System.IO;
29using System.Net;
30using OpenSim.Framework.ServiceAuth;
29 31
30namespace OpenSim.Framework.Servers.HttpServer 32namespace OpenSim.Framework.Servers.HttpServer
31{ 33{
34 /// <summary>
35 /// Base streamed request handler.
36 /// </summary>
37 /// <remarks>
38 /// Inheriting classes should override ProcessRequest() rather than Handle()
39 /// </remarks>
32 public abstract class BaseStreamHandler : BaseRequestHandler, IStreamedRequestHandler 40 public abstract class BaseStreamHandler : BaseRequestHandler, IStreamedRequestHandler
33 { 41 {
34 public abstract byte[] Handle(string path, Stream request, 42 protected IServiceAuth m_Auth;
35 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse);
36 43
37 protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) {} 44 protected BaseStreamHandler(string httpMethod, string path) : this(httpMethod, path, null, null) { }
38 45
39 protected BaseStreamHandler(string httpMethod, string path, string name, string description) 46 protected BaseStreamHandler(string httpMethod, string path, string name, string description)
40 : base(httpMethod, path, name, description) {} 47 : base(httpMethod, path, name, description) {}
48
49 protected BaseStreamHandler(string httpMethod, string path, IServiceAuth auth)
50 : base(httpMethod, path, null, null)
51 {
52 m_Auth = auth;
53 }
54
55 public virtual byte[] Handle(
56 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
57 {
58 RequestsReceived++;
59
60 if (m_Auth != null)
61 {
62 HttpStatusCode statusCode;
63
64 if (!m_Auth.Authenticate(httpRequest.Headers, httpResponse.AddHeader, out statusCode))
65 {
66 httpResponse.StatusCode = (int)statusCode;
67 httpResponse.ContentType = "text/plain";
68 return new byte[0];
69 }
70 }
71
72 byte[] result = ProcessRequest(path, request, httpRequest, httpResponse);
73
74 RequestsHandled++;
75
76 return result;
77 }
78
79 protected virtual byte[] ProcessRequest(
80 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
81 {
82 return null;
83 }
41 } 84 }
42} \ No newline at end of file 85} \ No newline at end of file