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
f37e85f0
Commit
f37e85f0
authored
Jul 18, 2017
by
justcoding121
Committed by
justcoding121
Jul 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#309 upstream override
parent
b9452bfd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
15 deletions
+37
-15
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+4
-2
TunnelConnectEventArgs.cs
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
+4
-2
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+7
-1
TcpConnection.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnection.cs
+6
-0
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+8
-5
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+8
-5
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
f37e85f0
...
@@ -98,13 +98,15 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -98,13 +98,15 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Constructor to initialize the proxy
/// Constructor to initialize the proxy
/// </summary>
/// </summary>
internal
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
Func
<
SessionEventArgs
,
Task
>
httpResponseHandler
)
internal
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
IPEndPoint
upStreamEndPoint
,
Func
<
SessionEventArgs
,
Task
>
httpResponseHandler
)
{
{
this
.
bufferSize
=
bufferSize
;
this
.
bufferSize
=
bufferSize
;
this
.
httpResponseHandler
=
httpResponseHandler
;
this
.
httpResponseHandler
=
httpResponseHandler
;
ProxyClient
=
new
ProxyClient
();
ProxyClient
=
new
ProxyClient
();
WebSession
=
new
HttpWebClient
(
bufferSize
);
WebSession
=
new
HttpWebClient
(
bufferSize
,
upStreamEndPoint
);
WebSession
.
ProcessId
=
new
Lazy
<
int
>(()
=>
WebSession
.
ProcessId
=
new
Lazy
<
int
>(()
=>
{
{
...
...
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
View file @
f37e85f0
using
Titanium.Web.Proxy.Models
;
using
System.Net
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.EventArguments
namespace
Titanium.Web.Proxy.EventArguments
{
{
...
@@ -6,7 +7,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -6,7 +7,8 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
public
bool
IsHttpsConnect
{
get
;
set
;
}
public
bool
IsHttpsConnect
{
get
;
set
;
}
public
TunnelConnectSessionEventArgs
(
ProxyEndPoint
endPoint
)
:
base
(
0
,
endPoint
,
null
)
public
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
IPEndPoint
upStreamEndPoint
)
:
base
(
bufferSize
,
endPoint
,
upStreamEndPoint
,
null
)
{
{
}
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
f37e85f0
...
@@ -25,6 +25,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -25,6 +25,11 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
Guid
RequestId
{
get
;
}
public
Guid
RequestId
{
get
;
}
/// <summary>
/// Override UpStreamEndPoint for this request; Local NIC via request is made
/// </summary>
public
IPEndPoint
UpStreamEndPoint
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Headers passed with Connect.
/// Headers passed with Connect.
/// </summary>
/// </summary>
...
@@ -51,9 +56,10 @@ namespace Titanium.Web.Proxy.Http
...
@@ -51,9 +56,10 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
bool
IsHttps
=>
Request
.
IsHttps
;
public
bool
IsHttps
=>
Request
.
IsHttps
;
internal
HttpWebClient
(
int
bufferSize
)
internal
HttpWebClient
(
int
bufferSize
,
IPEndPoint
upStreamEndPoint
)
{
{
this
.
bufferSize
=
bufferSize
;
this
.
bufferSize
=
bufferSize
;
UpStreamEndPoint
=
upStreamEndPoint
;
RequestId
=
Guid
.
NewGuid
();
RequestId
=
Guid
.
NewGuid
();
Request
=
new
Request
();
Request
=
new
Request
();
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnection.cs
View file @
f37e85f0
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
System
;
using
System
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
...
@@ -25,6 +26,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -25,6 +26,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
bool
UseUpstreamProxy
{
get
;
set
;
}
internal
bool
UseUpstreamProxy
{
get
;
set
;
}
/// <summary>
/// Local NIC via connection is made
/// </summary>
internal
IPEndPoint
UpStreamEndPoint
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Http version
/// Http version
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
f37e85f0
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
System
;
using
System
;
using
System.Linq
;
using
System.Linq
;
using
System.Net
;
using
System.Net.Security
;
using
System.Net.Security
;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Text
;
using
System.Text
;
...
@@ -17,19 +18,21 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -17,19 +18,21 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
class
TcpConnectionFactory
internal
class
TcpConnectionFactory
{
{
/// <summary>
/// <summary>
/// Creates a TCP connection to server
///
Creates a TCP connection to server
/// </summary>
/// </summary>
/// <param name="server"></param>
/// <param name="server"></param>
/// <param name="remoteHostName"></param>
/// <param name="remoteHostName"></param>
/// <param name="remotePort"></param>
/// <param name="remotePort"></param>
/// <param name="httpVersion"></param>
/// <param name="httpVersion"></param>
/// <param name="isConnect"></param>
/// <param name="isHttps"></param>
/// <param name="isHttps"></param>
/// <param name="isConnect"></param>
/// <param name="upStreamEndPoint"></param>
/// <param name="externalHttpProxy"></param>
/// <param name="externalHttpProxy"></param>
/// <param name="externalHttpsProxy"></param>
/// <param name="externalHttpsProxy"></param>
/// <returns></returns>
/// <returns></returns>
internal
async
Task
<
TcpConnection
>
CreateClient
(
ProxyServer
server
,
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
internal
async
Task
<
TcpConnection
>
CreateClient
(
ProxyServer
server
,
bool
isConnect
,
ExternalProxy
externalHttpProxy
,
ExternalProxy
externalHttpsProxy
)
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
bool
isConnect
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalHttpProxy
,
ExternalProxy
externalHttpsProxy
)
{
{
bool
useUpstreamProxy
=
false
;
bool
useUpstreamProxy
=
false
;
var
externalProxy
=
isHttps
?
externalHttpsProxy
:
externalHttpProxy
;
var
externalProxy
=
isHttps
?
externalHttpsProxy
:
externalHttpProxy
;
...
@@ -52,7 +55,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -52,7 +55,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
try
try
{
{
#if NET45
#if NET45
client
=
new
TcpClient
(
server
.
UpStreamEndPoint
);
client
=
new
TcpClient
(
upStreamEndPoint
??
server
.
UpStreamEndPoint
);
#else
#else
client
=
new
TcpClient
();
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
server
.
UpStreamEndPoint
);
client
.
Client
.
Bind
(
server
.
UpStreamEndPoint
);
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
f37e85f0
...
@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
...
@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
connectRequest
.
RequestHeaders
);
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
connectRequest
.
RequestHeaders
);
var
connectArgs
=
new
TunnelConnectSessionEventArgs
(
e
ndPoint
);
var
connectArgs
=
new
TunnelConnectSessionEventArgs
(
BufferSize
,
endPoint
,
UpStreamE
ndPoint
);
connectArgs
.
WebSession
.
Request
=
connectRequest
;
connectArgs
.
WebSession
.
Request
=
connectRequest
;
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
...
@@ -293,7 +293,7 @@ namespace Titanium.Web.Proxy
...
@@ -293,7 +293,7 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
HandleHttpSessionResponse
)
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
UpStreamEndPoint
,
HandleHttpSessionResponse
)
{
{
ProxyClient
=
{
TcpClient
=
client
},
ProxyClient
=
{
TcpClient
=
client
},
WebSession
=
{
ConnectRequest
=
connectRequest
}
WebSession
=
{
ConnectRequest
=
connectRequest
}
...
@@ -354,8 +354,10 @@ namespace Titanium.Web.Proxy
...
@@ -354,8 +354,10 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
//create a new connection if hostname changes
//create a new connection if hostname/upstream end point changes
if
(
connection
!=
null
&&
!
connection
.
HostName
.
Equals
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
))
if
(
connection
!=
null
&&
(!
connection
.
HostName
.
Equals
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
)
||
args
.
WebSession
.
UpStreamEndPoint
!=
connection
.
UpStreamEndPoint
))
{
{
connection
.
Dispose
();
connection
.
Dispose
();
UpdateServerConnectionCount
(
false
);
UpdateServerConnectionCount
(
false
);
...
@@ -571,7 +573,7 @@ namespace Titanium.Web.Proxy
...
@@ -571,7 +573,7 @@ namespace Titanium.Web.Proxy
/// <param name="args"></param>
/// <param name="args"></param>
/// <param name="isConnect"></param>
/// <param name="isConnect"></param>
/// <returns></returns>
/// <returns></returns>
private
async
Task
<
TcpConnection
>
GetServerConnection
(
SessionEventArgs
args
,
bool
isConnect
)
private
async
Task
<
TcpConnection
>
GetServerConnection
(
SessionEventArgs
args
,
bool
isConnect
)
{
{
ExternalProxy
customUpStreamHttpProxy
=
null
;
ExternalProxy
customUpStreamHttpProxy
=
null
;
ExternalProxy
customUpStreamHttpsProxy
=
null
;
ExternalProxy
customUpStreamHttpsProxy
=
null
;
...
@@ -599,6 +601,7 @@ namespace Titanium.Web.Proxy
...
@@ -599,6 +601,7 @@ namespace Titanium.Web.Proxy
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
HttpVersion
,
args
.
WebSession
.
Request
.
HttpVersion
,
args
.
IsHttps
,
isConnect
,
args
.
IsHttps
,
isConnect
,
args
.
WebSession
.
UpStreamEndPoint
,
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
);
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
);
}
}
...
...
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