remove some redundancy

master
UbitUmarov 2020-05-11 15:12:21 +01:00
parent 7f3bb9267a
commit 713c222ec8
8 changed files with 27 additions and 73 deletions

View File

@ -68,7 +68,7 @@ namespace OpenSim.Capabilities.Handlers
IRequestHandler reqHandler IRequestHandler reqHandler
= new RestHTTPHandler( = new RestHTTPHandler(
"GET", "GET",
"/CAPS/" + UUID.Random(), "/" + UUID.Random(),
httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null),
"GetMesh", "GetMesh",
null); null);

View File

@ -66,7 +66,7 @@ namespace OpenSim.Capabilities.Handlers
string rurl = serverConfig.GetString("GetTextureRedirectURL"); string rurl = serverConfig.GetString("GetTextureRedirectURL");
; ;
server.AddStreamHandler( server.AddStreamHandler(
new GetTextureRobustHandler("/CAPS/GetTexture/", m_AssetService, "GetTexture", null, rurl)); new GetTextureRobustHandler("/CAPS/GetTexture", m_AssetService, "GetTexture", null, rurl));
} }
} }
} }

View File

@ -101,7 +101,7 @@ namespace OpenSim.Framework.Servers.HttpServer
protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>();
// protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); // protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>();
protected ConcurrentDictionary<string, PollServiceEventArgs> m_pollHandlers = new ConcurrentDictionary<string, PollServiceEventArgs>(); protected ConcurrentDictionary<string, PollServiceEventArgs> m_pollHandlers = new ConcurrentDictionary<string, PollServiceEventArgs>();
protected Dictionary<string, WebSocketRequestDelegate> m_WebSocketHandlers = new Dictionary<string, WebSocketRequestDelegate>(); protected ConcurrentDictionary<string, WebSocketRequestDelegate> m_WebSocketHandlers = new ConcurrentDictionary<string, WebSocketRequestDelegate>();
protected ConcurrentDictionary<string, IRequestHandler> m_streamHandlers = new ConcurrentDictionary<string, IRequestHandler>(); protected ConcurrentDictionary<string, IRequestHandler> m_streamHandlers = new ConcurrentDictionary<string, IRequestHandler>();
protected ConcurrentDictionary<string, ISimpleStreamHandler> m_simpleStreamHandlers = new ConcurrentDictionary<string, ISimpleStreamHandler>(); protected ConcurrentDictionary<string, ISimpleStreamHandler> m_simpleStreamHandlers = new ConcurrentDictionary<string, ISimpleStreamHandler>();
@ -354,18 +354,12 @@ namespace OpenSim.Framework.Servers.HttpServer
public void AddWebSocketHandler(string servicepath, WebSocketRequestDelegate handler) public void AddWebSocketHandler(string servicepath, WebSocketRequestDelegate handler)
{ {
lock (m_WebSocketHandlers) m_WebSocketHandlers.TryAdd(servicepath, handler);
{
if (!m_WebSocketHandlers.ContainsKey(servicepath))
m_WebSocketHandlers.Add(servicepath, handler);
}
} }
public void RemoveWebSocketHandler(string servicepath) public void RemoveWebSocketHandler(string servicepath)
{ {
lock (m_WebSocketHandlers) m_WebSocketHandlers.TryRemove(servicepath, out WebSocketRequestDelegate dummy);
if (m_WebSocketHandlers.ContainsKey(servicepath))
m_WebSocketHandlers.Remove(servicepath);
} }
public List<string> GetStreamHandlerKeys() public List<string> GetStreamHandlerKeys()
@ -548,24 +542,30 @@ namespace OpenSim.Framework.Servers.HttpServer
return null; return null;
} }
public void OnRequest(object source, RequestEventArgs args) public void OnRequest(object source, RequestEventArgs args)
{ {
RequestNumber++; RequestNumber++;
try try
{ {
IHttpClientContext context = (IHttpClientContext)source;
IHttpRequest request = args.Request; IHttpRequest request = args.Request;
OSHttpRequest osRequest = new OSHttpRequest(request);
if(m_WebSocketHandlers.TryGetValue(osRequest.RawUrl, out WebSocketRequestDelegate dWebSocketRequestDelegate))
{
dWebSocketRequestDelegate?.Invoke(osRequest.Url.AbsolutePath, new WebSocketHttpServerHandler(osRequest, 8192));
return;
}
if (TryGetPollServiceHTTPHandler(Util.TrimEndSlash(request.UriPath), out PollServiceEventArgs psEvArgs)) if (TryGetPollServiceHTTPHandler(Util.TrimEndSlash(request.UriPath), out PollServiceEventArgs psEvArgs))
{ {
psEvArgs.RequestsReceived++; psEvArgs.RequestsReceived++;
PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request); PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, request);
psEvArgs.Request?.Invoke(psreq.RequestID, new OSHttpRequest(request)); psEvArgs.Request?.Invoke(psreq.RequestID, osRequest);
m_pollServiceManager.Enqueue(psreq); m_pollServiceManager.Enqueue(psreq);
} }
else else
{ {
OnHandleRequestIOThread(request); HandleRequest(osRequest, new OSHttpResponse(osRequest));
} }
} }
catch (Exception e) catch (Exception e)
@ -574,24 +574,6 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
} }
private void OnHandleRequestIOThread(IHttpRequest request)
{
OSHttpRequest req = new OSHttpRequest(request);
WebSocketRequestDelegate dWebSocketRequestDelegate = null;
lock (m_WebSocketHandlers)
{
if (m_WebSocketHandlers.ContainsKey(req.RawUrl))
dWebSocketRequestDelegate = m_WebSocketHandlers[req.RawUrl];
}
if (dWebSocketRequestDelegate != null)
{
dWebSocketRequestDelegate(req.Url.AbsolutePath, new WebSocketHttpServerHandler(req, request.Context, 8192));
return;
}
HandleRequest(req, new OSHttpResponse(req));
}
/// <summary> /// <summary>
/// This methods is the start of incoming HTTP request handling. /// This methods is the start of incoming HTTP request handling.
/// </summary> /// </summary>

View File

@ -309,8 +309,7 @@ namespace OpenSim.Framework.Servers.HttpServer
/// replying</param> /// replying</param>
public OSHttpResponse(OSHttpRequest req) public OSHttpResponse(OSHttpRequest req)
{ {
_httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest); _httpResponse = new HttpResponse(req.IHttpRequest);
} }
public OSHttpResponse(HttpResponse resp) public OSHttpResponse(HttpResponse resp)

View File

@ -35,14 +35,14 @@ namespace OSHttpServer
/// <param name="context">Client that send the <see cref="IHttpRequest"/>.</param> /// <param name="context">Client that send the <see cref="IHttpRequest"/>.</param>
/// <param name="request">Contains information of what the client want to receive.</param> /// <param name="request">Contains information of what the client want to receive.</param>
/// <exception cref="ArgumentException"><see cref="IHttpRequest.HttpVersion"/> cannot be empty.</exception> /// <exception cref="ArgumentException"><see cref="IHttpRequest.HttpVersion"/> cannot be empty.</exception>
public HttpResponse(IHttpClientContext context, IHttpRequest request) public HttpResponse(IHttpRequest request)
{ {
m_httpVersion = request.HttpVersion; m_httpVersion = request.HttpVersion;
if (string.IsNullOrEmpty(m_httpVersion)) if (string.IsNullOrEmpty(m_httpVersion))
m_httpVersion = "HTTP/1.1"; m_httpVersion = "HTTP/1.1";
Status = HttpStatusCode.OK; Status = HttpStatusCode.OK;
m_context = context; m_context = request.Context;
m_Connetion = request.Connection; m_Connetion = request.Connection;
requestID = request.ID; requestID = request.ID;
RawBufferStart = -1; RawBufferStart = -1;

View File

@ -42,42 +42,17 @@ namespace OpenSim.Framework.Servers.HttpServer
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public readonly PollServiceEventArgs PollServiceArgs; public readonly PollServiceEventArgs PollServiceArgs;
public readonly IHttpClientContext HttpContext;
public readonly IHttpRequest Request; public readonly IHttpRequest Request;
public readonly int RequestTime; public readonly int RequestTime;
public readonly UUID RequestID; public readonly UUID RequestID;
public int contextHash;
/*
private void GenContextHash()
{
Random rnd = new Random();
contextHash = 0;
if (Request.Headers["remote_addr"] != null)
contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16;
else
contextHash = rnd.Next() << 16;
if (Request.Headers["remote_port"] != null)
{
string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' });
contextHash += Int32.Parse(strPorts[0]);
}
else
contextHash += rnd.Next() & 0xffff;
}
*/
public PollServiceHttpRequest( public PollServiceHttpRequest(
PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) PollServiceEventArgs pPollServiceArgs, IHttpRequest pRequest)
{ {
PollServiceArgs = pPollServiceArgs; PollServiceArgs = pPollServiceArgs;
HttpContext = pHttpContext;
Request = pRequest; Request = pRequest;
RequestTime = System.Environment.TickCount; RequestTime = System.Environment.TickCount;
RequestID = UUID.Random(); RequestID = UUID.Random();
// GenContextHash();
contextHash = HttpContext.contextID;
} }
internal void DoHTTPGruntWork(Hashtable responsedata) internal void DoHTTPGruntWork(Hashtable responsedata)
@ -85,8 +60,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if (Request.Body.CanRead) if (Request.Body.CanRead)
Request.Body.Dispose(); Request.Body.Dispose();
OSHttpResponse response OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
= new OSHttpResponse(new HttpResponse(HttpContext, Request));
if (responsedata == null) if (responsedata == null)
{ {
@ -248,8 +222,7 @@ namespace OpenSim.Framework.Servers.HttpServer
internal void DoHTTPstop() internal void DoHTTPstop()
{ {
OSHttpResponse response OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
= new OSHttpResponse(new HttpResponse(HttpContext, Request));
if(Request.Body.CanRead) if(Request.Body.CanRead)
Request.Body.Dispose(); Request.Body.Dispose();

View File

@ -161,13 +161,13 @@ namespace OpenSim.Framework.Servers.HttpServer
Watchdog.UpdateThread(); Watchdog.UpdateThread();
if (!req.HttpContext.CanSend()) if (!req.Request.Context.CanSend())
{ {
req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id);
continue; continue;
} }
if (req.HttpContext.IsSending()) if (req.Request.Context.IsSending())
{ {
ReQueueEvent(req); ReQueueEvent(req);
continue; continue;

View File

@ -132,13 +132,13 @@ namespace OpenSim.Framework.Servers.HttpServer
/// </summary> /// </summary>
private const string WebsocketHandshakeAcceptHashConstant = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; private const string WebsocketHandshakeAcceptHashConstant = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
public WebSocketHttpServerHandler(OSHttpRequest preq, IHttpClientContext pContext, int bufferlen) public WebSocketHttpServerHandler(OSHttpRequest preq, int bufferlen)
: base(preq.HttpMethod, preq.Url.OriginalString) : base(preq.HttpMethod, preq.Url.OriginalString)
{ {
_request = preq; _request = preq;
_networkContext = pContext.GiveMeTheNetworkStreamIKnowWhatImDoing(); _networkContext = preq.IHttpClientContext.GiveMeTheNetworkStreamIKnowWhatImDoing();
_networkContext.Stream.ReadTimeout = _defaultReadTimeout; _networkContext.Stream.ReadTimeout = _defaultReadTimeout;
_clientContext = pContext; _clientContext = preq.IHttpClientContext;
_bufferLength = bufferlen; _bufferLength = bufferlen;
_buffer = new byte[_bufferLength]; _buffer = new byte[_bufferLength];
} }