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
65be519e
Commit
65be519e
authored
Dec 26, 2015
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #27
Improve performance by avoiding new Tasks for each requests
parent
ca13d730
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
148 additions
and
127 deletions
+148
-127
CustomBinaryReader.cs
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
+9
-9
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+1
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+120
-114
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+18
-3
No files found.
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
View file @
65be519e
...
...
@@ -14,27 +14,28 @@ namespace Titanium.Web.Proxy.Helpers
internal
string
ReadLine
()
{
var
buf
=
new
char
[
1
];
var
readBuffer
=
new
StringBuilder
();
try
{
var
lastChar
=
new
char
(
);
var
lastChar
=
default
(
char
);
while
(
(
Read
(
buf
,
0
,
1
))
>
0
)
while
(
true
)
{
if
(
lastChar
==
'\r'
&&
buf
[
0
]
==
'\n'
)
var
buf
=
ReadChar
();
if
(
lastChar
==
'\r'
&&
buf
==
'\n'
)
{
return
readBuffer
.
Remove
(
readBuffer
.
Length
-
1
,
1
).
ToString
();
}
if
(
buf
[
0
]
==
'\0'
)
if
(
buf
==
'\0'
)
{
return
readBuffer
.
ToString
();
}
readBuffer
.
Append
(
buf
[
0
]
);
readBuffer
.
Append
(
buf
);
lastChar
=
buf
[
0
]
;
lastChar
=
buf
;
}
return
readBuffer
.
ToString
();
}
catch
(
IOException
)
{
...
...
@@ -42,7 +43,6 @@ namespace Titanium.Web.Proxy.Helpers
}
}
internal
List
<
string
>
ReadAllLines
()
{
string
tmpLine
;
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
65be519e
...
...
@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy
{
ServicePointManager
.
Expect100Continue
=
false
;
WebRequest
.
DefaultWebProxy
=
null
;
ServicePointManager
.
DefaultConnectionLimit
=
10
;
ServicePointManager
.
DefaultConnectionLimit
=
int
.
MaxValue
;
ServicePointManager
.
DnsRefreshTimeout
=
3
*
60
*
1000
;
//3 minutes
ServicePointManager
.
MaxServicePointIdleTime
=
3
*
60
*
1000
;
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
65be519e
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/ResponseHandler.cs
View file @
65be519e
...
...
@@ -15,13 +15,12 @@ namespace Titanium.Web.Proxy
partial
class
ProxyServer
{
//Called asynchronously when a request was successfully and we received the response
private
static
void
HandleHttpSessionResponse
(
IAsyncResult
asynchronousResult
)
private
static
void
HandleHttpSessionResponse
(
SessionEventArgs
args
)
{
var
args
=
(
SessionEventArgs
)
asynchronousResult
.
AsyncState
;
try
{
args
.
ServerResponse
=
(
HttpWebResponse
)
args
.
ProxyRequest
.
EndGetResponse
(
asynchronousResult
);
args
.
ServerResponse
=
(
HttpWebResponse
)
args
.
ProxyRequest
.
GetResponse
(
);
}
catch
(
WebException
webEx
)
{
...
...
@@ -132,6 +131,8 @@ namespace Titanium.Web.Proxy
{
if
(
headers
!=
null
)
{
FixProxyHeaders
(
headers
);
foreach
(
var
header
in
headers
)
{
responseWriter
.
WriteLine
(
header
.
ToString
());
...
...
@@ -141,10 +142,24 @@ namespace Titanium.Web.Proxy
responseWriter
.
WriteLine
();
responseWriter
.
Flush
();
}
private
static
void
FixProxyHeaders
(
List
<
HttpHeader
>
headers
)
{
//If proxy-connection close was returned inform to close the connection
if
(
headers
.
Any
(
x
=>
x
.
Name
.
ToLower
()
==
"proxy-connection"
&&
x
.
Value
.
ToLower
()
==
"close"
))
if
(
headers
.
Any
(
x
=>
x
.
Name
.
ToLower
()
==
"connection"
)
==
false
)
{
headers
.
Add
(
new
HttpHeader
(
"connection"
,
"close"
));
headers
.
RemoveAll
(
x
=>
x
.
Name
.
ToLower
()
==
"proxy-connection"
);
}
else
headers
.
Find
(
x
=>
x
.
Name
.
ToLower
()
==
"connection"
).
Value
=
"close"
;
}
private
static
void
WriteResponseHeaders
(
StreamWriter
responseWriter
,
List
<
HttpHeader
>
headers
,
int
length
,
bool
isChunked
)
{
FixProxyHeaders
(
headers
);
if
(!
isChunked
)
{
if
(
headers
.
Any
(
x
=>
x
.
Name
.
ToLower
()
==
"content-length"
)
==
false
)
...
...
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