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
ba234a9c
Unverified
Commit
ba234a9c
authored
May 12, 2018
by
justcoding121
Committed by
GitHub
May 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #436 from justcoding121/master
Beta with small bug fixes in connection pool
parents
3d443dd7
4c092efd
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
29 deletions
+44
-29
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+1
-1
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+30
-14
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+3
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+7
-3
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+0
-5
Titanium.Web.Proxy.ProxyServer.html
docs/api/Titanium.Web.Proxy.ProxyServer.html
+2
-2
index.json
docs/index.json
+1
-1
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
ba234a9c
...
@@ -23,7 +23,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -23,7 +23,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
ProxyTestController
()
public
ProxyTestController
()
{
{
proxyServer
=
new
ProxyServer
();
proxyServer
=
new
ProxyServer
();
proxyServer
.
EnableConnectionPool
=
tru
e
;
//proxyServer.EnableConnectionPool = fals
e;
// generate root certificate without storing it in file system
// generate root certificate without storing it in file system
//proxyServer.CertificateManager.CreateRootCertificate(false);
//proxyServer.CertificateManager.CreateRootCertificate(false);
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
ba234a9c
...
@@ -463,7 +463,9 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -463,7 +463,9 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
/// <param name="html">HTML content to sent.</param>
/// <param name="html">HTML content to sent.</param>
/// <param name="headers">HTTP response headers.</param>
/// <param name="headers">HTTP response headers.</param>
public
void
Ok
(
string
html
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
)
/// <param name="closeServerConnection">Close the server connection?</param>
public
void
Ok
(
string
html
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
,
bool
closeServerConnection
=
false
)
{
{
var
response
=
new
OkResponse
();
var
response
=
new
OkResponse
();
if
(
headers
!=
null
)
if
(
headers
!=
null
)
...
@@ -474,7 +476,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -474,7 +476,7 @@ namespace Titanium.Web.Proxy.EventArguments
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
response
.
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
Respond
(
response
);
Respond
(
response
,
closeServerConnection
);
}
}
/// <summary>
/// <summary>
...
@@ -483,14 +485,16 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -483,14 +485,16 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
/// <param name="result">The html content bytes.</param>
/// <param name="result">The html content bytes.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="headers">The HTTP headers.</param>
public
void
Ok
(
byte
[]
result
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
)
/// <param name="closeServerConnection">Close the server connection?</param>
public
void
Ok
(
byte
[]
result
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
,
bool
closeServerConnection
=
false
)
{
{
var
response
=
new
OkResponse
();
var
response
=
new
OkResponse
();
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Body
=
result
;
response
.
Body
=
result
;
Respond
(
response
);
Respond
(
response
,
closeServerConnection
);
}
}
/// <summary>
/// <summary>
...
@@ -501,15 +505,16 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -501,15 +505,16 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="html">The html content.</param>
/// <param name="html">The html content.</param>
/// <param name="status">The HTTP status code.</param>
/// <param name="status">The HTTP status code.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="headers">The HTTP headers.</param>
/// <returns></returns>
/// <param name="closeServerConnection">Close the server connection?</param>
public
void
GenericResponse
(
string
html
,
HttpStatusCode
status
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
)
public
void
GenericResponse
(
string
html
,
HttpStatusCode
status
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
,
bool
closeServerConnection
=
false
)
{
{
var
response
=
new
GenericResponse
(
status
);
var
response
=
new
GenericResponse
(
status
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
response
.
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
Respond
(
response
);
Respond
(
response
,
closeServerConnection
);
}
}
/// <summary>
/// <summary>
...
@@ -519,51 +524,57 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -519,51 +524,57 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="result">The bytes to sent.</param>
/// <param name="result">The bytes to sent.</param>
/// <param name="status">The HTTP status code.</param>
/// <param name="status">The HTTP status code.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="headers">The HTTP headers.</param>
/// <returns></returns>
/// <param name="closeServerConnection">Close the server connection?</param>
public
void
GenericResponse
(
byte
[]
result
,
HttpStatusCode
status
,
Dictionary
<
string
,
HttpHeader
>
headers
)
public
void
GenericResponse
(
byte
[]
result
,
HttpStatusCode
status
,
Dictionary
<
string
,
HttpHeader
>
headers
,
bool
closeServerConnection
=
false
)
{
{
var
response
=
new
GenericResponse
(
status
);
var
response
=
new
GenericResponse
(
status
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Body
=
result
;
response
.
Body
=
result
;
Respond
(
response
);
Respond
(
response
,
closeServerConnection
);
}
}
/// <summary>
/// <summary>
/// Redirect to provided URL.
/// Redirect to provided URL.
/// </summary>
/// </summary>
/// <param name="url">The URL to redirect.</param>
/// <param name="url">The URL to redirect.</param>
/// <
returns></returns
>
/// <
param name="closeServerConnection">Close the server connection?</param
>
public
void
Redirect
(
string
url
)
public
void
Redirect
(
string
url
,
bool
closeServerConnection
=
false
)
{
{
var
response
=
new
RedirectResponse
();
var
response
=
new
RedirectResponse
();
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Headers
.
AddHeader
(
KnownHeaders
.
Location
,
url
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
Location
,
url
);
response
.
Body
=
emptyData
;
response
.
Body
=
emptyData
;
Respond
(
response
);
Respond
(
response
,
closeServerConnection
);
}
}
/// <summary>
/// <summary>
/// Respond with given response object to client.
/// Respond with given response object to client.
/// </summary>
/// </summary>
/// <param name="response">The response object.</param>
/// <param name="response">The response object.</param>
public
void
Respond
(
Response
response
)
/// <param name="closeServerConnection">Close the server connection?</param>
public
void
Respond
(
Response
response
,
bool
closeServerConnection
=
false
)
{
{
//request already send.
if
(
WebSession
.
Request
.
Locked
)
if
(
WebSession
.
Request
.
Locked
)
{
{
//response already received from server and ready to be sent to client.
if
(
WebSession
.
Response
.
Locked
)
if
(
WebSession
.
Response
.
Locked
)
{
{
throw
new
Exception
(
"You cannot call this function after response is sent to the client."
);
throw
new
Exception
(
"You cannot call this function after response is sent to the client."
);
}
}
//response already received from server but not yet ready to sent to client.
response
.
Locked
=
true
;
response
.
Locked
=
true
;
response
.
TerminateResponse
=
WebSession
.
Response
.
TerminateResponse
;
response
.
TerminateResponse
=
WebSession
.
Response
.
TerminateResponse
;
WebSession
.
Response
=
response
;
WebSession
.
Response
=
response
;
}
}
else
else
{
{
//request not yet sent.
WebSession
.
Request
.
Locked
=
true
;
WebSession
.
Request
.
Locked
=
true
;
response
.
Locked
=
true
;
response
.
Locked
=
true
;
...
@@ -571,6 +582,11 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -571,6 +582,11 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession
.
Request
.
CancelRequest
=
true
;
WebSession
.
Request
.
CancelRequest
=
true
;
}
}
if
(
closeServerConnection
)
{
TerminateServerConnection
();
}
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
ba234a9c
...
@@ -155,10 +155,10 @@ namespace Titanium.Web.Proxy
...
@@ -155,10 +155,10 @@ namespace Titanium.Web.Proxy
public
bool
Enable100ContinueBehaviour
{
get
;
set
;
}
public
bool
Enable100ContinueBehaviour
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Should we enable
experimental Tcp
server connection pool?
/// Should we enable server connection pool?
/// Defaults to
fals
e.
/// Defaults to
tru
e.
/// </summary>
/// </summary>
public
bool
EnableConnectionPool
{
get
;
set
;
}
public
bool
EnableConnectionPool
{
get
;
set
;
}
=
true
;
/// <summary>
/// <summary>
/// Buffer size used throughout this proxy.
/// Buffer size used throughout this proxy.
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
ba234a9c
...
@@ -182,14 +182,15 @@ namespace Titanium.Web.Proxy
...
@@ -182,14 +182,15 @@ namespace Titanium.Web.Proxy
}
}
//If prefetch task is available.
//If prefetch task is available.
//Delay awaiting prefect task as far as possible.
if
(
serverConnection
==
null
&&
prefetchTask
!=
null
)
if
(
serverConnection
==
null
&&
prefetchTask
!=
null
)
{
{
serverConnection
=
await
prefetchTask
;
serverConnection
=
await
prefetchTask
;
prefetchTask
=
null
;
prefetchTask
=
null
;
}
}
// create a new connection if cache key changes
// create a new connection if cache key changes.
// only gets hit when connection pool is disabled.
// or when prefetch task has a unexpectedly different connection.
if
(
serverConnection
!=
null
if
(
serverConnection
!=
null
&&
(
await
getConnectionCacheKey
(
args
,
false
,
&&
(
await
getConnectionCacheKey
(
args
,
false
,
clientConnection
.
NegotiatedApplicationProtocol
)
clientConnection
.
NegotiatedApplicationProtocol
)
...
@@ -218,6 +219,7 @@ namespace Titanium.Web.Proxy
...
@@ -218,6 +219,7 @@ namespace Titanium.Web.Proxy
await
handleWebSocketUpgrade
(
httpCmd
,
args
,
request
,
await
handleWebSocketUpgrade
(
httpCmd
,
args
,
request
,
response
,
clientStream
,
clientStreamWriter
,
response
,
clientStream
,
clientStreamWriter
,
serverConnection
,
cancellationTokenSource
,
cancellationToken
);
serverConnection
,
cancellationTokenSource
,
cancellationToken
);
closeServerConnection
=
true
;
return
;
return
;
}
}
...
@@ -245,8 +247,10 @@ namespace Titanium.Web.Proxy
...
@@ -245,8 +247,10 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
if
(
args
.
WebSession
.
ServerConnection
==
null
)
//user requested
if
(
args
.
WebSession
.
Response
.
TerminateResponse
)
{
{
closeServerConnection
=
true
;
return
;
return
;
}
}
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
ba234a9c
...
@@ -62,11 +62,6 @@ namespace Titanium.Web.Proxy
...
@@ -62,11 +62,6 @@ namespace Titanium.Web.Proxy
// syphon out the response body from server before setting the new body
// syphon out the response body from server before setting the new body
await
args
.
SyphonOutBodyAsync
(
false
,
cancellationToken
);
await
args
.
SyphonOutBodyAsync
(
false
,
cancellationToken
);
}
}
else
{
await
tcpConnectionFactory
.
Release
(
args
.
WebSession
.
ServerConnection
,
true
);
args
.
WebSession
.
ServerConnection
=
null
;
}
return
;
return
;
}
}
...
...
docs/api/Titanium.Web.Proxy.ProxyServer.html
View file @
ba234a9c
...
@@ -445,8 +445,8 @@ Defaults to false.</p>
...
@@ -445,8 +445,8 @@ Defaults to false.</p>
<a
id=
"Titanium_Web_Proxy_ProxyServer_EnableConnectionPool_"
data-uid=
"Titanium.Web.Proxy.ProxyServer.EnableConnectionPool*"
></a>
<a
id=
"Titanium_Web_Proxy_ProxyServer_EnableConnectionPool_"
data-uid=
"Titanium.Web.Proxy.ProxyServer.EnableConnectionPool*"
></a>
<h4
id=
"Titanium_Web_Proxy_ProxyServer_EnableConnectionPool"
data-uid=
"Titanium.Web.Proxy.ProxyServer.EnableConnectionPool"
>
EnableConnectionPool
</h4>
<h4
id=
"Titanium_Web_Proxy_ProxyServer_EnableConnectionPool"
data-uid=
"Titanium.Web.Proxy.ProxyServer.EnableConnectionPool"
>
EnableConnectionPool
</h4>
<div
class=
"markdown level1 summary"
><p>
Should we enable
experimental Tcp
server connection pool?
<div
class=
"markdown level1 summary"
><p>
Should we enable server connection pool?
Defaults to
fals
e.
</p>
Defaults to
tru
e.
</p>
</div>
</div>
<div
class=
"markdown level1 conceptual"
></div>
<div
class=
"markdown level1 conceptual"
></div>
<h5
class=
"decalaration"
>
Declaration
</h5>
<h5
class=
"decalaration"
>
Declaration
</h5>
...
...
docs/index.json
View file @
ba234a9c
This diff is collapsed.
Click to expand it.
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