fixes
This commit is contained in:
parent
b118c1cd30
commit
9834d350ec
2 changed files with 12 additions and 9 deletions
|
@ -48,7 +48,12 @@ public sealed class HttpClient
|
||||||
await FixRequest(request, host, ConnectionType.Close).WriteTo(stream);
|
await FixRequest(request, host, ConnectionType.Close).WriteTo(stream);
|
||||||
|
|
||||||
//Read response
|
//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)
|
static HttpRequest FixRequest(HttpRequest req, string host, ConnectionType conType)
|
||||||
|
@ -61,7 +66,7 @@ public sealed class HttpClient
|
||||||
Fields = req.Fields with
|
Fields = req.Fields with
|
||||||
{
|
{
|
||||||
Host = host,
|
Host = host,
|
||||||
Connection = ConnectionType.Close,
|
Connection = conType,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ class HttpStream : IDisposable
|
||||||
return new HttpContent(headers.ContentType.Value, data);
|
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
|
//Read initial header
|
||||||
string header = await ReadLine();
|
string header = await ReadLine();
|
||||||
|
@ -192,12 +192,10 @@ class HttpStream : IDisposable
|
||||||
if (!Enum.TryParse(parts[0], true, out HttpMethod method))
|
if (!Enum.TryParse(parts[0], true, out HttpMethod method))
|
||||||
throw new HttpException("Unknown HTTP method");
|
throw new HttpException("Unknown HTTP method");
|
||||||
|
|
||||||
//Path and query
|
//Path
|
||||||
string[] pathParts = parts[1].Split('?', 2, StringSplitOptions.RemoveEmptyEntries);
|
string path = parts[1].Replace("\\", "/");
|
||||||
string path = pathParts[0].Replace("\\", "/");
|
|
||||||
NameValueCollection query = HttpUtility.ParseQueryString(pathParts.Length > 1 ? pathParts[1] : string.Empty);
|
|
||||||
|
|
||||||
return (method, path, query);
|
return (method, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<(int Code, string Message)> ReadResponseHeader()
|
public async ValueTask<(int Code, string Message)> ReadResponseHeader()
|
||||||
|
@ -220,7 +218,7 @@ class HttpStream : IDisposable
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(HttpMethod method, string path, NameValueCollection query) = await ReadRequestHeader();
|
(HttpMethod method, string path) = await ReadRequestHeader();
|
||||||
HttpFields fields = await ReadFields();
|
HttpFields fields = await ReadFields();
|
||||||
HttpContent? content = await ReadContent(fields);
|
HttpContent? content = await ReadContent(fields);
|
||||||
return new HttpRequest(method, path, fields, content);
|
return new HttpRequest(method, path, fields, content);
|
||||||
|
|
Loading…
Reference in a new issue