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
bbd6f9b5
Commit
bbd6f9b5
authored
May 01, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redundant parameter removed
parent
5f65f4d7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
34 deletions
+31
-34
LimitedStream.cs
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
+1
-1
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+9
-9
SessionEventArgsBase.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
+2
-2
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+2
-3
TcpExtensions.cs
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
+4
-4
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+11
-13
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+2
-2
No files found.
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
View file @
bbd6f9b5
...
@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
bytesRemaining
=
-
1
;
bytesRemaining
=
-
1
;
//chunk trail
//
chunk trail
baseStream
.
ReadLineAsync
().
Wait
();
baseStream
.
ReadLineAsync
().
Wait
();
}
}
}
}
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
bbd6f9b5
...
@@ -88,14 +88,14 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -88,14 +88,14 @@ namespace Titanium.Web.Proxy.EventArguments
var
request
=
WebSession
.
Request
;
var
request
=
WebSession
.
Request
;
//If not already read (not cached yet)
//
If not already read (not cached yet)
if
(!
request
.
IsBodyRead
)
if
(!
request
.
IsBodyRead
)
{
{
var
body
=
await
ReadBodyAsync
(
true
,
cancellationToken
);
var
body
=
await
ReadBodyAsync
(
true
,
cancellationToken
);
request
.
Body
=
body
;
request
.
Body
=
body
;
//Now set the flag to true
//
Now set the flag to true
//So that next time we can deliver body from cache
//
So that next time we can deliver body from cache
request
.
IsBodyRead
=
true
;
request
.
IsBodyRead
=
true
;
OnDataSent
(
body
,
0
,
body
.
Length
);
OnDataSent
(
body
,
0
,
body
.
Length
);
}
}
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
internal
async
Task
ClearResponse
(
CancellationToken
cancellationToken
)
internal
async
Task
ClearResponse
(
CancellationToken
cancellationToken
)
{
{
//syphon out the response body from server
//
syphon out the response body from server
await
SyphonOutBodyAsync
(
false
,
cancellationToken
);
await
SyphonOutBodyAsync
(
false
,
cancellationToken
);
WebSession
.
Response
=
new
Response
();
WebSession
.
Response
=
new
Response
();
}
}
...
@@ -139,14 +139,14 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -139,14 +139,14 @@ namespace Titanium.Web.Proxy.EventArguments
return
;
return
;
}
}
//If not already read (not cached yet)
//
If not already read (not cached yet)
if
(!
response
.
IsBodyRead
)
if
(!
response
.
IsBodyRead
)
{
{
var
body
=
await
ReadBodyAsync
(
false
,
cancellationToken
);
var
body
=
await
ReadBodyAsync
(
false
,
cancellationToken
);
response
.
Body
=
body
;
response
.
Body
=
body
;
//Now set the flag to true
//
Now set the flag to true
//So that next time we can deliver body from cache
//
So that next time we can deliver body from cache
response
.
IsBodyRead
=
true
;
response
.
IsBodyRead
=
true
;
OnDataReceived
(
body
,
0
,
body
.
Length
);
OnDataReceived
(
body
,
0
,
body
.
Length
);
}
}
...
@@ -196,7 +196,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -196,7 +196,7 @@ namespace Titanium.Web.Proxy.EventArguments
long
contentLength
=
request
.
ContentLength
;
long
contentLength
=
request
.
ContentLength
;
//send the request body bytes to server
//
send the request body bytes to server
if
(
contentLength
>
0
&&
hasMulipartEventSubscribers
&&
request
.
IsMultipartFormData
)
if
(
contentLength
>
0
&&
hasMulipartEventSubscribers
&&
request
.
IsMultipartFormData
)
{
{
var
reader
=
GetStreamReader
(
true
);
var
reader
=
GetStreamReader
(
true
);
...
@@ -323,7 +323,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -323,7 +323,7 @@ namespace Titanium.Web.Proxy.EventArguments
if
(
bufferDataLength
==
buffer
.
Length
)
if
(
bufferDataLength
==
buffer
.
Length
)
{
{
//boundary is not longer than 70 bytes according to the specification, so keeping the last 100 (minimum 74) bytes is enough
//
boundary is not longer than 70 bytes according to the specification, so keeping the last 100 (minimum 74) bytes is enough
const
int
bytesToKeep
=
100
;
const
int
bytesToKeep
=
100
;
Buffer
.
BlockCopy
(
buffer
,
buffer
.
Length
-
bytesToKeep
,
buffer
,
0
,
bytesToKeep
);
Buffer
.
BlockCopy
(
buffer
,
buffer
.
Length
-
bytesToKeep
,
buffer
,
0
,
bytesToKeep
);
bufferDataLength
=
bytesToKeep
;
bufferDataLength
=
bytesToKeep
;
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
View file @
bbd6f9b5
...
@@ -53,14 +53,14 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -53,14 +53,14 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
var
remoteEndPoint
=
ClientEndPoint
;
var
remoteEndPoint
=
ClientEndPoint
;
//If client is localhost get the process id
//
If client is localhost get the process id
if
(
NetworkHelper
.
IsLocalIpAddress
(
remoteEndPoint
.
Address
))
if
(
NetworkHelper
.
IsLocalIpAddress
(
remoteEndPoint
.
Address
))
{
{
var
ipVersion
=
endPoint
.
IpV6Enabled
?
IpVersion
.
Ipv6
:
IpVersion
.
Ipv4
;
var
ipVersion
=
endPoint
.
IpV6Enabled
?
IpVersion
.
Ipv6
:
IpVersion
.
Ipv4
;
return
TcpHelper
.
GetProcessIdByLocalPort
(
ipVersion
,
remoteEndPoint
.
Port
);
return
TcpHelper
.
GetProcessIdByLocalPort
(
ipVersion
,
remoteEndPoint
.
Port
);
}
}
//can't access process Id of remote request from remote machine
//
can't access process Id of remote request from remote machine
return
-
1
;
return
-
1
;
}
}
...
...
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
bbd6f9b5
...
@@ -277,9 +277,8 @@ namespace Titanium.Web.Proxy
...
@@ -277,9 +277,8 @@ namespace Titanium.Web.Proxy
}
}
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
await
HandleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
clientStreamWriter
,
clientStreamWriter
,
cancellationTokenSource
,
connectHostname
,
cancellationTokenSource
,
connectHostname
,
connectArgs
?.
WebSession
.
ConnectRequest
);
connectArgs
?.
WebSession
.
ConnectRequest
);
}
}
catch
(
ProxyException
e
)
catch
(
ProxyException
e
)
{
{
...
...
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
View file @
bbd6f9b5
...
@@ -31,10 +31,10 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -31,10 +31,10 @@ namespace Titanium.Web.Proxy.Extensions
try
try
{
{
//This line is important!
//
This line is important!
//contributors please don't remove it without discussion
//
contributors please don't remove it without discussion
//It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//
It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//due to default TCP CLOSE_WAIT timeout for 4 minutes
//
due to default TCP CLOSE_WAIT timeout for 4 minutes
if
(
socketCleanedUpGetter
==
null
||
!
socketCleanedUpGetter
(
tcpClient
.
Client
))
if
(
socketCleanedUpGetter
==
null
||
!
socketCleanedUpGetter
(
tcpClient
.
Client
))
{
{
tcpClient
.
LingerState
=
new
LingerOption
(
true
,
0
);
tcpClient
.
LingerState
=
new
LingerOption
(
true
,
0
);
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
bbd6f9b5
...
@@ -44,8 +44,7 @@ namespace Titanium.Web.Proxy
...
@@ -44,8 +44,7 @@ namespace Titanium.Web.Proxy
/// <returns></returns>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClientConnection
clientConnection
,
private
async
Task
HandleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClientConnection
clientConnection
,
CustomBufferedStream
clientStream
,
HttpResponseWriter
clientStreamWriter
,
CustomBufferedStream
clientStream
,
HttpResponseWriter
clientStreamWriter
,
CancellationTokenSource
cancellationTokenSource
,
string
httpsConnectHostname
,
ConnectRequest
connectRequest
,
CancellationTokenSource
cancellationTokenSource
,
string
httpsConnectHostname
,
ConnectRequest
connectRequest
)
bool
isTransparentEndPoint
=
false
)
{
{
var
cancellationToken
=
cancellationTokenSource
.
Token
;
var
cancellationToken
=
cancellationTokenSource
.
Token
;
TcpServerConnection
serverConnection
=
null
;
TcpServerConnection
serverConnection
=
null
;
...
@@ -123,20 +122,19 @@ namespace Titanium.Web.Proxy
...
@@ -123,20 +122,19 @@ namespace Titanium.Web.Proxy
args
.
ProxyClient
.
ClientStream
=
clientStream
;
args
.
ProxyClient
.
ClientStream
=
clientStream
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
//proxy authorization check
if
(!
args
.
IsTransparent
)
if
(!
args
.
IsTransparent
&&
httpsConnectHostname
==
null
&&
await
CheckAuthorization
(
args
)
==
false
)
{
{
await
InvokeBeforeResponse
(
args
);
//proxy authorization check
if
(
httpsConnectHostname
==
null
&&
await
CheckAuthorization
(
args
)
==
false
)
{
await
InvokeBeforeResponse
(
args
);
//send the response
//send the response
await
clientStreamWriter
.
WriteResponseAsync
(
args
.
WebSession
.
Response
,
await
clientStreamWriter
.
WriteResponseAsync
(
args
.
WebSession
.
Response
,
cancellationToken
:
cancellationToken
);
cancellationToken
:
cancellationToken
);
return
;
return
;
}
}
if
(!
isTransparentEndPoint
)
{
PrepareRequestHeaders
(
request
.
Headers
);
PrepareRequestHeaders
(
request
.
Headers
);
request
.
Host
=
request
.
RequestUri
.
Authority
;
request
.
Host
=
request
.
RequestUri
.
Authority
;
}
}
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
bbd6f9b5
...
@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
...
@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
int
available
=
clientStream
.
Available
;
int
available
=
clientStream
.
Available
;
if
(
available
>
0
)
if
(
available
>
0
)
{
{
//send the buffered data
//
send the buffered data
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
try
try
...
@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy
...
@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy
//HTTPS server created - we can now decrypt the client's traffic
//HTTPS server created - we can now decrypt the client's traffic
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
clientStreamWriter
,
await
HandleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
clientStreamWriter
,
cancellationTokenSource
,
isHttps
?
httpsHostName
:
null
,
null
,
true
);
cancellationTokenSource
,
isHttps
?
httpsHostName
:
null
,
null
);
}
}
catch
(
ProxyException
e
)
catch
(
ProxyException
e
)
{
{
...
...
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