mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 06:06:06 +08:00
jsonSimStats: fix null ref when region not found; limite http content lenght; cosmetics
This commit is contained in:
@@ -112,12 +112,12 @@ namespace OSHttpServer
|
||||
LocalIPEndPoint = remoteEndPoint;
|
||||
m_log = m_logWriter;
|
||||
m_isClosing = false;
|
||||
m_currentRequest = new HttpRequest(this);
|
||||
m_parser = new HttpRequestParser(m_log);
|
||||
m_parser.RequestCompleted += OnRequestCompleted;
|
||||
m_parser.RequestLineReceived += OnRequestLine;
|
||||
m_parser.HeaderReceived += OnHeaderReceived;
|
||||
m_parser.BodyBytesReceived += OnBodyBytesReceived;
|
||||
m_currentRequest = new HttpRequest(this);
|
||||
IsSecured = secured;
|
||||
m_stream = stream;
|
||||
m_sock = sock;
|
||||
@@ -215,7 +215,6 @@ namespace OSHttpServer
|
||||
{
|
||||
LogWriter.Write(this, LogPrio.Debug, err.ToString());
|
||||
}
|
||||
//Task.Run(async () => await ReceiveLoop()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -248,9 +247,9 @@ namespace OSHttpServer
|
||||
HttpRequest req = m_requests.Dequeue();
|
||||
req.Clear();
|
||||
}
|
||||
m_requests = null;
|
||||
}
|
||||
m_requests.Clear();
|
||||
m_requests = null;
|
||||
|
||||
m_parser.Clear();
|
||||
|
||||
FirstRequestLineReceived = false;
|
||||
@@ -420,91 +419,12 @@ namespace OSHttpServer
|
||||
//Disconnect(SocketError.NoRecovery);
|
||||
Disconnect(SocketError.Success); // try to flush
|
||||
}
|
||||
catch (IOException err)
|
||||
catch (HttpException err)
|
||||
{
|
||||
LogWriter.Write(this, LogPrio.Debug, "Failed to end receive: " + err.Message);
|
||||
if (err.InnerException is SocketException)
|
||||
Disconnect((SocketError)((SocketException)err.InnerException).ErrorCode);
|
||||
else
|
||||
Disconnect(SocketError.ConnectionReset);
|
||||
}
|
||||
catch (ObjectDisposedException err)
|
||||
{
|
||||
LogWriter.Write(this, LogPrio.Debug, "Failed to end receive : " + err.Message);
|
||||
Disconnect(SocketError.NotSocket);
|
||||
}
|
||||
catch (NullReferenceException err)
|
||||
{
|
||||
LogWriter.Write(this, LogPrio.Debug, "Failed to end receive : NullRef: " + err.Message);
|
||||
Disconnect(SocketError.NoRecovery);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
LogWriter.Write(this, LogPrio.Debug, "Failed to end receive: " + err.Message);
|
||||
Disconnect(SocketError.NoRecovery);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private async Task ReceiveLoop()
|
||||
{
|
||||
m_ReceiveBytesLeft = 0;
|
||||
try
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
if (m_stream == null || !m_stream.CanRead)
|
||||
return;
|
||||
|
||||
int bytesRead = await m_stream.ReadAsync(m_ReceiveBuffer, m_ReceiveBytesLeft, m_ReceiveBuffer.Length - m_ReceiveBytesLeft).ConfigureAwait(false);
|
||||
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
Disconnect(SocketError.Success);
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_isClosing)
|
||||
continue;
|
||||
|
||||
m_ReceiveBytesLeft += bytesRead;
|
||||
|
||||
int offset = m_parser.Parse(m_ReceiveBuffer, 0, m_ReceiveBytesLeft);
|
||||
if (m_stream == null)
|
||||
return; // "Connection: Close" in effect.
|
||||
|
||||
while (offset != 0)
|
||||
{
|
||||
int nextBytesleft = m_ReceiveBytesLeft - offset;
|
||||
if(nextBytesleft <= 0)
|
||||
break;
|
||||
|
||||
int nextOffset = m_parser.Parse(m_ReceiveBuffer, offset, nextBytesleft);
|
||||
|
||||
if (m_stream == null)
|
||||
return; // "Connection: Close" in effect.
|
||||
|
||||
if (nextOffset == 0)
|
||||
break;
|
||||
|
||||
offset = nextOffset;
|
||||
}
|
||||
|
||||
// copy unused bytes to the beginning of the array
|
||||
if (offset > 0 && m_ReceiveBytesLeft > offset)
|
||||
Buffer.BlockCopy(m_ReceiveBuffer, offset, m_ReceiveBuffer, 0, m_ReceiveBytesLeft - offset);
|
||||
|
||||
m_ReceiveBytesLeft -= offset;
|
||||
if (StreamPassedOff)
|
||||
return; //?
|
||||
}
|
||||
}
|
||||
catch (BadRequestException err)
|
||||
{
|
||||
LogWriter.Write(this, LogPrio.Warning, "Bad request, responding with it. Error: " + err);
|
||||
LogWriter.Write(this, LogPrio.Warning, "Bad request, responding with it. Error: " + err.Message);
|
||||
try
|
||||
{
|
||||
Respond("HTTP/1.1", HttpStatusCode.BadRequest, err.Message);
|
||||
Respond("HTTP/1.1", err.HttpStatusCode, err.Message);
|
||||
}
|
||||
catch (Exception err2)
|
||||
{
|
||||
@@ -537,7 +457,6 @@ namespace OSHttpServer
|
||||
Disconnect(SocketError.NoRecovery);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private void OnRequestCompleted(object source, EventArgs args)
|
||||
{
|
||||
@@ -546,7 +465,7 @@ namespace OSHttpServer
|
||||
FullRequestReceived = true;
|
||||
LastActivityTimeMS = ContextTimeoutManager.EnvironmentTickCount();
|
||||
|
||||
if (m_maxRequests == 0)
|
||||
if (m_maxRequests <= 0 || RequestReceived == null)
|
||||
return;
|
||||
|
||||
if (--m_maxRequests == 0)
|
||||
@@ -573,22 +492,20 @@ namespace OSHttpServer
|
||||
|
||||
m_currentRequest.Body.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
bool donow = true;
|
||||
HttpRequest currentRequest = m_currentRequest;
|
||||
m_currentRequest = new HttpRequest(this);
|
||||
|
||||
lock (m_requestsLock)
|
||||
{
|
||||
if(m_waitingResponse)
|
||||
{
|
||||
m_requests.Enqueue(m_currentRequest);
|
||||
donow = false;
|
||||
m_requests.Enqueue(currentRequest);
|
||||
return;
|
||||
}
|
||||
else
|
||||
m_waitingResponse = true;
|
||||
}
|
||||
|
||||
if(donow)
|
||||
RequestReceived?.Invoke(this, new RequestEventArgs(m_currentRequest));
|
||||
|
||||
m_currentRequest = new HttpRequest(this);
|
||||
RequestReceived?.Invoke(this, new RequestEventArgs(currentRequest));
|
||||
}
|
||||
|
||||
public void StartSendResponse(HttpResponse response)
|
||||
|
||||
Reference in New Issue
Block a user