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
9d037680
Commit
9d037680
authored
Dec 31, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http headers names moved to constants
parent
5829ff32
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
131 additions
and
62 deletions
+131
-62
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-1
HttpHelper.cs
Titanium.Web.Proxy/Helpers/HttpHelper.cs
+3
-2
ConnectResponse.cs
Titanium.Web.Proxy/Http/ConnectResponse.cs
+1
-1
HeaderCollection.cs
Titanium.Web.Proxy/Http/HeaderCollection.cs
+19
-6
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+1
-1
KnownHeaders.cs
Titanium.Web.Proxy/Http/KnownHeaders.cs
+53
-0
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+16
-16
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+11
-11
HttpHeader.cs
Titanium.Web.Proxy/Models/HttpHeader.cs
+2
-1
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+3
-2
ProxyAuthorizationHandler.cs
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+12
-12
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+1
-2
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+8
-7
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
9d037680
...
@@ -586,7 +586,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -586,7 +586,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
var
response
=
new
RedirectResponse
();
var
response
=
new
RedirectResponse
();
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Headers
.
AddHeader
(
"Location"
,
url
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
Location
,
url
);
response
.
Body
=
emptyData
;
response
.
Body
=
emptyData
;
await
Respond
(
response
);
await
Respond
(
response
);
...
...
Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
9d037680
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Shared
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
...
@@ -28,7 +29,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -28,7 +29,7 @@ namespace Titanium.Web.Proxy.Helpers
foreach
(
string
parameter
in
parameters
)
foreach
(
string
parameter
in
parameters
)
{
{
var
split
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
var
split
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
if
(
split
.
Length
==
2
&&
split
[
0
].
Trim
().
Equals
(
"charset"
,
StringComparison
.
CurrentCultureIgnoreCase
))
if
(
split
.
Length
==
2
&&
split
[
0
].
Trim
().
Equals
(
KnownHeaders
.
ContentTypeCharset
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
{
string
value
=
split
[
1
];
string
value
=
split
[
1
];
if
(
value
.
Equals
(
"x-user-defined"
,
StringComparison
.
OrdinalIgnoreCase
))
if
(
value
.
Equals
(
"x-user-defined"
,
StringComparison
.
OrdinalIgnoreCase
))
...
@@ -65,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -65,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
foreach
(
string
parameter
in
parameters
)
foreach
(
string
parameter
in
parameters
)
{
{
var
split
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
var
split
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
if
(
split
.
Length
==
2
&&
split
[
0
].
Trim
().
Equals
(
"boundary"
,
StringComparison
.
CurrentCultureIgnoreCase
))
if
(
split
.
Length
==
2
&&
split
[
0
].
Trim
().
Equals
(
KnownHeaders
.
ContentTypeBoundary
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
{
string
value
=
split
[
1
];
string
value
=
split
[
1
];
if
(
value
.
Length
>
2
&&
value
[
0
]
==
'"'
&&
value
[
value
.
Length
-
1
]
==
'"'
)
if
(
value
.
Length
>
2
&&
value
[
0
]
==
'"'
&&
value
[
value
.
Length
-
1
]
==
'"'
)
...
...
Titanium.Web.Proxy/Http/ConnectResponse.cs
View file @
9d037680
...
@@ -22,7 +22,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -22,7 +22,7 @@ namespace Titanium.Web.Proxy.Http
StatusDescription
=
"Connection Established"
StatusDescription
=
"Connection Established"
};
};
response
.
Headers
.
AddHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
());
response
.
Headers
.
AddHeader
(
KnownHeaders
.
Timestamp
,
DateTime
.
Now
.
ToString
());
return
response
;
return
response
;
}
}
}
}
...
...
Titanium.Web.Proxy/Http/HeaderCollection.cs
View file @
9d037680
...
@@ -63,6 +63,21 @@ namespace Titanium.Web.Proxy.Http
...
@@ -63,6 +63,21 @@ namespace Titanium.Web.Proxy.Http
return
null
;
return
null
;
}
}
public
HttpHeader
GetFirstHeader
(
string
name
)
{
if
(
Headers
.
TryGetValue
(
name
,
out
var
header
))
{
return
header
;
}
if
(
NonUniqueHeaders
.
TryGetValue
(
name
,
out
var
headers
))
{
return
headers
.
FirstOrDefault
();
}
return
null
;
}
/// <summary>
/// <summary>
/// Returns all headers
/// Returns all headers
/// </summary>
/// </summary>
...
@@ -235,7 +250,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -235,7 +250,7 @@ namespace Titanium.Web.Proxy.Http
return
null
;
return
null
;
}
}
internal
string
SetOrAddHeaderValue
(
string
headerName
,
string
value
)
internal
void
SetOrAddHeaderValue
(
string
headerName
,
string
value
)
{
{
if
(
Headers
.
TryGetValue
(
headerName
,
out
var
header
))
if
(
Headers
.
TryGetValue
(
headerName
,
out
var
header
))
{
{
...
@@ -245,8 +260,6 @@ namespace Titanium.Web.Proxy.Http
...
@@ -245,8 +260,6 @@ namespace Titanium.Web.Proxy.Http
{
{
Headers
.
Add
(
headerName
,
new
HttpHeader
(
headerName
,
value
));
Headers
.
Add
(
headerName
,
new
HttpHeader
(
headerName
,
value
));
}
}
return
null
;
}
}
/// <summary>
/// <summary>
...
@@ -255,12 +268,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -255,12 +268,12 @@ namespace Titanium.Web.Proxy.Http
internal
void
FixProxyHeaders
()
internal
void
FixProxyHeaders
()
{
{
//If proxy-connection close was returned inform to close the connection
//If proxy-connection close was returned inform to close the connection
string
proxyHeader
=
GetHeaderValueOrNull
(
"proxy-connection"
);
string
proxyHeader
=
GetHeaderValueOrNull
(
KnownHeaders
.
ProxyConnection
);
RemoveHeader
(
"proxy-connection"
);
RemoveHeader
(
KnownHeaders
.
ProxyConnection
);
if
(
proxyHeader
!=
null
)
if
(
proxyHeader
!=
null
)
{
{
SetOrAddHeaderValue
(
"connection"
,
proxyHeader
);
SetOrAddHeaderValue
(
KnownHeaders
.
Connection
,
proxyHeader
);
}
}
}
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
9d037680
...
@@ -105,7 +105,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -105,7 +105,7 @@ namespace Titanium.Web.Proxy.Http
//write request headers
//write request headers
foreach
(
var
header
in
Request
.
Headers
)
foreach
(
var
header
in
Request
.
Headers
)
{
{
if
(
header
.
Name
!=
"Proxy-Authorization"
)
if
(
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
{
{
await
header
.
WriteToStreamAsync
(
writer
);
await
header
.
WriteToStreamAsync
(
writer
);
}
}
...
...
Titanium.Web.Proxy/Http/KnownHeaders.cs
0 → 100644
View file @
9d037680
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.Http
{
public
static
class
KnownHeaders
{
// Both
public
const
string
Connection
=
"connection"
;
public
const
string
ConnectionClose
=
"close"
;
public
const
string
ConnectionKeepAlive
=
"keep-alive"
;
public
const
string
ContentLength
=
"content-length"
;
public
const
string
ContentType
=
"content-type"
;
public
const
string
ContentTypeCharset
=
"charset"
;
public
const
string
ContentTypeBoundary
=
"boundary"
;
public
const
string
Upgrade
=
"upgrade"
;
public
const
string
UpgradeWebsocket
=
"websocket"
;
// Request headers
public
const
string
AcceptEncoding
=
"accept-encoding"
;
public
const
string
Authorization
=
"Authorization"
;
public
const
string
Expect
=
"expect"
;
public
const
string
Expect100Continue
=
"100-continue"
;
public
const
string
Host
=
"host"
;
public
const
string
ProxyAuthorization
=
"Proxy-Authorization"
;
public
const
string
ProxyConnection
=
"Proxy-Connection"
;
public
const
string
ProxyConnectionClose
=
"close"
;
// Response headers
public
const
string
ContentEncoding
=
"content-encoding"
;
public
const
string
Location
=
"Location"
;
public
const
string
ProxyAuthenticate
=
"Proxy-Authenticate"
;
public
const
string
TransferEncoding
=
"transfer-encoding"
;
public
const
string
TransferEncodingChunked
=
"chunked"
;
// ???
public
const
string
Timestamp
=
"Timestamp"
;
}
}
Titanium.Web.Proxy/Http/Request.cs
View file @
9d037680
...
@@ -67,14 +67,14 @@ namespace Titanium.Web.Proxy.Http
...
@@ -67,14 +67,14 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
string
Host
public
string
Host
{
{
get
=>
Headers
.
GetHeaderValueOrNull
(
"host"
);
get
=>
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
Host
);
set
=>
Headers
.
SetOrAddHeaderValue
(
"host"
,
value
);
set
=>
Headers
.
SetOrAddHeaderValue
(
KnownHeaders
.
Host
,
value
);
}
}
/// <summary>
/// <summary>
/// Content encoding header value
/// Content encoding header value
/// </summary>
/// </summary>
public
string
ContentEncoding
=>
Headers
.
GetHeaderValueOrNull
(
"content-encoding"
);
public
string
ContentEncoding
=>
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
ContentEncoding
);
/// <summary>
/// <summary>
/// Request content-length
/// Request content-length
...
@@ -83,7 +83,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -83,7 +83,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"content-length"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
ContentLength
);
if
(
headerValue
==
null
)
if
(
headerValue
==
null
)
{
{
...
@@ -102,12 +102,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -102,12 +102,12 @@ namespace Titanium.Web.Proxy.Http
{
{
if
(
value
>=
0
)
if
(
value
>=
0
)
{
{
Headers
.
SetOrAddHeaderValue
(
"content-length"
,
value
.
ToString
());
Headers
.
SetOrAddHeaderValue
(
KnownHeaders
.
ContentLength
,
value
.
ToString
());
IsChunked
=
false
;
IsChunked
=
false
;
}
}
else
else
{
{
Headers
.
RemoveHeader
(
"content-length"
);
Headers
.
RemoveHeader
(
KnownHeaders
.
ContentLength
);
}
}
}
}
}
}
...
@@ -117,8 +117,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -117,8 +117,8 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
string
ContentType
public
string
ContentType
{
{
get
=>
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
get
=>
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
ContentType
);
set
=>
Headers
.
SetOrAddHeaderValue
(
"content-type"
,
value
);
set
=>
Headers
.
SetOrAddHeaderValue
(
KnownHeaders
.
ContentType
,
value
);
}
}
/// <summary>
/// <summary>
...
@@ -128,19 +128,19 @@ namespace Titanium.Web.Proxy.Http
...
@@ -128,19 +128,19 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"transfer-encoding"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
TransferEncoding
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
"chunked"
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
KnownHeaders
.
TransferEncodingChunked
);
}
}
set
set
{
{
if
(
value
)
if
(
value
)
{
{
Headers
.
SetOrAddHeaderValue
(
"transfer-encoding"
,
"chunked"
);
Headers
.
SetOrAddHeaderValue
(
KnownHeaders
.
TransferEncoding
,
KnownHeaders
.
TransferEncodingChunked
);
ContentLength
=
-
1
;
ContentLength
=
-
1
;
}
}
else
else
{
{
Headers
.
RemoveHeader
(
"transfer-encoding"
);
Headers
.
RemoveHeader
(
KnownHeaders
.
TransferEncoding
);
}
}
}
}
}
}
...
@@ -152,8 +152,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -152,8 +152,8 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"expect"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
Expect
);
return
headerValue
!=
null
&&
headerValue
.
Equals
(
"100-continue"
);
return
headerValue
!=
null
&&
headerValue
.
Equals
(
KnownHeaders
.
Expect100Continue
);
}
}
}
}
...
@@ -241,14 +241,14 @@ namespace Titanium.Web.Proxy.Http
...
@@ -241,14 +241,14 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"upgrade"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
Upgrade
);
if
(
headerValue
==
null
)
if
(
headerValue
==
null
)
{
{
return
false
;
return
false
;
}
}
return
headerValue
.
Equals
(
"websocket"
,
StringComparison
.
CurrentCultureIgnoreCase
);
return
headerValue
.
Equals
(
KnownHeaders
.
UpgradeWebsocket
,
StringComparison
.
CurrentCultureIgnoreCase
);
}
}
}
}
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
9d037680
...
@@ -42,7 +42,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -42,7 +42,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Content encoding for this response
/// Content encoding for this response
/// </summary>
/// </summary>
public
string
ContentEncoding
=>
Headers
.
GetHeaderValueOrNull
(
"content-encoding"
)?.
Trim
();
public
string
ContentEncoding
=>
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
ContentEncoding
)?.
Trim
();
/// <summary>
/// <summary>
/// Http version
/// Http version
...
@@ -94,11 +94,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -94,11 +94,11 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"connection"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
Connection
);
if
(
headerValue
!=
null
)
if
(
headerValue
!=
null
)
{
{
if
(
headerValue
.
ContainsIgnoreCase
(
"close"
))
if
(
headerValue
.
ContainsIgnoreCase
(
KnownHeaders
.
ConnectionClose
))
{
{
return
false
;
return
false
;
}
}
...
@@ -111,7 +111,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -111,7 +111,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Content type of this response
/// Content type of this response
/// </summary>
/// </summary>
public
string
ContentType
=>
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
public
string
ContentType
=>
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
ContentType
);
/// <summary>
/// <summary>
/// Length of response body
/// Length of response body
...
@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"content-length"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
ContentLength
);
if
(
headerValue
==
null
)
if
(
headerValue
==
null
)
{
{
...
@@ -138,12 +138,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -138,12 +138,12 @@ namespace Titanium.Web.Proxy.Http
{
{
if
(
value
>=
0
)
if
(
value
>=
0
)
{
{
Headers
.
SetOrAddHeaderValue
(
"content-length"
,
value
.
ToString
());
Headers
.
SetOrAddHeaderValue
(
KnownHeaders
.
ContentLength
,
value
.
ToString
());
IsChunked
=
false
;
IsChunked
=
false
;
}
}
else
else
{
{
Headers
.
RemoveHeader
(
"content-length"
);
Headers
.
RemoveHeader
(
KnownHeaders
.
ContentLength
);
}
}
}
}
}
}
...
@@ -155,19 +155,19 @@ namespace Titanium.Web.Proxy.Http
...
@@ -155,19 +155,19 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"transfer-encoding"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
KnownHeaders
.
TransferEncoding
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
"chunked"
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
KnownHeaders
.
TransferEncodingChunked
);
}
}
set
set
{
{
if
(
value
)
if
(
value
)
{
{
Headers
.
SetOrAddHeaderValue
(
"transfer-encoding"
,
"chunked"
);
Headers
.
SetOrAddHeaderValue
(
KnownHeaders
.
TransferEncoding
,
KnownHeaders
.
TransferEncodingChunked
);
ContentLength
=
-
1
;
ContentLength
=
-
1
;
}
}
else
else
{
{
Headers
.
RemoveHeader
(
"transfer-encoding"
);
Headers
.
RemoveHeader
(
KnownHeaders
.
TransferEncoding
);
}
}
}
}
}
}
...
...
Titanium.Web.Proxy/Models/HttpHeader.cs
View file @
9d037680
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
namespace
Titanium.Web.Proxy.Models
namespace
Titanium.Web.Proxy.Models
{
{
...
@@ -56,7 +57,7 @@ namespace Titanium.Web.Proxy.Models
...
@@ -56,7 +57,7 @@ namespace Titanium.Web.Proxy.Models
internal
static
HttpHeader
GetProxyAuthorizationHeader
(
string
userName
,
string
password
)
internal
static
HttpHeader
GetProxyAuthorizationHeader
(
string
userName
,
string
password
)
{
{
var
result
=
new
HttpHeader
(
"Proxy-Authorization"
,
var
result
=
new
HttpHeader
(
KnownHeaders
.
ProxyAuthorization
,
"Basic "
+
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
$"
{
userName
}
:
{
password
}
"
)));
"Basic "
+
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
$"
{
userName
}
:
{
password
}
"
)));
return
result
;
return
result
;
}
}
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
9d037680
...
@@ -8,6 +8,7 @@ using System.Text;
...
@@ -8,6 +8,7 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.Network.Tcp
namespace
Titanium.Web.Proxy.Network.Tcp
...
@@ -71,12 +72,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -71,12 +72,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
var
writer
=
new
HttpRequestWriter
(
stream
,
server
.
BufferSize
);
var
writer
=
new
HttpRequestWriter
(
stream
,
server
.
BufferSize
);
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
(
"Connection: Keep-Alive
"
);
await
writer
.
WriteLineAsync
(
$"
{
KnownHeaders
.
Connection
}
:
{
KnownHeaders
.
ConnectionKeepAlive
}
"
);
if
(!
string
.
IsNullOrEmpty
(
externalProxy
.
UserName
)
&&
externalProxy
.
Password
!=
null
)
if
(!
string
.
IsNullOrEmpty
(
externalProxy
.
UserName
)
&&
externalProxy
.
Password
!=
null
)
{
{
await
HttpHeader
.
ProxyConnectionKeepAlive
.
WriteToStreamAsync
(
writer
);
await
HttpHeader
.
ProxyConnectionKeepAlive
.
WriteToStreamAsync
(
writer
);
await
writer
.
WriteLineAsync
(
"Proxy-Authorization"
+
": Basic "
+
await
writer
.
WriteLineAsync
(
KnownHeaders
.
ProxyAuthorization
+
": Basic "
+
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
externalProxy
.
UserName
+
":"
+
externalProxy
.
Password
)));
externalProxy
.
UserName
+
":"
+
externalProxy
.
Password
)));
}
}
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
9d037680
...
@@ -8,6 +8,7 @@ using Titanium.Web.Proxy.Exceptions;
...
@@ -8,6 +8,7 @@ using Titanium.Web.Proxy.Exceptions;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
...
@@ -20,37 +21,36 @@ namespace Titanium.Web.Proxy
...
@@ -20,37 +21,36 @@ namespace Titanium.Web.Proxy
return
true
;
return
true
;
}
}
var
httpHeaders
=
session
.
WebSession
.
Request
.
Headers
.
ToArray
()
;
var
httpHeaders
=
session
.
WebSession
.
Request
.
Headers
;
try
try
{
{
var
header
=
httpHeaders
.
FirstOrDefault
(
t
=>
t
.
Name
==
"Proxy-Authorization"
);
var
header
=
httpHeaders
.
GetFirstHeader
(
KnownHeaders
.
ProxyAuthorization
);
if
(
header
==
null
)
if
(
header
==
null
)
{
{
session
.
WebSession
.
Response
=
await
SendAuthentication407Response
(
clientStreamWriter
,
"Proxy Authentication Required"
);
session
.
WebSession
.
Response
=
await
SendAuthentication407Response
(
clientStreamWriter
,
"Proxy Authentication Required"
);
return
false
;
return
false
;
}
}
string
headerValue
=
header
.
Value
.
Trim
(
);
var
headerValueParts
=
header
.
Value
.
Split
(
ProxyConstants
.
SpaceSplit
);
if
(
!
headerValue
.
StartsWith
(
"basic"
,
StringComparison
.
CurrentCultureIgnoreCase
))
if
(
headerValueParts
.
Length
!=
2
||
!
headerValueParts
[
0
].
Equals
(
"basic"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
{
//Return not authorized
//Return not authorized
session
.
WebSession
.
Response
=
await
SendAuthentication407Response
(
clientStreamWriter
,
"Proxy Authentication Invalid"
);
session
.
WebSession
.
Response
=
await
SendAuthentication407Response
(
clientStreamWriter
,
"Proxy Authentication Invalid"
);
return
false
;
return
false
;
}
}
headerValue
=
headerValue
.
Substring
(
5
).
Trim
();
string
decoded
=
Encoding
.
UTF8
.
GetString
(
Convert
.
FromBase64String
(
headerValueParts
[
1
]));
int
colonIndex
=
decoded
.
IndexOf
(
':'
);
string
decoded
=
Encoding
.
UTF8
.
GetString
(
Convert
.
FromBase64String
(
headerValue
));
if
(
colonIndex
==
-
1
)
if
(
decoded
.
Contains
(
":"
)
==
false
)
{
{
//Return not authorized
//Return not authorized
session
.
WebSession
.
Response
=
await
SendAuthentication407Response
(
clientStreamWriter
,
"Proxy Authentication Invalid"
);
session
.
WebSession
.
Response
=
await
SendAuthentication407Response
(
clientStreamWriter
,
"Proxy Authentication Invalid"
);
return
false
;
return
false
;
}
}
string
username
=
decoded
.
Substring
(
0
,
decoded
.
IndexOf
(
':'
)
);
string
username
=
decoded
.
Substring
(
0
,
colonIndex
);
string
password
=
decoded
.
Substring
(
decoded
.
IndexOf
(
':'
)
+
1
);
string
password
=
decoded
.
Substring
(
colonIndex
+
1
);
return
await
AuthenticateUserFunc
(
username
,
password
);
return
await
AuthenticateUserFunc
(
username
,
password
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
...
@@ -72,8 +72,8 @@ namespace Titanium.Web.Proxy
...
@@ -72,8 +72,8 @@ namespace Titanium.Web.Proxy
StatusDescription
=
description
StatusDescription
=
description
};
};
response
.
Headers
.
AddHeader
(
"Proxy-Authenticate"
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyAuthenticate
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Headers
.
AddHeader
(
"Proxy-Connection"
,
"close"
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyConnection
,
KnownHeaders
.
ProxyConnectionClose
);
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
return
response
;
return
response
;
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
9d037680
...
@@ -6,7 +6,6 @@ using System.Net.Sockets;
...
@@ -6,7 +6,6 @@ using System.Net.Sockets;
using
System.Security.Authentication
;
using
System.Security.Authentication
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
;
using
StreamExtended
;
using
StreamExtended.Helpers
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Exceptions
;
...
@@ -597,7 +596,7 @@ namespace Titanium.Web.Proxy
...
@@ -597,7 +596,7 @@ namespace Titanium.Web.Proxy
switch
(
header
.
Name
.
ToLower
())
switch
(
header
.
Name
.
ToLower
())
{
{
//these are the only encoding this proxy can read
//these are the only encoding this proxy can read
case
"accept-encoding"
:
case
KnownHeaders
.
AcceptEncoding
:
header
.
Value
=
"gzip,deflate"
;
header
.
Value
=
"gzip,deflate"
;
break
;
break
;
}
}
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
9d037680
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.WinAuth
;
using
Titanium.Web.Proxy.Network.WinAuth
;
...
@@ -84,9 +85,9 @@ namespace Titanium.Web.Proxy
...
@@ -84,9 +85,9 @@ namespace Titanium.Web.Proxy
string
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
Equals
(
x
,
StringComparison
.
OrdinalIgnoreCase
));
string
scheme
=
authSchemes
.
FirstOrDefault
(
x
=>
authHeader
.
Value
.
Equals
(
x
,
StringComparison
.
OrdinalIgnoreCase
));
//clear any existing headers to avoid confusing bad servers
//clear any existing headers to avoid confusing bad servers
if
(
args
.
WebSession
.
Request
.
Headers
.
NonUniqueHeaders
.
ContainsKey
(
"Authorization"
))
if
(
args
.
WebSession
.
Request
.
Headers
.
NonUniqueHeaders
.
ContainsKey
(
KnownHeaders
.
Authorization
))
{
{
args
.
WebSession
.
Request
.
Headers
.
NonUniqueHeaders
.
Remove
(
"Authorization"
);
args
.
WebSession
.
Request
.
Headers
.
NonUniqueHeaders
.
Remove
(
KnownHeaders
.
Authorization
);
}
}
//initial value will match exactly any of the schemes
//initial value will match exactly any of the schemes
...
@@ -94,16 +95,16 @@ namespace Titanium.Web.Proxy
...
@@ -94,16 +95,16 @@ namespace Titanium.Web.Proxy
{
{
string
clientToken
=
WinAuthHandler
.
GetInitialAuthToken
(
args
.
WebSession
.
Request
.
Host
,
scheme
,
args
.
Id
);
string
clientToken
=
WinAuthHandler
.
GetInitialAuthToken
(
args
.
WebSession
.
Request
.
Host
,
scheme
,
args
.
Id
);
var
auth
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
var
auth
=
new
HttpHeader
(
KnownHeaders
.
Authorization
,
string
.
Concat
(
scheme
,
clientToken
));
//replace existing authorization header if any
//replace existing authorization header if any
if
(
args
.
WebSession
.
Request
.
Headers
.
Headers
.
ContainsKey
(
"Authorization"
))
if
(
args
.
WebSession
.
Request
.
Headers
.
Headers
.
ContainsKey
(
KnownHeaders
.
Authorization
))
{
{
args
.
WebSession
.
Request
.
Headers
.
Headers
[
"Authorization"
]
=
auth
;
args
.
WebSession
.
Request
.
Headers
.
Headers
[
KnownHeaders
.
Authorization
]
=
auth
;
}
}
else
else
{
{
args
.
WebSession
.
Request
.
Headers
.
Headers
.
Add
(
"Authorization"
,
auth
);
args
.
WebSession
.
Request
.
Headers
.
Headers
.
Add
(
KnownHeaders
.
Authorization
,
auth
);
}
}
//don't need to send body for Authorization request
//don't need to send body for Authorization request
...
@@ -122,7 +123,7 @@ namespace Titanium.Web.Proxy
...
@@ -122,7 +123,7 @@ namespace Titanium.Web.Proxy
string
clientToken
=
WinAuthHandler
.
GetFinalAuthToken
(
args
.
WebSession
.
Request
.
Host
,
serverToken
,
args
.
Id
);
string
clientToken
=
WinAuthHandler
.
GetFinalAuthToken
(
args
.
WebSession
.
Request
.
Host
,
serverToken
,
args
.
Id
);
//there will be an existing header from initial client request
//there will be an existing header from initial client request
args
.
WebSession
.
Request
.
Headers
.
Headers
[
"Authorization"
]
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
args
.
WebSession
.
Request
.
Headers
.
Headers
[
KnownHeaders
.
Authorization
]
=
new
HttpHeader
(
KnownHeaders
.
Authorization
,
string
.
Concat
(
scheme
,
clientToken
));
//send body for final auth request
//send body for final auth request
if
(
args
.
WebSession
.
Request
.
HasBody
)
if
(
args
.
WebSession
.
Request
.
HasBody
)
...
...
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