Fix upstream request line handling
This commit is contained in:
22
Program.cs
22
Program.cs
@@ -378,7 +378,7 @@ class Program
|
||||
{
|
||||
var lines = req.Raw.Split("\r\n", StringSplitOptions.None);
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(lines[0]).Append("\r\n");
|
||||
sb.Append(BuildUpstreamRequestLine(req, lines[0])).Append("\r\n");
|
||||
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
{
|
||||
@@ -410,6 +410,26 @@ class Program
|
||||
return result;
|
||||
}
|
||||
|
||||
static string BuildUpstreamRequestLine(HttpRequest req, string originalLine)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(originalLine))
|
||||
return originalLine ?? string.Empty;
|
||||
|
||||
var parts = originalLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length < 3)
|
||||
return originalLine;
|
||||
|
||||
string method = parts[0];
|
||||
string version = parts[2];
|
||||
string url = req.Url;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
return originalLine;
|
||||
|
||||
// Upstream forward proxy expects absolute-form: METHOD http://host/path HTTP/1.1
|
||||
return $"{method} {url} {version}";
|
||||
}
|
||||
|
||||
static string BuildUpstreamProxyAuthHeader()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(UPSTREAM_USER))
|
||||
|
||||
Reference in New Issue
Block a user