@@ -22,10 +22,10 @@ public class Request : RequestResponseBase
2222 /// <summary>
2323 /// Is Https?
2424 /// </summary>
25- public bool IsHttps => RequestUri.Scheme == ProxyServer.UriSchemeHttps;
25+ public bool IsHttps { get; internal set; }
2626
2727 private ByteString originalUrlData;
28- private protected ByteString UrlData ;
28+ private ByteString urlData ;
2929
3030 internal ByteString OriginalUrlData
3131 {
@@ -37,9 +37,21 @@ internal ByteString OriginalUrlData
3737 }
3838 }
3939
40- internal string Scheme { get; set; } = ProxyServer.UriSchemeHttp;
40+ private protected ByteString UrlData
41+ {
42+ get => urlData;
43+ set
44+ {
45+ urlData = value;
46+ var scheme = getUriScheme(UrlData);
47+ if (scheme.Length > 0)
48+ {
49+ IsHttps = scheme.Equals(ProxyServer.UriSchemeHttps8);
50+ }
51+ }
52+ }
4153
42- internal string? Hostname { get; set; }
54+ internal string? Authority { get; set; }
4355
4456 /// <summary>
4557 /// The original request Url.
@@ -53,21 +65,21 @@ public Uri RequestUri
5365 {
5466 get
5567 {
56- string url;
57- if (startsWithUriScheme(UrlData))
58- {
59- url = UrlData.GetString();
60- }
61- else
68+ string url = UrlData.GetString();
69+ if (getUriScheme(UrlData).Length == 0)
6270 {
63- string? host = Host ?? Hostname;
64- string? hostAndPath = host;
65- if (UrlData.Length > 0 && UrlData[0] == '/')
71+ string? hostAndPath = Host ?? Authority;
72+
73+ if (url.StartsWith("/"))
74+ {
75+ hostAndPath += url;
76+ }
77+ else
6678 {
67- hostAndPath += UrlData.GetString( );
79+ //throw new Exception($"Invalid URL: '{url}'" );
6880 }
6981
70- url = string.Concat(Scheme == ProxyServer.UriSchemeHttps ? "https://" : "http://", hostAndPath);
82+ url = string.Concat(IsHttps ? "https://" : "http://", hostAndPath);
7183 }
7284
7385 try
@@ -87,7 +99,16 @@ public Uri RequestUri
8799 public string Url
88100 {
89101 get => UrlData.GetString();
90- set => UrlData = value.GetByteString();
102+ set
103+ {
104+ UrlData = value.GetByteString();
105+
106+ if (Host != null)
107+ {
108+ var uri = new Uri(value);
109+ Host = uri.Authority;
110+ }
111+ }
91112 }
92113
93114 [Obsolete("This property is obsolete. Use Url property instead")]
@@ -147,7 +168,7 @@ public bool ExpectContinue
147168 get
148169 {
149170 string? headerValue = Headers.GetHeaderValueOrNull(KnownHeaders.Expect);
150- return headerValue != null && headerValue.Equals( KnownHeaders.Expect100Continue);
171+ return KnownHeaders.Expect100Continue.Equals(headerValue );
151172 }
152173 }
153174
@@ -290,11 +311,11 @@ private static bool isAllUpper(string input)
290311 return true;
291312 }
292313
293- private bool startsWithUriScheme (ByteString str)
314+ private ByteString getUriScheme (ByteString str)
294315 {
295316 if (str.Length < 3)
296317 {
297- return false ;
318+ return ByteString.Empty ;
298319 }
299320
300321 // regex: "^[a-z]*://"
@@ -310,26 +331,26 @@ private bool startsWithUriScheme(ByteString str)
310331
311332 if (ch < 'A' || ch > 'z' || (ch > 'Z' && ch < 'a')) // ASCII letter
312333 {
313- return false ;
334+ return ByteString.Empty ;
314335 }
315336 }
316337
317338 if (str[i++] != ':')
318339 {
319- return false ;
340+ return ByteString.Empty ;
320341 }
321342
322343 if (str[i++] != '/')
323344 {
324- return false ;
345+ return ByteString.Empty ;
325346 }
326347
327348 if (str[i] != '/')
328349 {
329- return false ;
350+ return ByteString.Empty ;
330351 }
331352
332- return true ;
353+ return new ByteString(str.Data.Slice(0, i - 2)) ;
333354 }
334355 }
335356}
0 commit comments