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
= new RestHTTPHandler(
"GET",
"/CAPS/" + UUID.Random(),
"/" + UUID.Random(),
httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null),
"GetMesh",
null);

View File

@ -66,7 +66,7 @@ namespace OpenSim.Capabilities.Handlers
string rurl = serverConfig.GetString("GetTextureRedirectURL");
;
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, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>();
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, ISimpleStreamHandler> m_simpleStreamHandlers = new ConcurrentDictionary<string, ISimpleStreamHandler>();
@ -354,18 +354,12 @@ namespace OpenSim.Framework.Servers.HttpServer
public void AddWebSocketHandler(string servicepath, WebSocketRequestDelegate handler)
{
lock (m_WebSocketHandlers)
{
if (!m_WebSocketHandlers.ContainsKey(servicepath))
m_WebSocketHandlers.Add(servicepath, handler);
}
m_WebSocketHandlers.TryAdd(servicepath, handler);
}
public void RemoveWebSocketHandler(string servicepath)
{
lock (m_WebSocketHandlers)
if (m_WebSocketHandlers.ContainsKey(servicepath))
m_WebSocketHandlers.Remove(servicepath);
m_WebSocketHandlers.TryRemove(servicepath, out WebSocketRequestDelegate dummy);
}
public List<string> GetStreamHandlerKeys()
@ -548,24 +542,30 @@ namespace OpenSim.Framework.Servers.HttpServer
return null;
}
public void OnRequest(object source, RequestEventArgs args)
{
RequestNumber++;
try
{
IHttpClientContext context = (IHttpClientContext)source;
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))
{
psEvArgs.RequestsReceived++;
PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);
psEvArgs.Request?.Invoke(psreq.RequestID, new OSHttpRequest(request));
PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, request);
psEvArgs.Request?.Invoke(psreq.RequestID, osRequest);
m_pollServiceManager.Enqueue(psreq);
}
else
{
OnHandleRequestIOThread(request);
HandleRequest(osRequest, new OSHttpResponse(osRequest));
}
}
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>
/// This methods is the start of incoming HTTP request handling.
/// </summary>

View File

@ -309,8 +309,7 @@ namespace OpenSim.Framework.Servers.HttpServer
/// replying</param>
public OSHttpResponse(OSHttpRequest req)
{
_httpResponse = new HttpResponse(req.IHttpClientContext, req.IHttpRequest);
_httpResponse = new HttpResponse(req.IHttpRequest);
}
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="request">Contains information of what the client want to receive.</param>
/// <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;
if (string.IsNullOrEmpty(m_httpVersion))
m_httpVersion = "HTTP/1.1";
Status = HttpStatusCode.OK;
m_context = context;
m_context = request.Context;
m_Connetion = request.Connection;
requestID = request.ID;
RawBufferStart = -1;

View File

@ -42,42 +42,17 @@ namespace OpenSim.Framework.Servers.HttpServer
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public readonly PollServiceEventArgs PollServiceArgs;
public readonly IHttpClientContext HttpContext;
public readonly IHttpRequest Request;
public readonly int RequestTime;
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(
PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
PollServiceEventArgs pPollServiceArgs, IHttpRequest pRequest)
{
PollServiceArgs = pPollServiceArgs;
HttpContext = pHttpContext;
Request = pRequest;
RequestTime = System.Environment.TickCount;
RequestID = UUID.Random();
// GenContextHash();
contextHash = HttpContext.contextID;
}
internal void DoHTTPGruntWork(Hashtable responsedata)
@ -85,8 +60,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if (Request.Body.CanRead)
Request.Body.Dispose();
OSHttpResponse response
= new OSHttpResponse(new HttpResponse(HttpContext, Request));
OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
if (responsedata == null)
{
@ -248,8 +222,7 @@ namespace OpenSim.Framework.Servers.HttpServer
internal void DoHTTPstop()
{
OSHttpResponse response
= new OSHttpResponse(new HttpResponse(HttpContext, Request));
OSHttpResponse response = new OSHttpResponse(new HttpResponse(Request));
if(Request.Body.CanRead)
Request.Body.Dispose();

View File

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

View File

@ -132,13 +132,13 @@ namespace OpenSim.Framework.Servers.HttpServer
/// </summary>
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)
{
_request = preq;
_networkContext = pContext.GiveMeTheNetworkStreamIKnowWhatImDoing();
_networkContext = preq.IHttpClientContext.GiveMeTheNetworkStreamIKnowWhatImDoing();
_networkContext.Stream.ReadTimeout = _defaultReadTimeout;
_clientContext = pContext;
_clientContext = preq.IHttpClientContext;
_bufferLength = bufferlen;
_buffer = new byte[_bufferLength];
}