This commit is contained in:
uwaa 2024-11-25 22:54:35 +00:00
parent b118c1cd30
commit 9834d350ec
2 changed files with 12 additions and 9 deletions

View file

@ -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,
}
};
}

View file

@ -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);