diff --git a/HTTP/HttpClient.cs b/HTTP/HttpClient.cs index c1dce8e..1578e8b 100644 --- a/HTTP/HttpClient.cs +++ b/HTTP/HttpClient.cs @@ -48,7 +48,12 @@ public sealed class HttpClient await FixRequest(request, host, ConnectionType.Close).WriteTo(stream); //Read response - return await stream.ReadResponse(); + HttpResponse res = await stream.ReadResponse(); + + //Close + client.Close(); + + return res; } static HttpRequest FixRequest(HttpRequest req, string host, ConnectionType conType) @@ -61,7 +66,7 @@ public sealed class HttpClient Fields = req.Fields with { Host = host, - Connection = ConnectionType.Close, + Connection = conType, } }; } diff --git a/HTTP/HttpStream.cs b/HTTP/HttpStream.cs index 2d39af7..02d06f1 100644 --- a/HTTP/HttpStream.cs +++ b/HTTP/HttpStream.cs @@ -179,7 +179,7 @@ class HttpStream : IDisposable return new HttpContent(headers.ContentType.Value, data); } - public async ValueTask<(HttpMethod Method, string Path, NameValueCollection Query)> ReadRequestHeader() + public async ValueTask<(HttpMethod Method, string Path)> ReadRequestHeader() { //Read initial header string header = await ReadLine(); @@ -192,12 +192,10 @@ class HttpStream : IDisposable if (!Enum.TryParse(parts[0], true, out HttpMethod method)) throw new HttpException("Unknown HTTP method"); - //Path and query - string[] pathParts = parts[1].Split('?', 2, StringSplitOptions.RemoveEmptyEntries); - string path = pathParts[0].Replace("\\", "/"); - NameValueCollection query = HttpUtility.ParseQueryString(pathParts.Length > 1 ? pathParts[1] : string.Empty); + //Path + string path = parts[1].Replace("\\", "/"); - return (method, path, query); + return (method, path); } public async ValueTask<(int Code, string Message)> ReadResponseHeader() @@ -220,7 +218,7 @@ class HttpStream : IDisposable { try { - (HttpMethod method, string path, NameValueCollection query) = await ReadRequestHeader(); + (HttpMethod method, string path) = await ReadRequestHeader(); HttpFields fields = await ReadFields(); HttpContent? content = await ReadContent(fields); return new HttpRequest(method, path, fields, content);