reduce httppipeline depth

master
UbitUmarov 2020-04-06 16:53:28 +01:00
parent 3989dbac31
commit 29f59fe407
4 changed files with 32 additions and 24 deletions

View File

@ -79,8 +79,11 @@ namespace OpenSim.Framework.Servers.HttpServer
{
RequestCookies cookies = _request.Cookies;
HttpCookieCollection httpCookies = new HttpCookieCollection();
foreach (RequestCookie cookie in cookies)
httpCookies.Add(new HttpCookie(cookie.Name, cookie.Value));
if(cookies != null)
{
foreach (RequestCookie cookie in cookies)
httpCookies.Add(new HttpCookie(cookie.Name, cookie.Value));
}
return httpCookies;
}
}

View File

@ -20,7 +20,7 @@ namespace OSHttpServer
/// </remarks>
public class HttpClientContext : IHttpClientContext, IDisposable
{
const int MAXREQUESTS = 20;
const int MAXPIPEREQUESTS = 5;
const int MAXKEEPALIVE = 60000;
static private int basecontextID;
@ -47,7 +47,7 @@ namespace OSHttpServer
public int m_TimeoutKeepAlive = MAXKEEPALIVE; // 400 seconds before keepalive timeout
// public int TimeoutKeepAlive = 120000; // 400 seconds before keepalive timeout
public int m_maxRequests = MAXREQUESTS;
public int m_maxPipeRequests = MAXPIPEREQUESTS;
public bool FirstRequestLineReceived;
public bool FullRequestReceived;
@ -68,12 +68,15 @@ namespace OSHttpServer
}
}
public int MAXRequests
public int MaxPipeRequests
{
get { return m_maxRequests; }
get { return m_maxPipeRequests; }
set
{
m_maxRequests = value > MAXREQUESTS ? MAXREQUESTS : value;
if(value <= 1)
m_maxPipeRequests = 1;
else
m_maxPipeRequests = value > MAXPIPEREQUESTS ? MAXPIPEREQUESTS : value;
}
}
@ -354,6 +357,9 @@ namespace OSHttpServer
return;
}
if(m_maxPipeRequests <= 0)
return;
m_ReceiveBytesLeft += bytesRead;
if (m_ReceiveBytesLeft > m_ReceiveBuffer.Length)
{
@ -531,28 +537,29 @@ namespace OSHttpServer
{
TriggerKeepalive = false;
MonitorKeepaliveMS = 0;
FullRequestReceived = true;
if (m_maxPipeRequests == 0)
return;
if(--m_maxPipeRequests == 0)
m_currentRequest.Connection = ConnectionType.Close;
// load cookies if they exist
RequestCookies cookies = m_currentRequest.Headers["cookie"] != null
? new RequestCookies(m_currentRequest.Headers["cookie"]) : new RequestCookies(String.Empty);
m_currentRequest.SetCookies(cookies);
if(m_currentRequest.Headers["cookie"] != null)
m_currentRequest.SetCookies(new RequestCookies(m_currentRequest.Headers["cookie"]));
m_currentRequest.Body.Seek(0, SeekOrigin.Begin);
FullRequestReceived = true;
int nreqs;
lock (requestsInServiceIDs)
{
nreqs = requestsInServiceIDs.Count;
requestsInServiceIDs.Add(m_currentRequest.ID);
if (m_maxRequests > 0)
m_maxRequests--;
}
// for now pipeline requests need to be serialized by opensim
RequestReceived(this, new RequestEventArgs(m_currentRequest));
RequestReceived?.Invoke(this, new RequestEventArgs(m_currentRequest));
m_currentRequest = new HttpRequest(this);
@ -610,10 +617,8 @@ namespace OSHttpServer
lock (requestsInServiceIDs)
{
requestsInServiceIDs.Remove(requestID);
// doclose = doclose && requestsInServiceIDs.Count == 0;
if (requestsInServiceIDs.Count > 1)
{
}
}
@ -750,11 +755,11 @@ namespace OSHttpServer
/// <remarks>
/// Event can be used to clean up a context, or to reuse it.
/// </remarks>
public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
public event EventHandler<DisconnectedEventArgs> Disconnected;
/// <summary>
/// A request have been received in the context.
/// </summary>
public event EventHandler<RequestEventArgs> RequestReceived = delegate { };
public event EventHandler<RequestEventArgs> RequestReceived;
public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
{

View File

@ -245,9 +245,9 @@ namespace OSHttpServer
sb.Append("Server: OSWebServer\r\n");
int keepaliveS = m_context.TimeoutKeepAlive / 1000;
if (Connection == ConnectionType.KeepAlive && keepaliveS > 0 && m_context.MAXRequests > 0)
if (Connection == ConnectionType.KeepAlive && keepaliveS > 0 && m_context.MaxPipeRequests > 0)
{
sb.AppendFormat("Keep-Alive:timeout={0}, max={1}\r\n", keepaliveS, m_context.MAXRequests);
sb.AppendFormat("Keep-Alive:timeout={0}, max={1}\r\n", keepaliveS, m_context.MaxPipeRequests);
sb.Append("Connection: Keep-Alive\r\n");
}
else
@ -282,7 +282,7 @@ namespace OSHttpServer
if (Sent)
throw new InvalidOperationException("Everything have already been sent.");
if (m_context.MAXRequests == 0 || m_keepAlive == 0)
if (m_context.MaxPipeRequests == 0 || m_keepAlive == 0)
{
Connection = ConnectionType.Close;
m_context.TimeoutKeepAlive = 0;

View File

@ -23,7 +23,7 @@ namespace OSHttpServer
int contextID {get;}
int TimeoutKeepAlive {get; set; }
int MAXRequests{get; set; }
int MaxPipeRequests{get; set; }
bool CanSend();
bool IsSending();