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
e3775e03
Commit
e3775e03
authored
May 08, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use stringbuilder to write headers in bulk
parent
222f2776
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
19 deletions
+16
-19
HttpWriter.cs
Titanium.Web.Proxy/Helpers/HttpWriter.cs
+5
-2
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+9
-10
HttpHeader.cs
Titanium.Web.Proxy/Models/HttpHeader.cs
+2
-7
No files found.
Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
e3775e03
...
@@ -104,12 +104,15 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -104,12 +104,15 @@ namespace Titanium.Web.Proxy.Helpers
internal
async
Task
WriteHeadersAsync
(
HeaderCollection
headers
,
bool
flush
=
true
,
internal
async
Task
WriteHeadersAsync
(
HeaderCollection
headers
,
bool
flush
=
true
,
CancellationToken
cancellationToken
=
default
)
CancellationToken
cancellationToken
=
default
)
{
{
var
headerBuilder
=
new
StringBuilder
();
foreach
(
var
header
in
headers
)
foreach
(
var
header
in
headers
)
{
{
await
header
.
WriteToStreamAsync
(
this
,
cancellationToken
);
header
.
Write
(
headerBuilder
);
}
}
headerBuilder
.
AppendLine
();
await
WriteAsync
(
headerBuilder
.
ToString
(),
cancellationToken
);
await
WriteLineAsync
(
cancellationToken
);
if
(
flush
)
if
(
flush
)
{
{
await
stream
.
FlushAsync
(
cancellationToken
);
await
stream
.
FlushAsync
(
cancellationToken
);
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
e3775e03
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Net
;
using
System.Net
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
...
@@ -15,12 +15,9 @@ namespace Titanium.Web.Proxy.Http
...
@@ -15,12 +15,9 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
class
HttpWebClient
public
class
HttpWebClient
{
{
private
readonly
int
bufferSize
;
internal
HttpWebClient
(
int
bufferSize
,
Request
request
=
null
,
Response
response
=
null
)
internal
HttpWebClient
(
int
bufferSize
,
Request
request
=
null
,
Response
response
=
null
)
{
{
this
.
bufferSize
=
bufferSize
;
Request
=
request
??
new
Request
();
Request
=
request
??
new
Request
();
Response
=
response
??
new
Response
();
Response
=
response
??
new
Response
();
}
}
...
@@ -99,15 +96,16 @@ namespace Titanium.Web.Proxy.Http
...
@@ -99,15 +96,16 @@ namespace Titanium.Web.Proxy.Http
useUpstreamProxy
||
isTransparent
?
Request
.
OriginalUrl
:
Request
.
RequestUri
.
PathAndQuery
,
useUpstreamProxy
||
isTransparent
?
Request
.
OriginalUrl
:
Request
.
RequestUri
.
PathAndQuery
,
Request
.
HttpVersion
),
cancellationToken
);
Request
.
HttpVersion
),
cancellationToken
);
var
headerBuilder
=
new
StringBuilder
();
// Send Authentication to Upstream proxy if needed
// Send Authentication to Upstream proxy if needed
if
(!
isTransparent
&&
upstreamProxy
!=
null
if
(!
isTransparent
&&
upstreamProxy
!=
null
&&
ServerConnection
.
IsHttps
==
false
&&
ServerConnection
.
IsHttps
==
false
&&
!
string
.
IsNullOrEmpty
(
upstreamProxy
.
UserName
)
&&
!
string
.
IsNullOrEmpty
(
upstreamProxy
.
UserName
)
&&
upstreamProxy
.
Password
!=
null
)
&&
upstreamProxy
.
Password
!=
null
)
{
{
await
HttpHeader
.
ProxyConnectionKeepAlive
.
WriteToStreamAsync
(
writer
,
cancellationToken
);
HttpHeader
.
ProxyConnectionKeepAlive
.
Write
(
headerBuilder
);
await
HttpHeader
.
GetProxyAuthorizationHeader
(
upstreamProxy
.
UserName
,
upstreamProxy
.
Password
)
HttpHeader
.
GetProxyAuthorizationHeader
(
upstreamProxy
.
UserName
,
upstreamProxy
.
Password
)
.
Write
ToStreamAsync
(
writer
,
cancellationToken
);
.
Write
(
headerBuilder
);
}
}
// write request headers
// write request headers
...
@@ -115,11 +113,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -115,11 +113,12 @@ namespace Titanium.Web.Proxy.Http
{
{
if
(
isTransparent
||
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
if
(
isTransparent
||
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
{
{
await
header
.
WriteToStreamAsync
(
writer
,
cancellationToken
);
header
.
Write
(
headerBuilder
);
}
}
}
}
await
writer
.
WriteLineAsync
(
cancellationToken
);
headerBuilder
.
AppendLine
();
await
writer
.
WriteAsync
(
headerBuilder
.
ToString
(),
cancellationToken
);
if
(
enable100ContinueBehaviour
)
if
(
enable100ContinueBehaviour
)
{
{
...
...
Titanium.Web.Proxy/Models/HttpHeader.cs
View file @
e3775e03
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
namespace
Titanium.Web.Proxy.Models
namespace
Titanium.Web.Proxy.Models
...
@@ -64,11 +61,9 @@ namespace Titanium.Web.Proxy.Models
...
@@ -64,11 +61,9 @@ namespace Titanium.Web.Proxy.Models
return
result
;
return
result
;
}
}
internal
async
Task
WriteToStreamAsync
(
HttpWriter
writer
,
CancellationToken
cancellationToken
)
internal
void
Write
(
StringBuilder
writer
)
{
{
await
writer
.
WriteAsync
(
Name
,
cancellationToken
);
writer
.
AppendLine
(
$"
{
Name
}
:
{
Value
}
"
);
await
writer
.
WriteAsync
(
": "
,
cancellationToken
);
await
writer
.
WriteLineAsync
(
Value
,
cancellationToken
);
}
}
}
}
}
}
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