HttpServer: Track current connection, ignore canceled connections
parent
ad38b48ae3
commit
996d949096
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue