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

Commit f560e29

Browse files
authored
Merge pull request #366 from justcoding121/develop
Request Url fix
2 parents 603223a + d154f42 commit f560e29

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net.Security;
66
using System.Net.Sockets;
77
using System.Security.Authentication;
8+
using System.Text.RegularExpressions;
89
using System.Threading.Tasks;
910
using StreamExtended;
1011
using StreamExtended.Helpers;
@@ -15,7 +16,6 @@
1516
using Titanium.Web.Proxy.Helpers;
1617
using Titanium.Web.Proxy.Http;
1718
using Titanium.Web.Proxy.Models;
18-
using Titanium.Web.Proxy.Network;
1919
using Titanium.Web.Proxy.Network.Tcp;
2020

2121
namespace Titanium.Web.Proxy
@@ -25,6 +25,8 @@ namespace Titanium.Web.Proxy
2525
/// </summary>
2626
partial class ProxyServer
2727
{
28+
private static readonly Regex uriSchemeRegex = new Regex("^[a-z]*://", RegexOptions.IgnoreCase | RegexOptions.Compiled);
29+
2830
private bool isWindowsAuthenticationEnabledAndSupported => EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono;
2931

3032
/// <summary>
@@ -360,9 +362,22 @@ private async Task<bool> HandleHttpSessionRequest(TcpClient client, string httpC
360362
//Read the request headers in to unique and non-unique header collections
361363
await HeaderParser.ReadHeaders(clientStreamReader, args.WebSession.Request.Headers);
362364

363-
var httpRemoteUri = new Uri(httpsConnectHostname == null
364-
? isTransparentEndPoint ? string.Concat("http://", args.WebSession.Request.Host, httpUrl) : httpUrl
365-
: string.Concat("https://", args.WebSession.Request.Host ?? httpsConnectHostname, httpUrl));
365+
Uri httpRemoteUri;
366+
if (uriSchemeRegex.IsMatch(httpUrl))
367+
{
368+
httpRemoteUri = new Uri(httpUrl);
369+
}
370+
else
371+
{
372+
string host = args.WebSession.Request.Host ?? httpsConnectHostname;
373+
string hostAndPath = host;
374+
if (httpUrl.StartsWith("/"))
375+
{
376+
hostAndPath += httpUrl;
377+
}
378+
379+
httpRemoteUri = new Uri(string.Concat(httpsConnectHostname == null ? "http://" : "https://", hostAndPath));
380+
}
366381

367382
args.WebSession.Request.RequestUri = httpRemoteUri;
368383
args.WebSession.Request.OriginalUrl = httpUrl;

0 commit comments

Comments
 (0)