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
ef2dbb18
Commit
ef2dbb18
authored
Jul 10, 2015
by
justcoding121
Committed by
justcoding121
Jul 10, 2015
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9 from titanium007/breaking-change
Use Async for each session
parents
2c8fdcf8
1a83e59b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
186 additions
and
224 deletions
+186
-224
SessionEventArgs.cs
Titanium.Web.Proxy/Models/SessionEventArgs.cs
+13
-4
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+10
-49
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+135
-159
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+28
-12
No files found.
Titanium.Web.Proxy/Models/SessionEventArgs.cs
View file @
ef2dbb18
...
@@ -33,8 +33,9 @@ namespace Titanium.Web.Proxy.Models
...
@@ -33,8 +33,9 @@ namespace Titanium.Web.Proxy.Models
internal
Stream
ClientStream
{
get
;
set
;
}
internal
Stream
ClientStream
{
get
;
set
;
}
internal
Stream
ServerResponseStream
{
get
;
set
;
}
internal
Stream
ServerResponseStream
{
get
;
set
;
}
internal
Encoding
Encoding
{
get
;
set
;
}
internal
Encoding
Encoding
{
get
;
set
;
}
internal
bool
WasModified
{
get
;
set
;
}
internal
bool
RequestWasModified
{
get
;
set
;
}
internal
System
.
Threading
.
ManualResetEvent
FinishedRequestEvent
{
get
;
set
;
}
internal
bool
ResponseWasModified
{
get
;
set
;
}
internal
string
UpgradeProtocol
{
get
;
set
;
}
internal
string
UpgradeProtocol
{
get
;
set
;
}
...
@@ -64,11 +65,13 @@ namespace Titanium.Web.Proxy.Models
...
@@ -64,11 +65,13 @@ namespace Titanium.Web.Proxy.Models
mw
.
Close
();
mw
.
Close
();
RequestHtmlBody
=
Encoding
.
Default
.
GetString
(
mw
.
ToArray
());
RequestHtmlBody
=
Encoding
.
Default
.
GetString
(
mw
.
ToArray
());
}
}
RequestWasModified
=
true
;
return
RequestHtmlBody
;
return
RequestHtmlBody
;
}
}
public
void
SetRequestHtmlBody
(
string
Body
)
public
void
SetRequestHtmlBody
(
string
Body
)
{
{
this
.
RequestHtmlBody
=
Body
;
this
.
RequestHtmlBody
=
Body
;
RequestWasModified
=
true
;
}
}
public
string
GetResponseHtmlBody
()
public
string
GetResponseHtmlBody
()
{
{
...
@@ -97,7 +100,7 @@ namespace Titanium.Web.Proxy.Models
...
@@ -97,7 +100,7 @@ namespace Titanium.Web.Proxy.Models
break
;
break
;
}
}
ResponseHtmlBody
=
ResponseData
;
ResponseHtmlBody
=
ResponseData
;
WasModified
=
true
;
Response
WasModified
=
true
;
}
}
return
ResponseHtmlBody
;
return
ResponseHtmlBody
;
...
@@ -153,7 +156,13 @@ namespace Titanium.Web.Proxy.Models
...
@@ -153,7 +156,13 @@ namespace Titanium.Web.Proxy.Models
public
System
.
Net
.
Sockets
.
TcpClient
Client
{
get
;
set
;
}
public
string
tunnelHostName
{
get
;
set
;
}
public
string
securehost
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/ProxyServer.cs
View file @
ef2dbb18
...
@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
...
@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
private
static
object
certificateAccessLock
=
new
object
();
private
static
object
certificateAccessLock
=
new
object
();
private
static
List
<
string
>
pinnedCertificateClients
=
new
List
<
string
>();
private
static
List
<
string
>
pinnedCertificateClients
=
new
List
<
string
>();
private
static
ManualResetEvent
tcpClientConnected
=
new
ManualResetEvent
(
false
);
private
static
TcpListener
listener
;
private
static
TcpListener
listener
;
private
static
Thread
listenerThread
;
private
static
Thread
listenerThread
;
...
@@ -46,6 +46,8 @@ namespace Titanium.Web.Proxy
...
@@ -46,6 +46,8 @@ namespace Titanium.Web.Proxy
public
static
IPAddress
ListeningIPInterface
{
get
;
set
;
}
public
static
IPAddress
ListeningIPInterface
{
get
;
set
;
}
public
static
string
RootCertificateName
{
get
;
set
;
}
public
static
string
RootCertificateName
{
get
;
set
;
}
public
static
bool
EnableSSL
{
get
;
set
;
}
public
static
bool
SetAsSystemProxy
{
get
;
set
;
}
public
static
Int32
ListeningPort
public
static
Int32
ListeningPort
{
{
...
@@ -141,65 +143,24 @@ namespace Titanium.Web.Proxy
...
@@ -141,65 +143,24 @@ namespace Titanium.Web.Proxy
{
{
while
(
ShouldListen
)
while
(
ShouldListen
)
{
{
// Set the event to nonsignaled state.
tcpClientConnected
.
Reset
();
var
client
=
listener
.
AcceptTcpClient
();
Task
.
Factory
.
StartNew
(()
=>
HandleClient
(
client
));
listener
.
BeginAcceptTcpClient
(
new
AsyncCallback
(
AcceptTcpClientCallback
),
listener
);
// Wait until a connection is made and processed before
// continuing.
tcpClientConnected
.
WaitOne
();
}
}
}
}
catch
(
ThreadInterruptedException
)
{
}
catch
(
ThreadInterruptedException
)
{
}
catch
(
SocketException
ex
)
catch
(
SocketException
)
{
{
Debug
.
WriteLine
(
ex
.
Message
);
}
}
public
static
void
AcceptTcpClientCallback
(
IAsyncResult
ar
)
{
try
{
// Get the listener that handles the client request.
TcpListener
listener
=
(
TcpListener
)
ar
.
AsyncState
;
TcpClient
client
=
null
;
// End the operation and display the received data on
// the console.
client
=
listener
.
EndAcceptTcpClient
(
ar
);
Task
.
Factory
.
StartNew
(()
=>
ProcessClient
(
client
));
// Signal the calling thread to continue.
tcpClientConnected
.
Set
();
}
}
catch
(
ObjectDisposedException
)
{
}
}
private
static
void
ProcessClient
(
Object
param
)
{
try
{
TcpClient
client
=
param
as
TcpClient
;
HandleClientRequest
(
client
);
client
.
Close
();
}
catch
(
Exception
ex
)
{
Debug
.
WriteLine
(
ex
.
Message
);
}
}
}
public
static
bool
EnableSSL
{
get
;
set
;
}
public
static
bool
SetAsSystemProxy
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/RequestHandler.cs
View file @
ef2dbb18
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/ResponseHandler.cs
View file @
ef2dbb18
...
@@ -11,12 +11,13 @@ using System.Security.Authentication;
...
@@ -11,12 +11,13 @@ using System.Security.Authentication;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
partial
class
ProxyServer
partial
class
ProxyServer
{
{
private
static
void
Handle
Server
Response
(
IAsyncResult
AsynchronousResult
)
private
static
void
Handle
HttpSession
Response
(
IAsyncResult
AsynchronousResult
)
{
{
SessionEventArgs
args
=
(
SessionEventArgs
)
AsynchronousResult
.
AsyncState
;
SessionEventArgs
args
=
(
SessionEventArgs
)
AsynchronousResult
.
AsyncState
;
...
@@ -55,7 +56,7 @@ namespace Titanium.Web.Proxy
...
@@ -55,7 +56,7 @@ namespace Titanium.Web.Proxy
if
(
BeforeResponse
!=
null
)
if
(
BeforeResponse
!=
null
)
BeforeResponse
(
null
,
args
);
BeforeResponse
(
null
,
args
);
if
(
args
.
WasModified
)
if
(
args
.
Response
WasModified
)
{
{
byte
[]
data
;
byte
[]
data
;
...
@@ -137,21 +138,36 @@ namespace Titanium.Web.Proxy
...
@@ -137,21 +138,36 @@ namespace Titanium.Web.Proxy
finally
finally
{
{
if
(
args
.
ProxyRequest
.
KeepAlive
==
false
)
if
(
args
.
ProxyRequest
!=
null
)
args
.
ProxyRequest
.
Abort
();
{
if
(
args
.
ServerResponseStream
!=
null
)
args
.
ServerResponseStream
.
Close
();
if
(
responseWriter
!=
null
)
responseWriter
.
Close
();
if
(
clientWriteStream
!=
null
)
clientWriteStream
.
Close
();
}
if
(
args
.
ServerResponse
!=
null
)
if
(
args
.
ServerResponse
!=
null
)
args
.
ServerResponse
.
Close
();
args
.
ServerResponse
.
Close
();
args
.
FinishedRequestEvent
.
Set
();
}
if
(
args
.
ProxyRequest
.
KeepAlive
==
false
)
{
if
(
responseWriter
!=
null
)
responseWriter
.
Close
();
if
(
clientWriteStream
!=
null
)
clientWriteStream
.
Close
();
args
.
Client
.
Close
();
}
else
{
string
httpCmd
,
tmpLine
;
List
<
string
>
requestLines
=
new
List
<
string
>();
requestLines
.
Clear
();
while
(!
String
.
IsNullOrEmpty
(
tmpLine
=
args
.
ClientStreamReader
.
ReadLine
()))
{
requestLines
.
Add
(
tmpLine
);
}
httpCmd
=
requestLines
.
Count
()
>
0
?
requestLines
[
0
]
:
null
;
TcpClient
Client
=
args
.
Client
;
HandleHttpSessionRequest
(
Client
,
httpCmd
,
args
.
ProxyRequest
.
ConnectionGroupName
,
args
.
ClientStream
,
args
.
tunnelHostName
,
requestLines
,
args
.
ClientStreamReader
,
args
.
securehost
);
}
}
}
}
...
...
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