Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
6f57a319
Commit
6f57a319
authored
Jan 07, 2020
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
27791e02
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
57 deletions
+75
-57
ExplicitClientHandler.cs
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
+1
-1
UriExtensions.cs
src/Titanium.Web.Proxy/Extensions/UriExtensions.cs
+44
-1
HttpWebClient.cs
src/Titanium.Web.Proxy/Http/HttpWebClient.cs
+18
-1
Request.cs
src/Titanium.Web.Proxy/Http/Request.cs
+3
-45
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+1
-1
RequestHandler.cs
src/Titanium.Web.Proxy/RequestHandler.cs
+8
-8
No files found.
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
6f57a319
...
...
@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy
}
// write back successful CONNECT response
var
response
=
ConnectResponse
.
CreateSuccessfulConnectResponse
(
requestLine
.
Version
);
var
response
=
ConnectResponse
.
CreateSuccessfulConnectResponse
(
connectRequest
.
Http
Version
);
// Set ContentLength explicitly to properly handle HTTP 1.0
response
.
ContentLength
=
0
;
...
...
src/Titanium.Web.Proxy/Extensions/UriExtensions.cs
View file @
6f57a319
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
))
...
...
@@ -12,5 +13,47 @@ namespace Titanium.Web.Proxy.Extensions
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
));
}
}
}
src/Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
6f57a319
...
...
@@ -2,6 +2,7 @@
using
System.Net
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.Tcp
;
...
...
@@ -113,10 +114,21 @@ namespace Titanium.Web.Proxy.Http
string
?
upstreamProxyPassword
=
null
;
string
url
;
if
(
!
useUpstreamProxy
||
isTransparent
)
if
(
isTransparent
)
{
url
=
Request
.
RequestUriString
;
}
else
if
(!
useUpstreamProxy
)
{
if
(
UriExtensions
.
GetScheme
(
Request
.
RequestUriString8
).
Length
==
0
)
{
url
=
Request
.
RequestUriString
;
}
else
{
url
=
Request
.
RequestUri
.
GetOriginalPathAndQuery
();
}
}
else
{
url
=
Request
.
RequestUri
.
ToString
();
...
...
@@ -129,6 +141,11 @@ namespace Titanium.Web.Proxy.Http
}
}
if
(
url
==
string
.
Empty
)
{
url
=
"/"
;
}
// prepare the request & headers
var
headerBuilder
=
new
HeaderBuilder
();
headerBuilder
.
WriteRequestLine
(
Request
.
Method
,
url
,
Request
.
HttpVersion
);
...
...
src/Titanium.Web.Proxy/Http/Request.cs
View file @
6f57a319
...
...
@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Http
set
{
requestUriString8
=
value
;
var
scheme
=
getUri
Scheme
(
value
);
var
scheme
=
UriExtensions
.
Get
Scheme
(
value
);
if
(
scheme
.
Length
>
0
)
{
IsHttps
=
scheme
.
Equals
(
ProxyServer
.
UriSchemeHttps8
);
...
...
@@ -71,7 +71,7 @@ namespace Titanium.Web.Proxy.Http
get
{
string
url
=
RequestUriString8
.
GetString
();
if
(
getUri
Scheme
(
RequestUriString8
).
Length
==
0
)
if
(
UriExtensions
.
Get
Scheme
(
RequestUriString8
).
Length
==
0
)
{
string
?
hostAndPath
=
Host
??
Authority
.
GetString
();
...
...
@@ -105,7 +105,7 @@ namespace Titanium.Web.Proxy.Http
{
RequestUriString8
=
(
ByteString
)
value
;
var
scheme
=
getUri
Scheme
(
RequestUriString8
);
var
scheme
=
UriExtensions
.
Get
Scheme
(
RequestUriString8
);
if
(
scheme
.
Length
>
0
&&
Host
!=
null
)
{
var
uri
=
new
Uri
(
value
);
...
...
@@ -307,47 +307,5 @@ namespace Titanium.Web.Proxy.Http
return
true
;
}
private
ByteString
getUriScheme
(
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
));
}
}
}
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
6f57a319
...
...
@@ -439,7 +439,7 @@ namespace Titanium.Web.Proxy
if
(
systemProxySettingsManager
==
null
)
{
throw
new
NotSupportedException
(
@"Setting system proxy settings are only supported in Windows.
Please manually conf
u
gure you operating system to use this proxy's port and address."
);
Please manually conf
i
gure you operating system to use this proxy's port and address."
);
}
validateEndPointAsSystemProxy
(
endPoint
);
...
...
src/Titanium.Web.Proxy/RequestHandler.cs
View file @
6f57a319
...
...
@@ -68,9 +68,10 @@ namespace Titanium.Web.Proxy
UserData
=
connectArgs
?.
UserData
};
var
request
=
args
.
HttpClient
.
Request
;
if
(
isHttps
)
{
args
.
HttpClient
.
R
equest
.
IsHttps
=
true
;
r
equest
.
IsHttps
=
true
;
}
try
...
...
@@ -81,7 +82,6 @@ namespace Titanium.Web.Proxy
await
HeaderParser
.
ReadHeaders
(
clientStream
,
args
.
HttpClient
.
Request
.
Headers
,
cancellationToken
);
var
request
=
args
.
HttpClient
.
Request
;
if
(
connectRequest
!=
null
)
{
request
.
IsHttps
=
connectRequest
.
IsHttps
;
...
...
@@ -93,6 +93,12 @@ namespace Titanium.Web.Proxy
request
.
Method
=
requestLine
.
Method
;
request
.
HttpVersion
=
requestLine
.
Version
;
// we need this to syphon out data from connection if API user changes them.
request
.
SetOriginalHeaders
();
// If user requested interception do it
await
onBeforeRequest
(
args
);
if
(!
args
.
IsTransparent
&&
!
args
.
IsSocks
)
{
// proxy authorization check
...
...
@@ -117,12 +123,6 @@ namespace Titanium.Web.Proxy
await
args
.
GetRequestBody
(
cancellationToken
);
}
// we need this to syphon out data from connection if API user changes them.
request
.
SetOriginalHeaders
();
// If user requested interception do it
await
onBeforeRequest
(
args
);
var
response
=
args
.
HttpClient
.
Response
;
if
(
request
.
CancelRequest
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment