Commit 67bfa3bc authored by justcoding121's avatar justcoding121

refactor new line

parent 2774ac08
...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Helpers
private readonly Stream stream; private readonly Stream stream;
private readonly IBufferPool bufferPool; private readonly IBufferPool bufferPool;
private static readonly byte[] newLine = ProxyConstants.NewLine; private static readonly byte[] newLine = ProxyConstants.NewLineBytes;
private static readonly Encoder encoder = Encoding.ASCII.GetEncoder(); private static readonly Encoder encoder = Encoding.ASCII.GetEncoder();
...@@ -109,9 +109,9 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -109,9 +109,9 @@ namespace Titanium.Web.Proxy.Helpers
var headerBuilder = new StringBuilder(); var headerBuilder = new StringBuilder();
foreach (var header in headers) foreach (var header in headers)
{ {
headerBuilder.AppendLine(header.ToString()); headerBuilder.Append($"{header.ToString()}{ProxyConstants.NewLine}");
} }
headerBuilder.AppendLine(); headerBuilder.Append(ProxyConstants.NewLine);
await WriteAsync(headerBuilder.ToString(), cancellationToken); await WriteAsync(headerBuilder.ToString(), cancellationToken);
......
...@@ -8,6 +8,7 @@ using Titanium.Web.Proxy.Exceptions; ...@@ -8,6 +8,7 @@ using Titanium.Web.Proxy.Exceptions;
using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.Network.Tcp; using Titanium.Web.Proxy.Network.Tcp;
using Titanium.Web.Proxy.Shared;
namespace Titanium.Web.Proxy.Http namespace Titanium.Web.Proxy.Http
{ {
...@@ -16,8 +17,6 @@ namespace Titanium.Web.Proxy.Http ...@@ -16,8 +17,6 @@ namespace Titanium.Web.Proxy.Http
/// </summary> /// </summary>
public class HttpWebClient public class HttpWebClient
{ {
private const string CRLF = "\r\n";
internal HttpWebClient(Request request = null, Response response = null) internal HttpWebClient(Request request = null, Response response = null)
{ {
Request = request ?? new Request(); Request = request ?? new Request();
...@@ -111,9 +110,8 @@ namespace Titanium.Web.Proxy.Http ...@@ -111,9 +110,8 @@ namespace Titanium.Web.Proxy.Http
&& !string.IsNullOrEmpty(upstreamProxy.UserName) && !string.IsNullOrEmpty(upstreamProxy.UserName)
&& upstreamProxy.Password != null) && upstreamProxy.Password != null)
{ {
headerBuilder.AppendFormat("{0}{1}", HttpHeader.ProxyConnectionKeepAlive, CRLF); headerBuilder.Append($"{HttpHeader.ProxyConnectionKeepAlive}{ProxyConstants.NewLine}");
headerBuilder.AppendFormat("{0}{1}", headerBuilder.Append($"{HttpHeader.GetProxyAuthorizationHeader(upstreamProxy.UserName, upstreamProxy.Password)}{ProxyConstants.NewLine}");
HttpHeader.GetProxyAuthorizationHeader(upstreamProxy.UserName, upstreamProxy.Password), CRLF);
} }
// write request headers // write request headers
...@@ -121,11 +119,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -121,11 +119,11 @@ namespace Titanium.Web.Proxy.Http
{ {
if (isTransparent || header.Name != KnownHeaders.ProxyAuthorization) if (isTransparent || header.Name != KnownHeaders.ProxyAuthorization)
{ {
headerBuilder.AppendFormat("{0}{1}", header, CRLF); headerBuilder.Append($"{header}{ProxyConstants.NewLine}");
} }
} }
headerBuilder.Append(CRLF); headerBuilder.Append(ProxyConstants.NewLine);
await writer.WriteAsync(headerBuilder.ToString(), cancellationToken); await writer.WriteAsync(headerBuilder.ToString(), cancellationToken);
......
...@@ -140,13 +140,13 @@ namespace Titanium.Web.Proxy.Http ...@@ -140,13 +140,13 @@ namespace Titanium.Web.Proxy.Http
get get
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine(CreateRequestLine(Method, OriginalUrl, HttpVersion)); sb.Append($"{CreateRequestLine(Method, OriginalUrl, HttpVersion)}{ProxyConstants.NewLine}");
foreach (var header in Headers) foreach (var header in Headers)
{ {
sb.AppendLine(header.ToString()); sb.Append($"{header.ToString()}{ProxyConstants.NewLine}");
} }
sb.AppendLine(); sb.Append(ProxyConstants.NewLine);
return sb.ToString(); return sb.ToString();
} }
} }
......
...@@ -110,13 +110,13 @@ namespace Titanium.Web.Proxy.Http ...@@ -110,13 +110,13 @@ namespace Titanium.Web.Proxy.Http
get get
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine(CreateResponseLine(HttpVersion, StatusCode, StatusDescription)); sb.Append($"{CreateResponseLine(HttpVersion, StatusCode, StatusDescription)}{ProxyConstants.NewLine}");
foreach (var header in Headers) foreach (var header in Headers)
{ {
sb.AppendLine(header.ToString()); sb.Append($"{header.ToString()}{ProxyConstants.NewLine}");
} }
sb.AppendLine(); sb.Append(ProxyConstants.NewLine);
return sb.ToString(); return sb.ToString();
} }
} }
......
...@@ -16,6 +16,7 @@ using Titanium.Web.Proxy.Helpers; ...@@ -16,6 +16,7 @@ using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Http; using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.Network.Tcp; using Titanium.Web.Proxy.Network.Tcp;
using Titanium.Web.Proxy.Shared;
namespace Titanium.Web.Proxy namespace Titanium.Web.Proxy
{ {
...@@ -24,15 +25,6 @@ namespace Titanium.Web.Proxy ...@@ -24,15 +25,6 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public partial class ProxyServer public partial class ProxyServer
{ {
private static readonly Regex uriSchemeRegex =
new Regex("^[a-z]*://", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly HashSet<string> proxySupportedCompressions =
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"gzip",
"deflate"
};
private bool isWindowsAuthenticationEnabledAndSupported => private bool isWindowsAuthenticationEnabledAndSupported =>
EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono; EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono;
...@@ -96,7 +88,7 @@ namespace Titanium.Web.Proxy ...@@ -96,7 +88,7 @@ namespace Titanium.Web.Proxy
cancellationToken); cancellationToken);
Uri httpRemoteUri; Uri httpRemoteUri;
if (uriSchemeRegex.IsMatch(httpUrl)) if (ProxyConstants.UriSchemeRegex.IsMatch(httpUrl))
{ {
try try
{ {
...@@ -400,7 +392,7 @@ namespace Titanium.Web.Proxy ...@@ -400,7 +392,7 @@ namespace Titanium.Web.Proxy
//only allow proxy supported compressions //only allow proxy supported compressions
supportedAcceptEncoding.AddRange(acceptEncoding.Split(',') supportedAcceptEncoding.AddRange(acceptEncoding.Split(',')
.Select(x => x.Trim()) .Select(x => x.Trim())
.Where(x => proxySupportedCompressions.Contains(x))); .Where(x => ProxyConstants.ProxySupportedCompressions.Contains(x)));
//uncompressed is always supported by proxy //uncompressed is always supported by proxy
supportedAcceptEncoding.Add("identity"); supportedAcceptEncoding.Add("identity");
......
using System.Text.RegularExpressions; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Titanium.Web.Proxy.Shared namespace Titanium.Web.Proxy.Shared
{ {
...@@ -14,9 +16,20 @@ namespace Titanium.Web.Proxy.Shared ...@@ -14,9 +16,20 @@ namespace Titanium.Web.Proxy.Shared
internal static readonly char[] SemiColonSplit = { ';' }; internal static readonly char[] SemiColonSplit = { ';' };
internal static readonly char[] EqualSplit = { '=' }; internal static readonly char[] EqualSplit = { '=' };
internal static readonly byte[] NewLine = { (byte)'\r', (byte)'\n' }; internal static readonly string NewLine = "\r\n";
internal static readonly byte[] NewLineBytes = { (byte)'\r', (byte)'\n' };
public static readonly Regex CNRemoverRegex = internal static readonly Regex UriSchemeRegex =
new Regex("^[a-z]*://", RegexOptions.IgnoreCase | RegexOptions.Compiled);
internal static readonly HashSet<string> ProxySupportedCompressions =
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"gzip",
"deflate"
};
internal static readonly Regex CNRemoverRegex =
new Regex(@"^CN\s*=\s*", RegexOptions.IgnoreCase | RegexOptions.Compiled); new Regex(@"^CN\s*=\s*", RegexOptions.IgnoreCase | RegexOptions.Compiled);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment