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
3d6e72a0
Commit
3d6e72a0
authored
Nov 16, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
1b0bfecd
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
93 additions
and
60 deletions
+93
-60
CompressionUtil.cs
src/Titanium.Web.Proxy/Compression/CompressionUtil.cs
+3
-3
ExplicitClientHandler.cs
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
+9
-10
ConnectRequest.cs
src/Titanium.Web.Proxy/Http/ConnectRequest.cs
+2
-2
HttpWebClient.cs
src/Titanium.Web.Proxy/Http/HttpWebClient.cs
+4
-0
Request.cs
src/Titanium.Web.Proxy/Http/Request.cs
+45
-24
Http2Helper.cs
src/Titanium.Web.Proxy/Http2/Http2Helper.cs
+7
-10
ExplicitProxyEndPoint.cs
src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs
+3
-1
TransparentProxyEndPoint.cs
src/Titanium.Web.Proxy/Models/TransparentProxyEndPoint.cs
+3
-1
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+10
-6
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+4
-0
RequestHandler.cs
src/Titanium.Web.Proxy/RequestHandler.cs
+2
-2
HttpContinueClient.cs
....Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs
+1
-1
No files found.
src/Titanium.Web.Proxy/Compression/CompressionUtil.cs
View file @
3d6e72a0
...
...
@@ -7,13 +7,13 @@ namespace Titanium.Web.Proxy.Compression
{
public
static
HttpCompression
CompressionNameToEnum
(
string
name
)
{
if
(
KnownHeaders
.
ContentEncodingGzip
.
Equals
(
name
.
AsSpan
()
))
if
(
KnownHeaders
.
ContentEncodingGzip
.
Equals
(
name
))
return
HttpCompression
.
Gzip
;
if
(
KnownHeaders
.
ContentEncodingDeflate
.
Equals
(
name
.
AsSpan
()
))
if
(
KnownHeaders
.
ContentEncodingDeflate
.
Equals
(
name
))
return
HttpCompression
.
Deflate
;
if
(
KnownHeaders
.
ContentEncodingBrotli
.
Equals
(
name
.
AsSpan
()
))
if
(
KnownHeaders
.
ContentEncodingBrotli
.
Equals
(
name
))
return
HttpCompression
.
Brotli
;
return
HttpCompression
.
Unsupported
;
...
...
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
3d6e72a0
...
...
@@ -47,7 +47,6 @@ namespace Titanium.Web.Proxy
try
{
string
?
connectHostname
=
null
;
TunnelConnectSessionEventArgs
?
connectArgs
=
null
;
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
...
...
@@ -62,14 +61,7 @@ namespace Titanium.Web.Proxy
Request
.
ParseRequestLine
(
httpCmd
!,
out
string
_
,
out
string
httpUrl
,
out
var
version
);
connectHostname
=
httpUrl
;
int
idx
=
connectHostname
.
IndexOf
(
":"
);
if
(
idx
>=
0
)
{
connectHostname
=
connectHostname
.
Substring
(
0
,
idx
);
}
var
connectRequest
=
new
ConnectRequest
(
connectHostname
)
var
connectRequest
=
new
ConnectRequest
(
httpUrl
)
{
OriginalUrlData
=
HttpHeader
.
Encoding
.
GetBytes
(
httpUrl
),
HttpVersion
=
version
...
...
@@ -130,7 +122,7 @@ namespace Titanium.Web.Proxy
bool
isClientHello
=
clientHelloInfo
!=
null
;
if
(
clientHelloInfo
!=
null
)
{
connectRequest
.
Scheme
=
ProxyServer
.
UriSchemeHttps
;
connectRequest
.
IsHttps
=
true
;
connectRequest
.
TunnelType
=
TunnelType
.
Https
;
connectRequest
.
ClientHelloInfo
=
clientHelloInfo
;
}
...
...
@@ -186,6 +178,13 @@ namespace Titanium.Web.Proxy
}
}
string
connectHostname
=
httpUrl
;
int
idx
=
connectHostname
.
IndexOf
(
":"
);
if
(
idx
>=
0
)
{
connectHostname
=
connectHostname
.
Substring
(
0
,
idx
);
}
X509Certificate2
?
certificate
=
null
;
try
{
...
...
src/Titanium.Web.Proxy/Http/ConnectRequest.cs
View file @
3d6e72a0
...
...
@@ -9,10 +9,10 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public
class
ConnectRequest
:
Request
{
public
ConnectRequest
(
string
hostname
)
public
ConnectRequest
(
string
authority
)
{
Method
=
"CONNECT"
;
Hostname
=
hostname
;
Authority
=
authority
;
}
public
TunnelType
TunnelType
{
get
;
internal
set
;
}
...
...
src/Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
3d6e72a0
...
...
@@ -121,6 +121,10 @@ namespace Titanium.Web.Proxy.Http
else
{
url
=
Request
.
RequestUri
.
GetOriginalPathAndQuery
();
if
(
url
==
string
.
Empty
)
{
url
=
"/"
;
}
}
var
headerBuilder
=
new
HeaderBuilder
();
...
...
src/Titanium.Web.Proxy/Http/Request.cs
View file @
3d6e72a0
...
...
@@ -22,10 +22,10 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Is Https?
/// </summary>
public
bool
IsHttps
=>
RequestUri
.
Scheme
==
ProxyServer
.
UriSchemeHttps
;
public
bool
IsHttps
{
get
;
internal
set
;
}
private
ByteString
originalUrlData
;
private
protected
ByteString
U
rlData
;
private
ByteString
u
rlData
;
internal
ByteString
OriginalUrlData
{
...
...
@@ -37,9 +37,21 @@ namespace Titanium.Web.Proxy.Http
}
}
internal
string
Scheme
{
get
;
set
;
}
=
ProxyServer
.
UriSchemeHttp
;
private
protected
ByteString
UrlData
{
get
=>
urlData
;
set
{
urlData
=
value
;
var
scheme
=
getUriScheme
(
UrlData
);
if
(
scheme
.
Length
>
0
)
{
IsHttps
=
scheme
.
Equals
(
ProxyServer
.
UriSchemeHttps8
);
}
}
}
internal
string
?
Hostname
{
get
;
set
;
}
internal
string
?
Authority
{
get
;
set
;
}
/// <summary>
/// The original request Url.
...
...
@@ -53,21 +65,21 @@ namespace Titanium.Web.Proxy.Http
{
get
{
string
url
;
if
(
startsWithUriScheme
(
UrlData
))
{
url
=
UrlData
.
GetString
();
}
else
string
url
=
UrlData
.
GetString
();
if
(
getUriScheme
(
UrlData
).
Length
==
0
)
{
string
?
host
=
Host
??
Hostname
;
string
?
hostAndPath
=
host
;
if
(
UrlData
.
Length
>
0
&&
UrlData
[
0
]
==
'/'
)
string
?
hostAndPath
=
Host
??
Authority
;
if
(
url
.
StartsWith
(
"/"
))
{
hostAndPath
+=
url
;
}
else
{
hostAndPath
+=
UrlData
.
GetString
(
);
//throw new Exception($"Invalid URL: '{url}'"
);
}
url
=
string
.
Concat
(
Scheme
==
ProxyServer
.
UriScheme
Https
?
"https://"
:
"http://"
,
hostAndPath
);
url
=
string
.
Concat
(
Is
Https
?
"https://"
:
"http://"
,
hostAndPath
);
}
try
...
...
@@ -87,7 +99,16 @@ namespace Titanium.Web.Proxy.Http
public
string
Url
{
get
=>
UrlData
.
GetString
();
set
=>
UrlData
=
value
.
GetByteString
();
set
{
UrlData
=
value
.
GetByteString
();
if
(
Host
!=
null
)
{
var
uri
=
new
Uri
(
value
);
Host
=
uri
.
Authority
;
}
}
}
[
Obsolete
(
"This property is obsolete. Use Url property instead"
)]
...
...
@@ -147,7 +168,7 @@ namespace Titanium.Web.Proxy.Http
get
{
string
?
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
Expect
);
return
headerValue
!=
null
&&
headerValue
.
Equals
(
KnownHeaders
.
Expect100Contin
ue
);
return
KnownHeaders
.
Expect100Continue
.
Equals
(
headerVal
ue
);
}
}
...
...
@@ -290,11 +311,11 @@ namespace Titanium.Web.Proxy.Http
return
true
;
}
private
bool
startsWith
UriScheme
(
ByteString
str
)
private
ByteString
get
UriScheme
(
ByteString
str
)
{
if
(
str
.
Length
<
3
)
{
return
false
;
return
ByteString
.
Empty
;
}
// regex: "^[a-z]*://"
...
...
@@ -310,26 +331,26 @@ namespace Titanium.Web.Proxy.Http
if
(
ch
<
'A'
||
ch
>
'z'
||
(
ch
>
'Z'
&&
ch
<
'a'
))
// ASCII letter
{
return
false
;
return
ByteString
.
Empty
;
}
}
if
(
str
[
i
++]
!=
':'
)
{
return
false
;
return
ByteString
.
Empty
;
}
if
(
str
[
i
++]
!=
'/'
)
{
return
false
;
return
ByteString
.
Empty
;
}
if
(
str
[
i
]
!=
'/'
)
{
return
false
;
return
ByteString
.
Empty
;
}
return
true
;
return
new
ByteString
(
str
.
Data
.
Slice
(
0
,
i
-
2
))
;
}
}
}
src/Titanium.Web.Proxy/Http2/Http2Helper.cs
View file @
3d6e72a0
...
...
@@ -263,9 +263,9 @@ namespace Titanium.Web.Proxy.Http2
request
.
HttpVersion
=
HttpVersion
.
Version20
;
request
.
Method
=
method
.
GetString
();
request
.
IsHttps
=
headerListener
.
Scheme
==
ProxyServer
.
UriSchemeHttps
;
request
.
Authority
=
headerListener
.
Authority
.
GetString
();
request
.
OriginalUrlData
=
path
;
request
.
Scheme
=
headerListener
.
Scheme
;
request
.
Hostname
=
headerListener
.
Authority
.
GetString
();
//request.RequestUri = headerListener.GetUri();
}
...
...
@@ -468,9 +468,10 @@ namespace Titanium.Web.Proxy.Http2
if
(
rr
is
Request
request
)
{
var
uri
=
request
.
RequestUri
;
encoder
.
EncodeHeader
(
writer
,
StaticTable
.
KnownHeaderMethod
,
request
.
Method
.
GetByteString
());
encoder
.
EncodeHeader
(
writer
,
StaticTable
.
KnownHeaderAuhtority
,
request
.
RequestUri
.
Host
.
GetByteString
());
encoder
.
EncodeHeader
(
writer
,
StaticTable
.
KnownHeaderScheme
,
request
.
RequestU
ri
.
Scheme
.
GetByteString
());
encoder
.
EncodeHeader
(
writer
,
StaticTable
.
KnownHeaderAuhtority
,
uri
.
Authority
.
GetByteString
());
encoder
.
EncodeHeader
(
writer
,
StaticTable
.
KnownHeaderScheme
,
u
ri
.
Scheme
.
GetByteString
());
encoder
.
EncodeHeader
(
writer
,
StaticTable
.
KnownHeaderPath
,
request
.
Url
.
GetByteString
(),
false
,
HpackUtil
.
IndexType
.
None
,
false
);
}
...
...
@@ -572,10 +573,6 @@ namespace Titanium.Web.Proxy.Http2
class
MyHeaderListener
:
IHeaderListener
{
private
static
ByteString
SchemeHttp
=
(
ByteString
)
ProxyServer
.
UriSchemeHttp
;
private
static
ByteString
SchemeHttps
=
(
ByteString
)
ProxyServer
.
UriSchemeHttps
;
private
readonly
Action
<
ByteString
,
ByteString
>
addHeaderFunc
;
public
ByteString
Method
{
get
;
private
set
;
}
...
...
@@ -592,12 +589,12 @@ namespace Titanium.Web.Proxy.Http2
{
get
{
if
(
scheme
.
Equals
(
SchemeHttp
))
if
(
scheme
.
Equals
(
ProxyServer
.
UriSchemeHttp8
))
{
return
ProxyServer
.
UriSchemeHttp
;
}
if
(
scheme
.
Equals
(
SchemeHttps
))
if
(
scheme
.
Equals
(
ProxyServer
.
UriSchemeHttps8
))
{
return
ProxyServer
.
UriSchemeHttps
;
}
...
...
src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs
View file @
3d6e72a0
using
System.Net
;
using
System.Diagnostics
;
using
System.Net
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
...
...
@@ -9,6 +10,7 @@ namespace Titanium.Web.Proxy.Models
/// A proxy endpoint that the client is aware of.
/// So client application know that it is communicating with a proxy server.
/// </summary>
[
DebuggerDisplay
(
"Explicit: {IpAddress}:{Port}"
)]
public
class
ExplicitProxyEndPoint
:
ProxyEndPoint
{
/// <summary>
...
...
src/Titanium.Web.Proxy/Models/TransparentProxyEndPoint.cs
View file @
3d6e72a0
using
System.Net
;
using
System.Diagnostics
;
using
System.Net
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
...
...
@@ -9,6 +10,7 @@ namespace Titanium.Web.Proxy.Models
/// A proxy end point client is not aware of.
/// Useful when requests are redirected to this proxy end point through port forwarding via router.
/// </summary>
[
DebuggerDisplay
(
"Explicit: {IpAddress}:{Port}"
)]
public
class
TransparentProxyEndPoint
:
ProxyEndPoint
{
/// <summary>
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
3d6e72a0
...
...
@@ -125,9 +125,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
session
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
var
uri
=
session
.
HttpClient
.
Request
.
RequestUri
;
return
GetConnectionCacheKey
(
session
.
HttpClient
.
Request
.
RequestU
ri
.
Host
,
session
.
HttpClient
.
Request
.
RequestU
ri
.
Port
,
u
ri
.
Host
,
u
ri
.
Port
,
isHttps
,
applicationProtocols
,
session
.
HttpClient
.
UpStreamEndPoint
??
server
.
UpStreamEndPoint
,
customUpStreamProxy
??
(
isHttps
?
server
.
UpStreamHttpsProxy
:
server
.
UpStreamHttpProxy
));
...
...
@@ -179,9 +180,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
session
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
var
uri
=
session
.
HttpClient
.
Request
.
RequestUri
;
return
await
GetServerConnection
(
session
.
HttpClient
.
Request
.
RequestU
ri
.
Host
,
session
.
HttpClient
.
Request
.
RequestU
ri
.
Port
,
u
ri
.
Host
,
u
ri
.
Port
,
session
.
HttpClient
.
Request
.
HttpVersion
,
isHttps
,
applicationProtocols
,
isConnect
,
server
,
session
,
session
.
HttpClient
.
UpStreamEndPoint
??
server
.
UpStreamEndPoint
,
...
...
@@ -372,9 +374,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
{
var
writer
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
BufferPool
);
var
connectRequest
=
new
ConnectRequest
(
remoteHostName
)
string
authority
=
$"
{
remoteHostName
}
:
{
remotePort
}
"
;
var
connectRequest
=
new
ConnectRequest
(
authority
)
{
OriginalUrlData
=
HttpHeader
.
Encoding
.
GetBytes
(
$"
{
remoteHostName
}
:
{
remotePort
}
"
),
IsHttps
=
isHttps
,
OriginalUrlData
=
HttpHeader
.
Encoding
.
GetBytes
(
authority
),
HttpVersion
=
httpVersion
};
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
3d6e72a0
...
...
@@ -32,6 +32,10 @@ namespace Titanium.Web.Proxy
internal
static
readonly
string
UriSchemeHttp
=
Uri
.
UriSchemeHttp
;
internal
static
readonly
string
UriSchemeHttps
=
Uri
.
UriSchemeHttps
;
internal
static
ByteString
UriSchemeHttp8
=
(
ByteString
)
UriSchemeHttp
;
internal
static
ByteString
UriSchemeHttps8
=
(
ByteString
)
UriSchemeHttps
;
/// <summary>
/// A default exception log func.
/// </summary>
...
...
src/Titanium.Web.Proxy/RequestHandler.cs
View file @
3d6e72a0
...
...
@@ -84,8 +84,8 @@ namespace Titanium.Web.Proxy
var
request
=
args
.
HttpClient
.
Request
;
if
(
connectRequest
!=
null
)
{
request
.
Scheme
=
connectRequest
.
Scheme
;
request
.
Hostname
=
connectRequest
.
Hostname
;
request
.
IsHttps
=
connectRequest
.
IsHttps
;
request
.
Authority
=
connectRequest
.
Authority
;
}
request
.
OriginalUrlData
=
HttpHeader
.
Encoding
.
GetBytes
(
httpUrl
);
...
...
tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpContinueClient.cs
View file @
3d6e72a0
...
...
@@ -34,7 +34,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
var
buffer
=
new
byte
[
1024
];
var
responseMsg
=
string
.
Empty
;
Response
response
=
null
;
Response
response
;
while
((
response
=
HttpMessageParsing
.
ParseResponse
(
responseMsg
))
==
null
)
{
...
...
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