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
e49020b4
Commit
e49020b4
authored
May 21, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return/continue check in retry
parent
69012f32
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
20 deletions
+33
-20
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+6
-2
RetryPolicy.cs
Titanium.Web.Proxy/Network/RetryPolicy.cs
+20
-17
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+7
-1
No files found.
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
e49020b4
...
...
@@ -203,6 +203,12 @@ namespace Titanium.Web.Proxy
{
decryptSsl
=
false
;
}
if
(!
decryptSsl
)
{
await
tcpConnectionFactory
.
Release
(
prefetchConnectionTask
,
true
);
prefetchConnectionTask
=
null
;
}
}
if
(
cancellationTokenSource
.
IsCancellationRequested
)
...
...
@@ -250,8 +256,6 @@ namespace Titanium.Web.Proxy
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
connectArgs
.
CancellationTokenSource
,
ExceptionFunc
);
}
finally
{
...
...
Titanium.Web.Proxy/Network/RetryPolicy.cs
View file @
e49020b4
...
...
@@ -11,8 +11,6 @@ namespace Titanium.Web.Proxy.Network
private
readonly
TcpConnectionFactory
tcpConnectionFactory
;
private
TcpServerConnection
currentConnection
;
private
Exception
exception
;
private
Policy
policy
;
internal
RetryPolicy
(
int
retries
,
TcpConnectionFactory
tcpConnectionFactory
)
...
...
@@ -26,15 +24,16 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// Execute and retry the given action until retry number of times.
/// </summary>
/// <param name="action">The action to retry.</param>
/// <param name="action">The action to retry
with return value specifying whether caller should continue execution
.</param>
/// <param name="generator">The Tcp connection generator to be invoked to get new connection for retry.</param>
/// <param name="initialConnection">Initial Tcp connection to use.</param>
/// <returns>Returns the latest connection used and the latest exception if any.</returns>
internal
async
Task
<
RetryResult
>
ExecuteAsync
(
Func
<
TcpServerConnection
,
Task
>
action
,
internal
async
Task
<
RetryResult
>
ExecuteAsync
(
Func
<
TcpServerConnection
,
Task
<
bool
>
>
action
,
Func
<
Task
<
TcpServerConnection
>>
generator
,
TcpServerConnection
initialConnection
)
{
currentConnection
=
initialConnection
;
exception
=
null
;
Exception
exception
=
null
;
bool
@continue
=
true
;
try
{
...
...
@@ -46,13 +45,13 @@ namespace Titanium.Web.Proxy.Network
currentConnection
=
currentConnection
as
TcpServerConnection
??
await
generator
();
//try
await
action
(
currentConnection
);
@continue
=
await
action
(
currentConnection
);
});
}
catch
(
Exception
e
)
{
exception
=
e
;
}
return
new
RetryResult
(
currentConnection
,
exception
);
return
new
RetryResult
(
currentConnection
,
exception
,
@continue
);
}
//get the policy
...
...
@@ -60,7 +59,11 @@ namespace Titanium.Web.Proxy.Network
{
return
Policy
.
Handle
<
T
>()
.
RetryAsync
(
retries
,
onRetryAsync
:
async
(
ex
,
i
,
context
)
=>
onRetryAsync
:
onRetry
);
}
//before retry clear connection
private
async
Task
onRetry
(
Exception
ex
,
int
attempt
)
{
if
(
currentConnection
!=
null
)
{
...
...
@@ -68,8 +71,6 @@ namespace Titanium.Web.Proxy.Network
await
tcpConnectionFactory
.
Release
(
currentConnection
,
true
);
currentConnection
=
null
;
}
});
}
}
...
...
@@ -78,11 +79,13 @@ namespace Titanium.Web.Proxy.Network
internal
bool
IsSuccess
=>
Exception
==
null
;
internal
TcpServerConnection
LatestConnection
{
get
;
}
internal
Exception
Exception
{
get
;
}
internal
bool
Continue
{
get
;
}
internal
RetryResult
(
TcpServerConnection
lastConnection
,
Exception
exception
)
internal
RetryResult
(
TcpServerConnection
lastConnection
,
Exception
exception
,
bool
@continue
)
{
LatestConnection
=
lastConnection
;
Exception
=
exception
;
Continue
=
@continue
;
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
e49020b4
...
...
@@ -220,11 +220,12 @@ namespace Titanium.Web.Proxy
response
,
clientStream
,
clientStreamWriter
,
serverConnection
,
cancellationTokenSource
,
cancellationToken
);
closeServerConnection
=
true
;
return
;
return
false
;
}
// construct the web request that we are going to issue on behalf of the client.
await
handleHttpSessionRequestInternal
(
serverConnection
,
args
);
return
true
;
},
generator
,
connection
);
...
...
@@ -237,6 +238,11 @@ namespace Titanium.Web.Proxy
throw
result
.
Exception
;
}
if
(!
result
.
Continue
)
{
return
;
}
//user requested
if
(
args
.
WebSession
.
CloseServerConnection
)
{
...
...
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