HttpServer: Track current connection, ignore canceled connections

master
Harald Wolff 2019-10-11 12:37:16 +02:00
parent ad38b48ae3
commit 996d949096
2 changed files with 14 additions and 2 deletions

View File

@ -44,7 +44,8 @@ namespace ln.http
{
HTTPServerConnection saveCurrent = Current.Value;
Current.Value = this;
currentConnections.Add(this);
lock (currentConnections)
currentConnections.Add(this);
try
{
@ -53,6 +54,9 @@ namespace ln.http
HttpReader httpReader = new HttpReader(TcpClient.GetStream());
httpReader.Read();
if (!httpReader.Valid)
return;
HttpResponse response = null;
using (CurrentRequest = new HttpRequest(httpReader, (IPEndPoint)TcpClient.Client.LocalEndPoint))
@ -108,7 +112,8 @@ namespace ln.http
finally
{
Current.Value = saveCurrent;
currentConnections.Remove(this);
lock (currentConnections)
currentConnections.Remove(this);
}
}

View File

@ -25,6 +25,8 @@ namespace ln.http
public Dictionary<string, string> Headers { get; } = new Dictionary<string, string>();
public bool Valid { get; private set; } = false;
public HttpReader(Stream stream)
{
Stream = stream;
@ -39,6 +41,9 @@ namespace ln.http
{
ReadRequestHead();
if (blen == 0)
return;
Method = ReadToken();
SkipWhiteSpace();
URL = ReadToken();
@ -47,6 +52,8 @@ namespace ln.http
ReadLine();
ReadHeaders();
Valid = true;
}
public int ReadByte()