diff options
Merge branch 'master' into careminster
Conflicts:
bin/HttpServer_OpenSim.dll
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index e3f2e7a..27af009 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -54,6 +54,16 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
55 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); | 55 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); |
56 | 56 | ||
57 | |||
58 | /// <summary> | ||
59 | /// This is a pending websocket request before it got an sucessful upgrade response. | ||
60 | /// The consumer must call handler.HandshakeAndUpgrade() to signal to the handler to | ||
61 | /// start the connection and optionally provide an origin authentication method. | ||
62 | /// </summary> | ||
63 | /// <param name="servicepath"></param> | ||
64 | /// <param name="handler"></param> | ||
65 | public delegate void WebSocketRequestDelegate(string servicepath, WebSocketHttpServerHandler handler); | ||
66 | |||
57 | /// <summary> | 67 | /// <summary> |
58 | /// Gets or sets the debug level. | 68 | /// Gets or sets the debug level. |
59 | /// </summary> | 69 | /// </summary> |
@@ -87,6 +97,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
87 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = | 97 | protected Dictionary<string, PollServiceEventArgs> m_pollHandlers = |
88 | new Dictionary<string, PollServiceEventArgs>(); | 98 | new Dictionary<string, PollServiceEventArgs>(); |
89 | 99 | ||
100 | protected Dictionary<string, WebSocketRequestDelegate> m_WebSocketHandlers = | ||
101 | new Dictionary<string, WebSocketRequestDelegate>(); | ||
102 | |||
90 | protected uint m_port; | 103 | protected uint m_port; |
91 | protected uint m_sslport; | 104 | protected uint m_sslport; |
92 | protected bool m_ssl; | 105 | protected bool m_ssl; |
@@ -170,6 +183,22 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
170 | } | 183 | } |
171 | } | 184 | } |
172 | 185 | ||
186 | public void AddWebSocketHandler(string servicepath, WebSocketRequestDelegate handler) | ||
187 | { | ||
188 | lock (m_WebSocketHandlers) | ||
189 | { | ||
190 | if (!m_WebSocketHandlers.ContainsKey(servicepath)) | ||
191 | m_WebSocketHandlers.Add(servicepath, handler); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | public void RemoveWebSocketHandler(string servicepath) | ||
196 | { | ||
197 | lock (m_WebSocketHandlers) | ||
198 | if (m_WebSocketHandlers.ContainsKey(servicepath)) | ||
199 | m_WebSocketHandlers.Remove(servicepath); | ||
200 | } | ||
201 | |||
173 | public List<string> GetStreamHandlerKeys() | 202 | public List<string> GetStreamHandlerKeys() |
174 | { | 203 | { |
175 | lock (m_streamHandlers) | 204 | lock (m_streamHandlers) |
@@ -410,9 +439,24 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
410 | 439 | ||
411 | public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) | 440 | public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) |
412 | { | 441 | { |
442 | |||
413 | OSHttpRequest req = new OSHttpRequest(context, request); | 443 | OSHttpRequest req = new OSHttpRequest(context, request); |
444 | WebSocketRequestDelegate dWebSocketRequestDelegate = null; | ||
445 | lock (m_WebSocketHandlers) | ||
446 | { | ||
447 | if (m_WebSocketHandlers.ContainsKey(req.RawUrl)) | ||
448 | dWebSocketRequestDelegate = m_WebSocketHandlers[req.RawUrl]; | ||
449 | } | ||
450 | if (dWebSocketRequestDelegate != null) | ||
451 | { | ||
452 | dWebSocketRequestDelegate(req.Url.AbsolutePath, new WebSocketHttpServerHandler(req, context, 8192)); | ||
453 | return; | ||
454 | } | ||
455 | |||
414 | OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); | 456 | OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); |
457 | |||
415 | HandleRequest(req, resp); | 458 | HandleRequest(req, resp); |
459 | |||
416 | 460 | ||
417 | // !!!HACK ALERT!!! | 461 | // !!!HACK ALERT!!! |
418 | // There seems to be a bug in the underlying http code that makes subsequent requests | 462 | // There seems to be a bug in the underlying http code that makes subsequent requests |
@@ -501,7 +545,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
501 | LogIncomingToStreamHandler(request, requestHandler); | 545 | LogIncomingToStreamHandler(request, requestHandler); |
502 | 546 | ||
503 | response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. | 547 | response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. |
504 | 548 | ||
505 | if (requestHandler is IStreamedRequestHandler) | 549 | if (requestHandler is IStreamedRequestHandler) |
506 | { | 550 | { |
507 | IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; | 551 | IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler; |