55using System . Net . Security ;
66using System . Net . Sockets ;
77using System . Security . Authentication ;
8+ using System . Text . RegularExpressions ;
89using System . Threading . Tasks ;
910using StreamExtended ;
1011using StreamExtended . Helpers ;
1516using Titanium . Web . Proxy . Helpers ;
1617using Titanium . Web . Proxy . Http ;
1718using Titanium . Web . Proxy . Models ;
18- using Titanium . Web . Proxy . Network ;
1919using Titanium . Web . Proxy . Network . Tcp ;
2020
2121namespace 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