From 5cecf4f15186ba651b2d366a84fea8f860dcffaa Mon Sep 17 00:00:00 2001 From: Paul S Date: Thu, 23 Aug 2018 08:41:14 +0900 Subject: [PATCH 1/2] Fix environment specific header termination on Unix. --- Titanium.Web.Proxy/Http/HttpWebClient.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Titanium.Web.Proxy/Http/HttpWebClient.cs b/Titanium.Web.Proxy/Http/HttpWebClient.cs index 1247499b1..e8b6fcfc1 100644 --- a/Titanium.Web.Proxy/Http/HttpWebClient.cs +++ b/Titanium.Web.Proxy/Http/HttpWebClient.cs @@ -16,6 +16,7 @@ namespace Titanium.Web.Proxy.Http /// public class HttpWebClient { + private const string CRLF = "\r\n"; internal HttpWebClient(Request request = null, Response response = null) { @@ -103,14 +104,16 @@ await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method, Request.HttpVersion), cancellationToken); var headerBuilder = new StringBuilder(); + // Send Authentication to Upstream proxy if needed if (!isTransparent && upstreamProxy != null && ServerConnection.IsHttps == false && !string.IsNullOrEmpty(upstreamProxy.UserName) && upstreamProxy.Password != null) { - headerBuilder.AppendLine(HttpHeader.ProxyConnectionKeepAlive.ToString()); - headerBuilder.AppendLine(HttpHeader.GetProxyAuthorizationHeader(upstreamProxy.UserName, upstreamProxy.Password).ToString()); + headerBuilder.AppendFormat("{0}{1}", HttpHeader.ProxyConnectionKeepAlive, CRLF); + headerBuilder.AppendFormat("{0}{1}", + HttpHeader.GetProxyAuthorizationHeader(upstreamProxy.UserName, upstreamProxy.Password)); } // write request headers @@ -118,11 +121,12 @@ await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method, { if (isTransparent || header.Name != KnownHeaders.ProxyAuthorization) { - headerBuilder.AppendLine(header.ToString()); + headerBuilder.AppendFormat("{0}{1}", header, CRLF); } } - headerBuilder.AppendLine(); + headerBuilder.Append(CRLF); + await writer.WriteAsync(headerBuilder.ToString(), cancellationToken); if (enable100ContinueBehaviour) From 364c54ffb9eb16498763b80d0c4f403127cacdf6 Mon Sep 17 00:00:00 2001 From: Paul S Date: Thu, 23 Aug 2018 08:58:57 +0900 Subject: [PATCH 2/2] Add back missing CRLF on upstream proxy auth header. --- Titanium.Web.Proxy/Http/HttpWebClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Titanium.Web.Proxy/Http/HttpWebClient.cs b/Titanium.Web.Proxy/Http/HttpWebClient.cs index e8b6fcfc1..6335d7ac8 100644 --- a/Titanium.Web.Proxy/Http/HttpWebClient.cs +++ b/Titanium.Web.Proxy/Http/HttpWebClient.cs @@ -113,7 +113,7 @@ await writer.WriteLineAsync(Request.CreateRequestLine(Request.Method, { headerBuilder.AppendFormat("{0}{1}", HttpHeader.ProxyConnectionKeepAlive, CRLF); headerBuilder.AppendFormat("{0}{1}", - HttpHeader.GetProxyAuthorizationHeader(upstreamProxy.UserName, upstreamProxy.Password)); + HttpHeader.GetProxyAuthorizationHeader(upstreamProxy.UserName, upstreamProxy.Password), CRLF); } // write request headers