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
6e2acc49
Commit
6e2acc49
authored
Jan 01, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle exception in user events, small fix
parent
236e7563
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
13 deletions
+43
-13
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+33
-5
TunnelConnectEventArgs.cs
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
+4
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+6
-5
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
6e2acc49
...
@@ -34,6 +34,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -34,6 +34,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
private
Func
<
SessionEventArgs
,
Task
>
httpResponseHandler
;
private
Func
<
SessionEventArgs
,
Task
>
httpResponseHandler
;
private
readonly
Action
<
Exception
>
exceptionFunc
;
/// <summary>
/// <summary>
/// Backing field for corresponding public property
/// Backing field for corresponding public property
/// </summary>
/// </summary>
...
@@ -104,12 +106,14 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -104,12 +106,14 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Constructor to initialize the proxy
/// Constructor to initialize the proxy
/// </summary>
/// </summary>
internal
SessionEventArgs
(
int
bufferSize
,
internal
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ProxyEndPoint
endPoint
,
Func
<
SessionEventArgs
,
Task
>
httpResponseHandler
)
Func
<
SessionEventArgs
,
Task
>
httpResponseHandler
,
Action
<
Exception
>
exceptionFunc
)
{
{
this
.
bufferSize
=
bufferSize
;
this
.
bufferSize
=
bufferSize
;
this
.
httpResponseHandler
=
httpResponseHandler
;
this
.
httpResponseHandler
=
httpResponseHandler
;
this
.
exceptionFunc
=
exceptionFunc
;
ProxyClient
=
new
ProxyClient
();
ProxyClient
=
new
ProxyClient
();
WebSession
=
new
HttpWebClient
(
bufferSize
);
WebSession
=
new
HttpWebClient
(
bufferSize
);
...
@@ -169,17 +173,41 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -169,17 +173,41 @@ namespace Titanium.Web.Proxy.EventArguments
internal
void
OnDataSent
(
byte
[]
buffer
,
int
offset
,
int
count
)
internal
void
OnDataSent
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
{
DataSent
?.
Invoke
(
this
,
new
DataEventArgs
(
buffer
,
offset
,
count
));
try
{
DataSent
?.
Invoke
(
this
,
new
DataEventArgs
(
buffer
,
offset
,
count
));
}
catch
(
Exception
ex
)
{
var
ex2
=
new
Exception
(
"Exception thrown in user event"
,
ex
);
exceptionFunc
(
ex2
);
}
}
}
internal
void
OnDataReceived
(
byte
[]
buffer
,
int
offset
,
int
count
)
internal
void
OnDataReceived
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
{
DataReceived
?.
Invoke
(
this
,
new
DataEventArgs
(
buffer
,
offset
,
count
));
try
{
DataReceived
?.
Invoke
(
this
,
new
DataEventArgs
(
buffer
,
offset
,
count
));
}
catch
(
Exception
ex
)
{
var
ex2
=
new
Exception
(
"Exception thrown in user event"
,
ex
);
exceptionFunc
(
ex2
);
}
}
}
internal
void
OnMultipartRequestPartSent
(
string
boundary
,
HeaderCollection
headers
)
internal
void
OnMultipartRequestPartSent
(
string
boundary
,
HeaderCollection
headers
)
{
{
MultipartRequestPartSent
?.
Invoke
(
this
,
new
MultipartRequestPartSentEventArgs
(
boundary
,
headers
));
try
{
MultipartRequestPartSent
?.
Invoke
(
this
,
new
MultipartRequestPartSentEventArgs
(
boundary
,
headers
));
}
catch
(
Exception
ex
)
{
var
ex2
=
new
Exception
(
"Exception thrown in user event"
,
ex
);
exceptionFunc
(
ex2
);
}
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
View file @
6e2acc49
using
Titanium.Web.Proxy.Http
;
using
System
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.EventArguments
namespace
Titanium.Web.Proxy.EventArguments
...
@@ -7,8 +8,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -7,8 +8,8 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
public
bool
IsHttpsConnect
{
get
;
set
;
}
public
bool
IsHttpsConnect
{
get
;
set
;
}
internal
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
)
internal
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
Action
<
Exception
>
exceptionFunc
)
:
base
(
bufferSize
,
endPoint
,
null
)
:
base
(
bufferSize
,
endPoint
,
null
,
exceptionFunc
)
{
{
WebSession
.
Request
=
connectRequest
;
WebSession
.
Request
=
connectRequest
;
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
6e2acc49
...
@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
...
@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
connectRequest
.
Headers
);
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
connectRequest
.
Headers
);
var
connectArgs
=
new
TunnelConnectSessionEventArgs
(
BufferSize
,
endPoint
,
connectRequest
);
var
connectArgs
=
new
TunnelConnectSessionEventArgs
(
BufferSize
,
endPoint
,
connectRequest
,
ExceptionFunc
);
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
...
@@ -164,7 +164,8 @@ namespace Titanium.Web.Proxy
...
@@ -164,7 +164,8 @@ namespace Titanium.Web.Proxy
{
{
if
(
isClientHello
)
if
(
isClientHello
)
{
{
if
(
clientStream
.
Available
>
0
)
int
available
=
clientStream
.
Available
;
if
(
available
>
0
)
{
{
//send the buffered data
//send the buffered data
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
...
@@ -172,8 +173,8 @@ namespace Titanium.Web.Proxy
...
@@ -172,8 +173,8 @@ namespace Titanium.Web.Proxy
try
try
{
{
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await
clientStream
.
ReadAsync
(
data
,
0
,
clientStream
.
A
vailable
);
await
clientStream
.
ReadAsync
(
data
,
0
,
a
vailable
);
await
connection
.
StreamWriter
.
WriteAsync
(
data
,
true
);
await
connection
.
StreamWriter
.
WriteAsync
(
data
,
0
,
available
,
true
);
}
}
finally
finally
{
{
...
@@ -309,7 +310,7 @@ namespace Titanium.Web.Proxy
...
@@ -309,7 +310,7 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
HandleHttpSessionResponse
)
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
HandleHttpSessionResponse
,
ExceptionFunc
)
{
{
ProxyClient
=
{
TcpClient
=
client
},
ProxyClient
=
{
TcpClient
=
client
},
WebSession
=
{
ConnectRequest
=
connectRequest
}
WebSession
=
{
ConnectRequest
=
connectRequest
}
...
...
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