Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Fix environment specific header termination on Unix (issue #483) #484

Merged
merged 2 commits into from
Aug 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Titanium.Web.Proxy/Http/HttpWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public class HttpWebClient
{
private const string CRLF = "\r\n";

internal HttpWebClient(Request request = null, Response response = null)
{
Expand Down Expand Up @@ -103,26 +104,29 @@ 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), CRLF);
}

// write request headers
foreach (var header in Request.Headers)
{
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)
Expand Down