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
67bfa3bc
Commit
67bfa3bc
authored
Aug 23, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor new line
parent
2774ac08
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
30 deletions
+33
-30
HttpWriter.cs
Titanium.Web.Proxy/Helpers/HttpWriter.cs
+3
-3
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+5
-7
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+3
-3
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+3
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+3
-11
ProxyConstants.cs
Titanium.Web.Proxy/Shared/ProxyConstants.cs
+16
-3
No files found.
Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
67bfa3bc
...
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Helpers
private
readonly
Stream
stream
;
private
readonly
IBufferPool
bufferPool
;
private
static
readonly
byte
[]
newLine
=
ProxyConstants
.
NewLine
;
private
static
readonly
byte
[]
newLine
=
ProxyConstants
.
NewLine
Bytes
;
private
static
readonly
Encoder
encoder
=
Encoding
.
ASCII
.
GetEncoder
();
...
...
@@ -109,9 +109,9 @@ namespace Titanium.Web.Proxy.Helpers
var
headerBuilder
=
new
StringBuilder
();
foreach
(
var
header
in
headers
)
{
headerBuilder
.
Append
Line
(
header
.
ToString
()
);
headerBuilder
.
Append
(
$"
{
header
.
ToString
()}{
ProxyConstants
.
NewLine
}
"
);
}
headerBuilder
.
Append
Line
(
);
headerBuilder
.
Append
(
ProxyConstants
.
NewLine
);
await
WriteAsync
(
headerBuilder
.
ToString
(),
cancellationToken
);
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
67bfa3bc
...
...
@@ -8,6 +8,7 @@ using Titanium.Web.Proxy.Exceptions;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Http
{
...
...
@@ -16,8 +17,6 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public
class
HttpWebClient
{
private
const
string
CRLF
=
"\r\n"
;
internal
HttpWebClient
(
Request
request
=
null
,
Response
response
=
null
)
{
Request
=
request
??
new
Request
();
...
...
@@ -111,9 +110,8 @@ namespace Titanium.Web.Proxy.Http
&&
!
string
.
IsNullOrEmpty
(
upstreamProxy
.
UserName
)
&&
upstreamProxy
.
Password
!=
null
)
{
headerBuilder
.
AppendFormat
(
"{0}{1}"
,
HttpHeader
.
ProxyConnectionKeepAlive
,
CRLF
);
headerBuilder
.
AppendFormat
(
"{0}{1}"
,
HttpHeader
.
GetProxyAuthorizationHeader
(
upstreamProxy
.
UserName
,
upstreamProxy
.
Password
),
CRLF
);
headerBuilder
.
Append
(
$"
{
HttpHeader
.
ProxyConnectionKeepAlive
}{
ProxyConstants
.
NewLine
}
"
);
headerBuilder
.
Append
(
$"
{
HttpHeader
.
GetProxyAuthorizationHeader
(
upstreamProxy
.
UserName
,
upstreamProxy
.
Password
)}{
ProxyConstants
.
NewLine
}
"
);
}
// write request headers
...
...
@@ -121,11 +119,11 @@ namespace Titanium.Web.Proxy.Http
{
if
(
isTransparent
||
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
{
headerBuilder
.
Append
Format
(
"{0}{1}"
,
header
,
CRLF
);
headerBuilder
.
Append
(
$"
{
header
}{
ProxyConstants
.
NewLine
}
"
);
}
}
headerBuilder
.
Append
(
CRLF
);
headerBuilder
.
Append
(
ProxyConstants
.
NewLine
);
await
writer
.
WriteAsync
(
headerBuilder
.
ToString
(),
cancellationToken
);
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
67bfa3bc
...
...
@@ -140,13 +140,13 @@ namespace Titanium.Web.Proxy.Http
get
{
var
sb
=
new
StringBuilder
();
sb
.
Append
Line
(
CreateRequestLine
(
Method
,
OriginalUrl
,
HttpVersion
)
);
sb
.
Append
(
$"
{
CreateRequestLine
(
Method
,
OriginalUrl
,
HttpVersion
)}{
ProxyConstants
.
NewLine
}
"
);
foreach
(
var
header
in
Headers
)
{
sb
.
Append
Line
(
header
.
ToString
()
);
sb
.
Append
(
$"
{
header
.
ToString
()}{
ProxyConstants
.
NewLine
}
"
);
}
sb
.
Append
Line
(
);
sb
.
Append
(
ProxyConstants
.
NewLine
);
return
sb
.
ToString
();
}
}
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
67bfa3bc
...
...
@@ -110,13 +110,13 @@ namespace Titanium.Web.Proxy.Http
get
{
var
sb
=
new
StringBuilder
();
sb
.
Append
Line
(
CreateResponseLine
(
HttpVersion
,
StatusCode
,
StatusDescription
)
);
sb
.
Append
(
$"
{
CreateResponseLine
(
HttpVersion
,
StatusCode
,
StatusDescription
)}{
ProxyConstants
.
NewLine
}
"
);
foreach
(
var
header
in
Headers
)
{
sb
.
Append
Line
(
header
.
ToString
()
);
sb
.
Append
(
$"
{
header
.
ToString
()}{
ProxyConstants
.
NewLine
}
"
);
}
sb
.
Append
Line
(
);
sb
.
Append
(
ProxyConstants
.
NewLine
);
return
sb
.
ToString
();
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
67bfa3bc
...
...
@@ -16,6 +16,7 @@ using Titanium.Web.Proxy.Helpers;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy
{
...
...
@@ -24,15 +25,6 @@ namespace Titanium.Web.Proxy
/// </summary>
public
partial
class
ProxyServer
{
private
static
readonly
Regex
uriSchemeRegex
=
new
Regex
(
"^[a-z]*://"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Compiled
);
private
static
readonly
HashSet
<
string
>
proxySupportedCompressions
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
"gzip"
,
"deflate"
};
private
bool
isWindowsAuthenticationEnabledAndSupported
=>
EnableWinAuth
&&
RunTime
.
IsWindows
&&
!
RunTime
.
IsRunningOnMono
;
...
...
@@ -96,7 +88,7 @@ namespace Titanium.Web.Proxy
cancellationToken
);
Uri
httpRemoteUri
;
if
(
u
riSchemeRegex
.
IsMatch
(
httpUrl
))
if
(
ProxyConstants
.
U
riSchemeRegex
.
IsMatch
(
httpUrl
))
{
try
{
...
...
@@ -400,7 +392,7 @@ namespace Titanium.Web.Proxy
//only allow proxy supported compressions
supportedAcceptEncoding
.
AddRange
(
acceptEncoding
.
Split
(
','
)
.
Select
(
x
=>
x
.
Trim
())
.
Where
(
x
=>
p
roxySupportedCompressions
.
Contains
(
x
)));
.
Where
(
x
=>
ProxyConstants
.
P
roxySupportedCompressions
.
Contains
(
x
)));
//uncompressed is always supported by proxy
supportedAcceptEncoding
.
Add
(
"identity"
);
...
...
Titanium.Web.Proxy/Shared/ProxyConstants.cs
View file @
67bfa3bc
using
System.Text.RegularExpressions
;
using
System
;
using
System.Collections.Generic
;
using
System.Text.RegularExpressions
;
namespace
Titanium.Web.Proxy.Shared
{
...
...
@@ -14,9 +16,20 @@ namespace Titanium.Web.Proxy.Shared
internal
static
readonly
char
[]
SemiColonSplit
=
{
';'
};
internal
static
readonly
char
[]
EqualSplit
=
{
'='
};
internal
static
readonly
byte
[]
NewLine
=
{
(
byte
)
'\r'
,
(
byte
)
'\n'
};
internal
static
readonly
string
NewLine
=
"\r\n"
;
internal
static
readonly
byte
[]
NewLineBytes
=
{
(
byte
)
'\r'
,
(
byte
)
'\n'
};
public
static
readonly
Regex
CNRemoverRegex
=
internal
static
readonly
Regex
UriSchemeRegex
=
new
Regex
(
"^[a-z]*://"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Compiled
);
internal
static
readonly
HashSet
<
string
>
ProxySupportedCompressions
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
"gzip"
,
"deflate"
};
internal
static
readonly
Regex
CNRemoverRegex
=
new
Regex
(
@"^CN\s*=\s*"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Compiled
);
}
}
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