This repository has been archived by the owner on Jul 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from justcoding121/master
stable
- Loading branch information
Showing
8 changed files
with
94 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,59 @@ | ||
using System; | ||
using Titanium.Web.Proxy.Models; | ||
|
||
namespace Titanium.Web.Proxy.Extensions | ||
{ | ||
internal static class UriExtensions | ||
{ | ||
internal static string GetOriginalPathAndQuery(this Uri uri) | ||
public static string GetOriginalPathAndQuery(this Uri uri) | ||
{ | ||
string leftPart = uri.GetLeftPart(UriPartial.Authority); | ||
if (uri.OriginalString.StartsWith(leftPart)) | ||
return uri.OriginalString.Substring(leftPart.Length); | ||
|
||
return uri.IsWellFormedOriginalString() ? uri.PathAndQuery : uri.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped); | ||
} | ||
|
||
public static ByteString GetScheme(ByteString str) | ||
{ | ||
if (str.Length < 3) | ||
{ | ||
return ByteString.Empty; | ||
} | ||
|
||
// regex: "^[a-z]*://" | ||
int i; | ||
|
||
for (i = 0; i < str.Length - 3; i++) | ||
{ | ||
byte ch = str[i]; | ||
if (ch == ':') | ||
{ | ||
break; | ||
} | ||
|
||
if (ch < 'A' || ch > 'z' || (ch > 'Z' && ch < 'a')) // ASCII letter | ||
{ | ||
return ByteString.Empty; | ||
} | ||
} | ||
|
||
if (str[i++] != ':') | ||
{ | ||
return ByteString.Empty; | ||
} | ||
|
||
if (str[i++] != '/') | ||
{ | ||
return ByteString.Empty; | ||
} | ||
|
||
if (str[i] != '/') | ||
{ | ||
return ByteString.Empty; | ||
} | ||
|
||
return new ByteString(str.Data.Slice(0, i - 2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters