HttpServer: Track current connection, ignore canceled connections
parent
ad38b48ae3
commit
996d949096
|
@ -44,7 +44,8 @@ namespace ln.http
|
||||||
{
|
{
|
||||||
HTTPServerConnection saveCurrent = Current.Value;
|
HTTPServerConnection saveCurrent = Current.Value;
|
||||||
Current.Value = this;
|
Current.Value = this;
|
||||||
currentConnections.Add(this);
|
lock (currentConnections)
|
||||||
|
currentConnections.Add(this);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -53,6 +54,9 @@ namespace ln.http
|
||||||
HttpReader httpReader = new HttpReader(TcpClient.GetStream());
|
HttpReader httpReader = new HttpReader(TcpClient.GetStream());
|
||||||
httpReader.Read();
|
httpReader.Read();
|
||||||
|
|
||||||
|
if (!httpReader.Valid)
|
||||||
|
return;
|
||||||
|
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
|
|
||||||
using (CurrentRequest = new HttpRequest(httpReader, (IPEndPoint)TcpClient.Client.LocalEndPoint))
|
using (CurrentRequest = new HttpRequest(httpReader, (IPEndPoint)TcpClient.Client.LocalEndPoint))
|
||||||
|
@ -108,7 +112,8 @@ namespace ln.http
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Current.Value = saveCurrent;
|
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 Dictionary<string, string> Headers { get; } = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
public bool Valid { get; private set; } = false;
|
||||||
|
|
||||||
public HttpReader(Stream stream)
|
public HttpReader(Stream stream)
|
||||||
{
|
{
|
||||||
Stream = stream;
|
Stream = stream;
|
||||||
|
@ -39,6 +41,9 @@ namespace ln.http
|
||||||
{
|
{
|
||||||
ReadRequestHead();
|
ReadRequestHead();
|
||||||
|
|
||||||
|
if (blen == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
Method = ReadToken();
|
Method = ReadToken();
|
||||||
SkipWhiteSpace();
|
SkipWhiteSpace();
|
||||||
URL = ReadToken();
|
URL = ReadToken();
|
||||||
|
@ -47,6 +52,8 @@ namespace ln.http
|
||||||
ReadLine();
|
ReadLine();
|
||||||
|
|
||||||
ReadHeaders();
|
ReadHeaders();
|
||||||
|
|
||||||
|
Valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ReadByte()
|
public int ReadByte()
|
||||||
|
|
Loading…
Reference in New Issue