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
730d4866
Commit
730d4866
authored
Nov 16, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Request, Response Properties renamed
C# language changed to C# 7.1
parent
8faf2835
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
174 additions
and
174 deletions
+174
-174
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+3
-3
Titanium.Web.Proxy.Examples.Basic.csproj
...y.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
+1
-1
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+4
-4
SessionListItem.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs
+1
-1
Titanium.Web.Proxy.Examples.Wpf.csproj
...Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
+1
-1
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+35
-35
HttpResponseWriter.cs
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
+3
-3
ConnectResponse.cs
Titanium.Web.Proxy/Http/ConnectResponse.cs
+3
-3
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+12
-12
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+30
-30
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+31
-31
GenericResponse.cs
Titanium.Web.Proxy/Http/Responses/GenericResponse.cs
+4
-4
OkResponse.cs
Titanium.Web.Proxy/Http/Responses/OkResponse.cs
+2
-2
RedirectResponse.cs
Titanium.Web.Proxy/Http/Responses/RedirectResponse.cs
+2
-2
ProxyAuthorizationHandler.cs
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+5
-5
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+15
-15
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+9
-9
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+12
-12
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
730d4866
...
@@ -147,7 +147,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -147,7 +147,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
Console
.
WriteLine
(
e
.
WebSession
.
Request
.
Url
);
Console
.
WriteLine
(
e
.
WebSession
.
Request
.
Url
);
//read request headers
//read request headers
requestHeaderHistory
[
e
.
Id
]
=
e
.
WebSession
.
Request
.
Request
Headers
;
requestHeaderHistory
[
e
.
Id
]
=
e
.
WebSession
.
Request
.
Headers
;
if
(
e
.
WebSession
.
Request
.
HasBody
)
if
(
e
.
WebSession
.
Request
.
HasBody
)
{
{
...
@@ -194,7 +194,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -194,7 +194,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//}
//}
//read response headers
//read response headers
responseHeaderHistory
[
e
.
Id
]
=
e
.
WebSession
.
Response
.
Response
Headers
;
responseHeaderHistory
[
e
.
Id
]
=
e
.
WebSession
.
Response
.
Headers
;
// print out process id of current session
// print out process id of current session
//Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}");
//Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}");
...
@@ -202,7 +202,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -202,7 +202,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
//if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
if
(
e
.
WebSession
.
Request
.
Method
==
"GET"
||
e
.
WebSession
.
Request
.
Method
==
"POST"
)
if
(
e
.
WebSession
.
Request
.
Method
==
"GET"
||
e
.
WebSession
.
Request
.
Method
==
"POST"
)
{
{
if
(
e
.
WebSession
.
Response
.
Response
StatusCode
==
(
int
)
HttpStatusCode
.
OK
)
if
(
e
.
WebSession
.
Response
.
StatusCode
==
(
int
)
HttpStatusCode
.
OK
)
{
{
if
(
e
.
WebSession
.
Response
.
ContentType
!=
null
&&
e
.
WebSession
.
Response
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
if
(
e
.
WebSession
.
Response
.
ContentType
!=
null
&&
e
.
WebSession
.
Response
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
{
{
...
...
Examples/Titanium.Web.Proxy.Examples.Basic/Titanium.Web.Proxy.Examples.Basic.csproj
View file @
730d4866
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<OutputType>Exe</OutputType>
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>
6
</LangVersion>
<LangVersion>
7.1
</LangVersion>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup>
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
730d4866
...
@@ -122,7 +122,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -122,7 +122,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
if
(
e
.
WebSession
.
Request
.
HasBody
)
if
(
e
.
WebSession
.
Request
.
HasBody
)
{
{
e
.
WebSession
.
Request
.
Keep
Request
Body
=
true
;
e
.
WebSession
.
Request
.
KeepBody
=
true
;
await
e
.
GetRequestBody
();
await
e
.
GetRequestBody
();
}
}
}
}
...
@@ -144,7 +144,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -144,7 +144,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{
{
if
(
e
.
WebSession
.
Response
.
HasBody
)
if
(
e
.
WebSession
.
Response
.
HasBody
)
{
{
e
.
WebSession
.
Response
.
Keep
Response
Body
=
true
;
e
.
WebSession
.
Response
.
KeepBody
=
true
;
await
e
.
GetResponseBody
();
await
e
.
GetResponseBody
();
}
}
}
}
...
@@ -220,7 +220,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -220,7 +220,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
var
session
=
SelectedSession
.
WebSession
;
var
session
=
SelectedSession
.
WebSession
;
var
request
=
session
.
Request
;
var
request
=
session
.
Request
;
var
data
=
(
request
.
RequestBodyRead
?
request
.
Request
Body
:
null
)
??
new
byte
[
0
];
var
data
=
(
request
.
IsBodyRead
?
request
.
Body
:
null
)
??
new
byte
[
0
];
bool
truncated
=
data
.
Length
>
truncateLimit
;
bool
truncated
=
data
.
Length
>
truncateLimit
;
if
(
truncated
)
if
(
truncated
)
{
{
...
@@ -233,7 +233,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -233,7 +233,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
(
request
as
ConnectRequest
)?.
ClientHelloInfo
;
(
request
as
ConnectRequest
)?.
ClientHelloInfo
;
var
response
=
session
.
Response
;
var
response
=
session
.
Response
;
data
=
(
response
.
ResponseBodyRead
?
response
.
Response
Body
:
null
)
??
new
byte
[
0
];
data
=
(
response
.
IsBodyRead
?
response
.
Body
:
null
)
??
new
byte
[
0
];
truncated
=
data
.
Length
>
truncateLimit
;
truncated
=
data
.
Length
>
truncateLimit
;
if
(
truncated
)
if
(
truncated
)
{
{
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs
View file @
730d4866
...
@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{
{
var
request
=
WebSession
.
Request
;
var
request
=
WebSession
.
Request
;
var
response
=
WebSession
.
Response
;
var
response
=
WebSession
.
Response
;
int
statusCode
=
response
?.
Response
StatusCode
??
0
;
int
statusCode
=
response
?.
StatusCode
??
0
;
StatusCode
=
statusCode
==
0
?
"-"
:
statusCode
.
ToString
();
StatusCode
=
statusCode
==
0
?
"-"
:
statusCode
.
ToString
();
Protocol
=
request
.
RequestUri
.
Scheme
;
Protocol
=
request
.
RequestUri
.
Scheme
;
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
View file @
730d4866
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
<LangVersion>
6
</LangVersion>
<LangVersion>
7.1
</LangVersion>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<PlatformTarget>
AnyCPU
</PlatformTarget>
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
730d4866
...
@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments
get
{
return
reRequest
;
}
get
{
return
reRequest
;
}
set
set
{
{
if
(
WebSession
.
Response
.
Response
StatusCode
==
0
)
if
(
WebSession
.
Response
.
StatusCode
==
0
)
{
{
throw
new
Exception
(
"Response status code is empty. Cannot request again a request "
+
"which was never send to server."
);
throw
new
Exception
(
"Response status code is empty. Cannot request again a request "
+
"which was never send to server."
);
}
}
...
@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
//Caching check
//Caching check
if
(!
WebSession
.
Request
.
Request
BodyRead
)
if
(!
WebSession
.
Request
.
Is
BodyRead
)
{
{
//If chunked then its easy just read the whole body with the content length mentioned in the request header
//If chunked then its easy just read the whole body with the content length mentioned in the request header
using
(
var
requestBodyStream
=
new
MemoryStream
())
using
(
var
requestBodyStream
=
new
MemoryStream
())
...
@@ -173,13 +173,13 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -173,13 +173,13 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
}
}
WebSession
.
Request
.
Request
Body
=
await
GetDecompressedResponseBody
(
WebSession
.
Request
.
ContentEncoding
,
requestBodyStream
.
ToArray
());
WebSession
.
Request
.
Body
=
await
GetDecompressedResponseBody
(
WebSession
.
Request
.
ContentEncoding
,
requestBodyStream
.
ToArray
());
}
}
//Now set the flag to true
//Now set the flag to true
//So that next time we can deliver body from cache
//So that next time we can deliver body from cache
WebSession
.
Request
.
Request
BodyRead
=
true
;
WebSession
.
Request
.
Is
BodyRead
=
true
;
var
body
=
WebSession
.
Request
.
Request
Body
;
var
body
=
WebSession
.
Request
.
Body
;
OnDataSent
(
body
,
0
,
body
.
Length
);
OnDataSent
(
body
,
0
,
body
.
Length
);
}
}
}
}
...
@@ -215,7 +215,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -215,7 +215,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
//If not already read (not cached yet)
//If not already read (not cached yet)
if
(!
WebSession
.
Response
.
Response
BodyRead
)
if
(!
WebSession
.
Response
.
Is
BodyRead
)
{
{
if
(
WebSession
.
Response
.
HasBody
)
if
(
WebSession
.
Response
.
HasBody
)
{
{
...
@@ -240,17 +240,17 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -240,17 +240,17 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
}
}
WebSession
.
Response
.
Response
Body
=
await
GetDecompressedResponseBody
(
WebSession
.
Response
.
ContentEncoding
,
responseBodyStream
.
ToArray
());
WebSession
.
Response
.
Body
=
await
GetDecompressedResponseBody
(
WebSession
.
Response
.
ContentEncoding
,
responseBodyStream
.
ToArray
());
}
}
}
}
else
else
{
{
WebSession
.
Response
.
Response
Body
=
new
byte
[
0
];
WebSession
.
Response
.
Body
=
new
byte
[
0
];
}
}
//set this to true for caching
//set this to true for caching
WebSession
.
Response
.
Response
BodyRead
=
true
;
WebSession
.
Response
.
Is
BodyRead
=
true
;
var
body
=
WebSession
.
Response
.
Response
Body
;
var
body
=
WebSession
.
Response
.
Body
;
OnDataReceived
(
body
,
0
,
body
.
Length
);
OnDataReceived
(
body
,
0
,
body
.
Length
);
}
}
}
}
...
@@ -261,12 +261,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -261,12 +261,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
byte
[
]>
GetRequestBody
()
public
async
Task
<
byte
[
]>
GetRequestBody
()
{
{
if
(!
WebSession
.
Request
.
Request
BodyRead
)
if
(!
WebSession
.
Request
.
Is
BodyRead
)
{
{
await
ReadRequestBody
();
await
ReadRequestBody
();
}
}
return
WebSession
.
Request
.
Request
Body
;
return
WebSession
.
Request
.
Body
;
}
}
/// <summary>
/// <summary>
...
@@ -275,12 +275,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -275,12 +275,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
string
>
GetRequestBodyAsString
()
public
async
Task
<
string
>
GetRequestBodyAsString
()
{
{
if
(!
WebSession
.
Request
.
Request
BodyRead
)
if
(!
WebSession
.
Request
.
Is
BodyRead
)
{
{
await
ReadRequestBody
();
await
ReadRequestBody
();
}
}
return
WebSession
.
Request
.
Request
BodyString
;
return
WebSession
.
Request
.
BodyString
;
}
}
/// <summary>
/// <summary>
...
@@ -295,12 +295,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -295,12 +295,12 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
//syphon out the request body from client before setting the new body
//syphon out the request body from client before setting the new body
if
(!
WebSession
.
Request
.
Request
BodyRead
)
if
(!
WebSession
.
Request
.
Is
BodyRead
)
{
{
await
ReadRequestBody
();
await
ReadRequestBody
();
}
}
WebSession
.
Request
.
Request
Body
=
body
;
WebSession
.
Request
.
Body
=
body
;
WebSession
.
Request
.
ContentLength
=
WebSession
.
Request
.
IsChunked
?
-
1
:
body
.
Length
;
WebSession
.
Request
.
ContentLength
=
WebSession
.
Request
.
IsChunked
?
-
1
:
body
.
Length
;
}
}
...
@@ -316,7 +316,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -316,7 +316,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
//syphon out the request body from client before setting the new body
//syphon out the request body from client before setting the new body
if
(!
WebSession
.
Request
.
Request
BodyRead
)
if
(!
WebSession
.
Request
.
Is
BodyRead
)
{
{
await
ReadRequestBody
();
await
ReadRequestBody
();
}
}
...
@@ -330,12 +330,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -330,12 +330,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
byte
[
]>
GetResponseBody
()
public
async
Task
<
byte
[
]>
GetResponseBody
()
{
{
if
(!
WebSession
.
Response
.
Response
BodyRead
)
if
(!
WebSession
.
Response
.
Is
BodyRead
)
{
{
await
ReadResponseBody
();
await
ReadResponseBody
();
}
}
return
WebSession
.
Response
.
Response
Body
;
return
WebSession
.
Response
.
Body
;
}
}
/// <summary>
/// <summary>
...
@@ -344,12 +344,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -344,12 +344,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
string
>
GetResponseBodyAsString
()
public
async
Task
<
string
>
GetResponseBodyAsString
()
{
{
if
(!
WebSession
.
Response
.
Response
BodyRead
)
if
(!
WebSession
.
Response
.
Is
BodyRead
)
{
{
await
ReadResponseBody
();
await
ReadResponseBody
();
}
}
return
WebSession
.
Response
.
Response
BodyString
;
return
WebSession
.
Response
.
BodyString
;
}
}
/// <summary>
/// <summary>
...
@@ -364,12 +364,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -364,12 +364,12 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
//syphon out the response body from server before setting the new body
//syphon out the response body from server before setting the new body
if
(
WebSession
.
Response
.
Response
Body
==
null
)
if
(
WebSession
.
Response
.
Body
==
null
)
{
{
await
GetResponseBody
();
await
GetResponseBody
();
}
}
WebSession
.
Response
.
Response
Body
=
body
;
WebSession
.
Response
.
Body
=
body
;
//If there is a content length header update it
//If there is a content length header update it
if
(
WebSession
.
Response
.
IsChunked
==
false
)
if
(
WebSession
.
Response
.
IsChunked
==
false
)
...
@@ -394,7 +394,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -394,7 +394,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
//syphon out the response body from server before setting the new body
//syphon out the response body from server before setting the new body
if
(!
WebSession
.
Response
.
Response
BodyRead
)
if
(!
WebSession
.
Response
.
Is
BodyRead
)
{
{
await
GetResponseBody
();
await
GetResponseBody
();
}
}
...
@@ -422,9 +422,9 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -422,9 +422,9 @@ namespace Titanium.Web.Proxy.EventArguments
public
async
Task
Ok
(
string
html
,
Dictionary
<
string
,
HttpHeader
>
headers
)
public
async
Task
Ok
(
string
html
,
Dictionary
<
string
,
HttpHeader
>
headers
)
{
{
var
response
=
new
OkResponse
();
var
response
=
new
OkResponse
();
response
.
Response
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Response
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
response
.
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
await
Respond
(
response
);
await
Respond
(
response
);
...
@@ -441,9 +441,9 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -441,9 +441,9 @@ namespace Titanium.Web.Proxy.EventArguments
public
async
Task
Ok
(
byte
[]
result
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
)
public
async
Task
Ok
(
byte
[]
result
,
Dictionary
<
string
,
HttpHeader
>
headers
=
null
)
{
{
var
response
=
new
OkResponse
();
var
response
=
new
OkResponse
();
response
.
Response
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Response
Body
=
result
;
response
.
Body
=
result
;
await
Respond
(
response
);
await
Respond
(
response
);
}
}
...
@@ -462,8 +462,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -462,8 +462,8 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
var
response
=
new
GenericResponse
(
status
);
var
response
=
new
GenericResponse
(
status
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Response
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Response
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
response
.
Body
=
response
.
Encoding
.
GetBytes
(
html
??
string
.
Empty
);
await
Respond
(
response
);
await
Respond
(
response
);
}
}
...
@@ -482,8 +482,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -482,8 +482,8 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
var
response
=
new
GenericResponse
(
status
);
var
response
=
new
GenericResponse
(
status
);
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Response
Headers
.
AddHeaders
(
headers
);
response
.
Headers
.
AddHeaders
(
headers
);
response
.
Response
Body
=
result
;
response
.
Body
=
result
;
await
Respond
(
response
);
await
Respond
(
response
);
}
}
...
@@ -497,8 +497,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -497,8 +497,8 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
var
response
=
new
RedirectResponse
();
var
response
=
new
RedirectResponse
();
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
Response
Headers
.
AddHeader
(
"Location"
,
url
);
response
.
Headers
.
AddHeader
(
"Location"
,
url
);
response
.
Response
Body
=
new
byte
[
0
];
response
.
Body
=
new
byte
[
0
];
await
Respond
(
response
);
await
Respond
(
response
);
}
}
...
@@ -514,7 +514,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -514,7 +514,7 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession
.
Request
.
RequestLocked
=
true
;
WebSession
.
Request
.
RequestLocked
=
true
;
response
.
ResponseLocked
=
true
;
response
.
ResponseLocked
=
true
;
response
.
Response
BodyRead
=
true
;
response
.
Is
BodyRead
=
true
;
WebSession
.
Response
=
response
;
WebSession
.
Response
=
response
;
...
...
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
View file @
730d4866
...
@@ -25,9 +25,9 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -25,9 +25,9 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns>
/// <returns></returns>
public
async
Task
WriteResponseAsync
(
Response
response
,
bool
flush
=
true
)
public
async
Task
WriteResponseAsync
(
Response
response
,
bool
flush
=
true
)
{
{
await
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
ResponseStatusCode
,
response
.
Response
StatusDescription
);
await
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
response
.
Response
Headers
.
FixProxyHeaders
();
response
.
Headers
.
FixProxyHeaders
();
await
WriteHeadersAsync
(
response
.
Response
Headers
,
flush
);
await
WriteHeadersAsync
(
response
.
Headers
,
flush
);
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/Http/ConnectResponse.cs
View file @
730d4866
...
@@ -18,11 +18,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -18,11 +18,11 @@ namespace Titanium.Web.Proxy.Http
var
response
=
new
ConnectResponse
var
response
=
new
ConnectResponse
{
{
HttpVersion
=
httpVersion
,
HttpVersion
=
httpVersion
,
Response
StatusCode
=
(
int
)
HttpStatusCode
.
OK
,
StatusCode
=
(
int
)
HttpStatusCode
.
OK
,
Response
StatusDescription
=
"Connection Established"
StatusDescription
=
"Connection Established"
};
};
response
.
Response
Headers
.
AddHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
());
response
.
Headers
.
AddHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
());
return
response
;
return
response
;
}
}
}
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
730d4866
...
@@ -94,7 +94,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -94,7 +94,7 @@ namespace Titanium.Web.Proxy.Http
//prepare the request & headers
//prepare the request & headers
if
(
useUpstreamProxy
)
if
(
useUpstreamProxy
)
{
{
writer
.
WriteLine
(
$"
{
Request
.
Method
}
{
Request
.
Original
Request
Url
}
HTTP/
{
Request
.
HttpVersion
.
Major
}
.
{
Request
.
HttpVersion
.
Minor
}
"
);
writer
.
WriteLine
(
$"
{
Request
.
Method
}
{
Request
.
OriginalUrl
}
HTTP/
{
Request
.
HttpVersion
.
Major
}
.
{
Request
.
HttpVersion
.
Minor
}
"
);
}
}
else
else
{
{
...
@@ -113,7 +113,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -113,7 +113,7 @@ namespace Titanium.Web.Proxy.Http
}
}
//write request headers
//write request headers
foreach
(
var
header
in
Request
.
Request
Headers
)
foreach
(
var
header
in
Request
.
Headers
)
{
{
if
(
header
.
Name
!=
"Proxy-Authorization"
)
if
(
header
.
Name
!=
"Proxy-Authorization"
)
{
{
...
@@ -165,7 +165,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -165,7 +165,7 @@ namespace Titanium.Web.Proxy.Http
internal
async
Task
ReceiveResponse
()
internal
async
Task
ReceiveResponse
()
{
{
//return if this is already read
//return if this is already read
if
(
Response
.
Response
StatusCode
!=
0
)
if
(
Response
.
StatusCode
!=
0
)
return
;
return
;
string
httpStatus
=
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
string
httpStatus
=
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
...
@@ -186,28 +186,28 @@ namespace Titanium.Web.Proxy.Http
...
@@ -186,28 +186,28 @@ namespace Titanium.Web.Proxy.Http
Response
.
ParseResponseLine
(
httpStatus
,
out
version
,
out
statusCode
,
out
statusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
version
,
out
statusCode
,
out
statusDescription
);
Response
.
HttpVersion
=
version
;
Response
.
HttpVersion
=
version
;
Response
.
Response
StatusCode
=
statusCode
;
Response
.
StatusCode
=
statusCode
;
Response
.
Response
StatusDescription
=
statusDescription
;
Response
.
StatusDescription
=
statusDescription
;
//For HTTP 1.1 comptibility server may send expect-continue even if not asked for it in request
//For HTTP 1.1 comptibility server may send expect-continue even if not asked for it in request
if
(
Response
.
Response
StatusCode
==
(
int
)
HttpStatusCode
.
Continue
if
(
Response
.
StatusCode
==
(
int
)
HttpStatusCode
.
Continue
&&
Response
.
Response
StatusDescription
.
Equals
(
"continue"
,
StringComparison
.
CurrentCultureIgnoreCase
))
&&
Response
.
StatusDescription
.
Equals
(
"continue"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
{
//Read the next line after 100-continue
//Read the next line after 100-continue
Response
.
Is100Continue
=
true
;
Response
.
Is100Continue
=
true
;
Response
.
Response
StatusCode
=
0
;
Response
.
StatusCode
=
0
;
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
//now receive response
//now receive response
await
ReceiveResponse
();
await
ReceiveResponse
();
return
;
return
;
}
}
if
(
Response
.
Response
StatusCode
==
(
int
)
HttpStatusCode
.
ExpectationFailed
if
(
Response
.
StatusCode
==
(
int
)
HttpStatusCode
.
ExpectationFailed
&&
Response
.
Response
StatusDescription
.
Equals
(
"expectation failed"
,
StringComparison
.
CurrentCultureIgnoreCase
))
&&
Response
.
StatusDescription
.
Equals
(
"expectation failed"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
{
//read next line after expectation failed response
//read next line after expectation failed response
Response
.
ExpectationFailed
=
true
;
Response
.
ExpectationFailed
=
true
;
Response
.
Response
StatusCode
=
0
;
Response
.
StatusCode
=
0
;
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
//now receive response
//now receive response
await
ReceiveResponse
();
await
ReceiveResponse
();
...
@@ -215,7 +215,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -215,7 +215,7 @@ namespace Titanium.Web.Proxy.Http
}
}
//Read the response headers in to unique and non-unique header collections
//Read the response headers in to unique and non-unique header collections
await
HeaderParser
.
ReadHeaders
(
ServerConnection
.
StreamReader
,
Response
.
Response
Headers
);
await
HeaderParser
.
ReadHeaders
(
ServerConnection
.
StreamReader
,
Response
.
Headers
);
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
730d4866
...
@@ -14,12 +14,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -14,12 +14,12 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Cached request body as byte array
/// Cached request body as byte array
/// </summary>
/// </summary>
private
byte
[]
requestB
ody
;
private
byte
[]
b
ody
;
/// <summary>
/// <summary>
/// Cached request body as string
/// Cached request body as string
/// </summary>
/// </summary>
private
string
requestB
odyString
;
private
string
b
odyString
;
/// <summary>
/// <summary>
/// Request Method
/// Request Method
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// The original request Url.
/// The original request Url.
/// </summary>
/// </summary>
public
string
Original
Request
Url
{
get
;
set
;
}
public
string
OriginalUrl
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Request Http Version
/// Request Http Version
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Keeps the request body data after the session is finished
/// Keeps the request body data after the session is finished
/// </summary>
/// </summary>
public
bool
Keep
Request
Body
{
get
;
set
;
}
public
bool
KeepBody
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Has request body?
/// Has request body?
...
@@ -65,18 +65,18 @@ namespace Titanium.Web.Proxy.Http
...
@@ -65,18 +65,18 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
return
Request
Headers
.
GetHeaderValueOrNull
(
"host"
);
return
Headers
.
GetHeaderValueOrNull
(
"host"
);
}
}
set
set
{
{
Request
Headers
.
SetOrAddHeaderValue
(
"host"
,
value
);
Headers
.
SetOrAddHeaderValue
(
"host"
,
value
);
}
}
}
}
/// <summary>
/// <summary>
/// Content encoding header value
/// Content encoding header value
/// </summary>
/// </summary>
public
string
ContentEncoding
=>
Request
Headers
.
GetHeaderValueOrNull
(
"content-encoding"
);
public
string
ContentEncoding
=>
Headers
.
GetHeaderValueOrNull
(
"content-encoding"
);
/// <summary>
/// <summary>
/// Request content-length
/// Request content-length
...
@@ -85,7 +85,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -85,7 +85,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Request
Headers
.
GetHeaderValueOrNull
(
"content-length"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"content-length"
);
if
(
headerValue
==
null
)
if
(
headerValue
==
null
)
{
{
...
@@ -105,12 +105,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -105,12 +105,12 @@ namespace Titanium.Web.Proxy.Http
{
{
if
(
value
>=
0
)
if
(
value
>=
0
)
{
{
Request
Headers
.
SetOrAddHeaderValue
(
"content-length"
,
value
.
ToString
());
Headers
.
SetOrAddHeaderValue
(
"content-length"
,
value
.
ToString
());
IsChunked
=
false
;
IsChunked
=
false
;
}
}
else
else
{
{
Request
Headers
.
RemoveHeader
(
"content-length"
);
Headers
.
RemoveHeader
(
"content-length"
);
}
}
}
}
}
}
...
@@ -122,11 +122,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -122,11 +122,11 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
return
Request
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
return
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
}
}
set
set
{
{
Request
Headers
.
SetOrAddHeaderValue
(
"content-type"
,
value
);
Headers
.
SetOrAddHeaderValue
(
"content-type"
,
value
);
}
}
}
}
...
@@ -137,19 +137,19 @@ namespace Titanium.Web.Proxy.Http
...
@@ -137,19 +137,19 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Request
Headers
.
GetHeaderValueOrNull
(
"transfer-encoding"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"transfer-encoding"
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
"chunked"
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
"chunked"
);
}
}
set
set
{
{
if
(
value
)
if
(
value
)
{
{
Request
Headers
.
SetOrAddHeaderValue
(
"transfer-encoding"
,
"chunked"
);
Headers
.
SetOrAddHeaderValue
(
"transfer-encoding"
,
"chunked"
);
ContentLength
=
-
1
;
ContentLength
=
-
1
;
}
}
else
else
{
{
Request
Headers
.
RemoveHeader
(
"transfer-encoding"
);
Headers
.
RemoveHeader
(
"transfer-encoding"
);
}
}
}
}
}
}
...
@@ -161,7 +161,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -161,7 +161,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Request
Headers
.
GetHeaderValueOrNull
(
"expect"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"expect"
);
return
headerValue
!=
null
&&
headerValue
.
Equals
(
"100-continue"
);
return
headerValue
!=
null
&&
headerValue
.
Equals
(
"100-continue"
);
}
}
}
}
...
@@ -184,11 +184,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -184,11 +184,11 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Request body as byte array
/// Request body as byte array
/// </summary>
/// </summary>
public
byte
[]
Request
Body
public
byte
[]
Body
{
{
get
get
{
{
if
(!
Request
BodyRead
)
if
(!
Is
BodyRead
)
{
{
if
(
RequestLocked
)
if
(
RequestLocked
)
{
{
...
@@ -200,12 +200,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -200,12 +200,12 @@ namespace Titanium.Web.Proxy.Http
"method to read the request body."
);
"method to read the request body."
);
}
}
return
requestB
ody
;
return
b
ody
;
}
}
internal
set
internal
set
{
{
requestB
ody
=
value
;
b
ody
=
value
;
requestB
odyString
=
null
;
b
odyString
=
null
;
}
}
}
}
...
@@ -213,12 +213,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -213,12 +213,12 @@ namespace Titanium.Web.Proxy.Http
/// Request body as string
/// Request body as string
/// Use the encoding specified in request to decode the byte[] data to string
/// Use the encoding specified in request to decode the byte[] data to string
/// </summary>
/// </summary>
public
string
RequestBodyString
=>
requestBodyString
??
(
requestBodyString
=
Encoding
.
GetString
(
Request
Body
));
public
string
BodyString
=>
bodyString
??
(
bodyString
=
Encoding
.
GetString
(
Body
));
/// <summary>
/// <summary>
/// Request body was read by user?
/// Request body was read by user?
/// </summary>
/// </summary>
public
bool
Request
BodyRead
{
get
;
internal
set
;
}
public
bool
Is
BodyRead
{
get
;
internal
set
;
}
/// <summary>
/// <summary>
/// Request is ready to be sent (user callbacks are complete?)
/// Request is ready to be sent (user callbacks are complete?)
...
@@ -232,7 +232,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -232,7 +232,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Request
Headers
.
GetHeaderValueOrNull
(
"upgrade"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"upgrade"
);
if
(
headerValue
==
null
)
if
(
headerValue
==
null
)
{
{
...
@@ -246,7 +246,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -246,7 +246,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Request header collection
/// Request header collection
/// </summary>
/// </summary>
public
HeaderCollection
Request
Headers
{
get
;
}
=
new
HeaderCollection
();
public
HeaderCollection
Headers
{
get
;
}
=
new
HeaderCollection
();
/// <summary>
/// <summary>
/// Does server responsed positively for 100 continue request
/// Does server responsed positively for 100 continue request
...
@@ -266,8 +266,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -266,8 +266,8 @@ namespace Titanium.Web.Proxy.Http
get
get
{
{
var
sb
=
new
StringBuilder
();
var
sb
=
new
StringBuilder
();
sb
.
AppendLine
(
$"
{
Method
}
{
Original
Request
Url
}
HTTP/
{
HttpVersion
.
Major
}
.
{
HttpVersion
.
Minor
}
"
);
sb
.
AppendLine
(
$"
{
Method
}
{
OriginalUrl
}
HTTP/
{
HttpVersion
.
Major
}
.
{
HttpVersion
.
Minor
}
"
);
foreach
(
var
header
in
Request
Headers
)
foreach
(
var
header
in
Headers
)
{
{
sb
.
AppendLine
(
header
.
ToString
());
sb
.
AppendLine
(
header
.
ToString
());
}
}
...
@@ -333,10 +333,10 @@ namespace Titanium.Web.Proxy.Http
...
@@ -333,10 +333,10 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
void
FinishSession
()
public
void
FinishSession
()
{
{
if
(!
Keep
Request
Body
)
if
(!
KeepBody
)
{
{
requestB
ody
=
null
;
b
ody
=
null
;
requestB
odyString
=
null
;
b
odyString
=
null
;
}
}
}
}
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
730d4866
...
@@ -14,22 +14,22 @@ namespace Titanium.Web.Proxy.Http
...
@@ -14,22 +14,22 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Cached response body content as byte array
/// Cached response body content as byte array
/// </summary>
/// </summary>
private
byte
[]
responseB
ody
;
private
byte
[]
b
ody
;
/// <summary>
/// <summary>
/// Cached response body as string
/// Cached response body as string
/// </summary>
/// </summary>
private
string
responseB
odyString
;
private
string
b
odyString
;
/// <summary>
/// <summary>
/// Response Status Code.
/// Response Status Code.
/// </summary>
/// </summary>
public
int
Response
StatusCode
{
get
;
set
;
}
public
int
StatusCode
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Response Status description.
/// Response Status description.
/// </summary>
/// </summary>
public
string
Response
StatusDescription
{
get
;
set
;
}
public
string
StatusDescription
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Encoding used in response
/// Encoding used in response
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Content encoding for this response
/// Content encoding for this response
/// </summary>
/// </summary>
public
string
ContentEncoding
=>
Response
Headers
.
GetHeaderValueOrNull
(
"content-encoding"
)?.
Trim
();
public
string
ContentEncoding
=>
Headers
.
GetHeaderValueOrNull
(
"content-encoding"
)?.
Trim
();
/// <summary>
/// <summary>
/// Http version
/// Http version
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Keeps the response body data after the session is finished
/// Keeps the response body data after the session is finished
/// </summary>
/// </summary>
public
bool
Keep
Response
Body
{
get
;
set
;
}
public
bool
KeepBody
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Has response body?
/// Has response body?
...
@@ -60,14 +60,14 @@ namespace Titanium.Web.Proxy.Http
...
@@ -60,14 +60,14 @@ namespace Titanium.Web.Proxy.Http
{
{
//Has body only if response is chunked or content length >0
//Has body only if response is chunked or content length >0
//If none are true then check if connection:close header exist, if so write response until server or client terminates the connection
//If none are true then check if connection:close header exist, if so write response until server or client terminates the connection
if
(
IsChunked
||
ContentLength
>
0
||
!
Response
KeepAlive
)
if
(
IsChunked
||
ContentLength
>
0
||
!
KeepAlive
)
{
{
return
true
;
return
true
;
}
}
//has response if connection:keep-alive header exist and when version is http/1.0
//has response if connection:keep-alive header exist and when version is http/1.0
//Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
//Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
if
(
Response
KeepAlive
&&
HttpVersion
.
Minor
==
0
)
if
(
KeepAlive
&&
HttpVersion
.
Minor
==
0
)
{
{
return
true
;
return
true
;
}
}
...
@@ -79,11 +79,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -79,11 +79,11 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Keep the connection alive?
/// Keep the connection alive?
/// </summary>
/// </summary>
public
bool
Response
KeepAlive
public
bool
KeepAlive
{
{
get
get
{
{
string
headerValue
=
Response
Headers
.
GetHeaderValueOrNull
(
"connection"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"connection"
);
if
(
headerValue
!=
null
)
if
(
headerValue
!=
null
)
{
{
...
@@ -100,7 +100,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -100,7 +100,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Content type of this response
/// Content type of this response
/// </summary>
/// </summary>
public
string
ContentType
=>
Response
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
public
string
ContentType
=>
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
/// <summary>
/// <summary>
/// Length of response body
/// Length of response body
...
@@ -109,7 +109,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -109,7 +109,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Response
Headers
.
GetHeaderValueOrNull
(
"content-length"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"content-length"
);
if
(
headerValue
==
null
)
if
(
headerValue
==
null
)
{
{
...
@@ -129,12 +129,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -129,12 +129,12 @@ namespace Titanium.Web.Proxy.Http
{
{
if
(
value
>=
0
)
if
(
value
>=
0
)
{
{
Response
Headers
.
SetOrAddHeaderValue
(
"content-length"
,
value
.
ToString
());
Headers
.
SetOrAddHeaderValue
(
"content-length"
,
value
.
ToString
());
IsChunked
=
false
;
IsChunked
=
false
;
}
}
else
else
{
{
Response
Headers
.
RemoveHeader
(
"content-length"
);
Headers
.
RemoveHeader
(
"content-length"
);
}
}
}
}
}
}
...
@@ -146,19 +146,19 @@ namespace Titanium.Web.Proxy.Http
...
@@ -146,19 +146,19 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
string
headerValue
=
Response
Headers
.
GetHeaderValueOrNull
(
"transfer-encoding"
);
string
headerValue
=
Headers
.
GetHeaderValueOrNull
(
"transfer-encoding"
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
"chunked"
);
return
headerValue
!=
null
&&
headerValue
.
ContainsIgnoreCase
(
"chunked"
);
}
}
set
set
{
{
if
(
value
)
if
(
value
)
{
{
Response
Headers
.
SetOrAddHeaderValue
(
"transfer-encoding"
,
"chunked"
);
Headers
.
SetOrAddHeaderValue
(
"transfer-encoding"
,
"chunked"
);
ContentLength
=
-
1
;
ContentLength
=
-
1
;
}
}
else
else
{
{
Response
Headers
.
RemoveHeader
(
"transfer-encoding"
);
Headers
.
RemoveHeader
(
"transfer-encoding"
);
}
}
}
}
}
}
...
@@ -166,28 +166,28 @@ namespace Titanium.Web.Proxy.Http
...
@@ -166,28 +166,28 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Collection of all response headers
/// Collection of all response headers
/// </summary>
/// </summary>
public
HeaderCollection
Response
Headers
{
get
;
}
=
new
HeaderCollection
();
public
HeaderCollection
Headers
{
get
;
}
=
new
HeaderCollection
();
/// <summary>
/// <summary>
/// Response body as byte array
/// Response body as byte array
/// </summary>
/// </summary>
public
byte
[]
Response
Body
public
byte
[]
Body
{
{
get
get
{
{
if
(!
Response
BodyRead
)
if
(!
Is
BodyRead
)
{
{
throw
new
Exception
(
"Response body is not read yet. "
+
throw
new
Exception
(
"Response body is not read yet. "
+
"Use SessionEventArgs.GetResponseBody() or SessionEventArgs.GetResponseBodyAsString() "
+
"Use SessionEventArgs.GetResponseBody() or SessionEventArgs.GetResponseBodyAsString() "
+
"method to read the response body."
);
"method to read the response body."
);
}
}
return
responseB
ody
;
return
b
ody
;
}
}
internal
set
internal
set
{
{
responseB
ody
=
value
;
b
ody
=
value
;
responseB
odyString
=
null
;
b
odyString
=
null
;
}
}
}
}
...
@@ -195,12 +195,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -195,12 +195,12 @@ namespace Titanium.Web.Proxy.Http
/// Response body as string
/// Response body as string
/// Use the encoding specified in response to decode the byte[] data to string
/// Use the encoding specified in response to decode the byte[] data to string
/// </summary>
/// </summary>
public
string
ResponseBodyString
=>
responseBodyString
??
(
responseBodyString
=
Encoding
.
GetString
(
Response
Body
));
public
string
BodyString
=>
bodyString
??
(
bodyString
=
Encoding
.
GetString
(
Body
));
/// <summary>
/// <summary>
/// Was response body read by user
/// Was response body read by user
/// </summary>
/// </summary>
public
bool
Response
BodyRead
{
get
;
internal
set
;
}
public
bool
Is
BodyRead
{
get
;
internal
set
;
}
/// <summary>
/// <summary>
/// Is response is no more modifyable by user (user callbacks complete?)
/// Is response is no more modifyable by user (user callbacks complete?)
...
@@ -220,7 +220,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -220,7 +220,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Gets the resposne status.
/// Gets the resposne status.
/// </summary>
/// </summary>
public
string
ResponseStatus
=>
$"HTTP/
{
HttpVersion
?.
Major
}
.
{
HttpVersion
?.
Minor
}
{
ResponseStatusCode
}
{
Response
StatusDescription
}
"
;
public
string
Status
=>
$"HTTP/
{
HttpVersion
?.
Major
}
.
{
HttpVersion
?.
Minor
}
{
StatusCode
}
{
StatusDescription
}
"
;
/// <summary>
/// <summary>
/// Gets the header text.
/// Gets the header text.
...
@@ -230,8 +230,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -230,8 +230,8 @@ namespace Titanium.Web.Proxy.Http
get
get
{
{
var
sb
=
new
StringBuilder
();
var
sb
=
new
StringBuilder
();
sb
.
AppendLine
(
Response
Status
);
sb
.
AppendLine
(
Status
);
foreach
(
var
header
in
Response
Headers
)
foreach
(
var
header
in
Headers
)
{
{
sb
.
AppendLine
(
header
.
ToString
());
sb
.
AppendLine
(
header
.
ToString
());
}
}
...
@@ -266,10 +266,10 @@ namespace Titanium.Web.Proxy.Http
...
@@ -266,10 +266,10 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
internal
void
FinishSession
()
internal
void
FinishSession
()
{
{
if
(!
Keep
Response
Body
)
if
(!
KeepBody
)
{
{
responseB
ody
=
null
;
b
ody
=
null
;
responseB
odyString
=
null
;
b
odyString
=
null
;
}
}
}
}
...
...
Titanium.Web.Proxy/Http/Responses/GenericResponse.cs
View file @
730d4866
...
@@ -13,11 +13,11 @@ namespace Titanium.Web.Proxy.Http.Responses
...
@@ -13,11 +13,11 @@ namespace Titanium.Web.Proxy.Http.Responses
/// <param name="status"></param>
/// <param name="status"></param>
public
GenericResponse
(
HttpStatusCode
status
)
public
GenericResponse
(
HttpStatusCode
status
)
{
{
Response
StatusCode
=
(
int
)
status
;
StatusCode
=
(
int
)
status
;
//todo: this is not really correct, status description should contain spaces, too
//todo: this is not really correct, status description should contain spaces, too
//see: https://tools.ietf.org/html/rfc7231#section-6.1
//see: https://tools.ietf.org/html/rfc7231#section-6.1
Response
StatusDescription
=
status
.
ToString
();
StatusDescription
=
status
.
ToString
();
}
}
/// <summary>
/// <summary>
...
@@ -27,8 +27,8 @@ namespace Titanium.Web.Proxy.Http.Responses
...
@@ -27,8 +27,8 @@ namespace Titanium.Web.Proxy.Http.Responses
/// <param name="statusDescription"></param>
/// <param name="statusDescription"></param>
public
GenericResponse
(
int
statusCode
,
string
statusDescription
)
public
GenericResponse
(
int
statusCode
,
string
statusDescription
)
{
{
Response
StatusCode
=
statusCode
;
StatusCode
=
statusCode
;
Response
StatusDescription
=
statusDescription
;
StatusDescription
=
statusDescription
;
}
}
}
}
}
}
Titanium.Web.Proxy/Http/Responses/OkResponse.cs
View file @
730d4866
...
@@ -12,8 +12,8 @@ namespace Titanium.Web.Proxy.Http.Responses
...
@@ -12,8 +12,8 @@ namespace Titanium.Web.Proxy.Http.Responses
/// </summary>
/// </summary>
public
OkResponse
()
public
OkResponse
()
{
{
Response
StatusCode
=
(
int
)
HttpStatusCode
.
OK
;
StatusCode
=
(
int
)
HttpStatusCode
.
OK
;
Response
StatusDescription
=
"OK"
;
StatusDescription
=
"OK"
;
}
}
}
}
}
}
Titanium.Web.Proxy/Http/Responses/RedirectResponse.cs
View file @
730d4866
...
@@ -12,8 +12,8 @@ namespace Titanium.Web.Proxy.Http.Responses
...
@@ -12,8 +12,8 @@ namespace Titanium.Web.Proxy.Http.Responses
/// </summary>
/// </summary>
public
RedirectResponse
()
public
RedirectResponse
()
{
{
Response
StatusCode
=
(
int
)
HttpStatusCode
.
Found
;
StatusCode
=
(
int
)
HttpStatusCode
.
Found
;
Response
StatusDescription
=
"Found"
;
StatusDescription
=
"Found"
;
}
}
}
}
}
}
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
730d4866
...
@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy
...
@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy
return
true
;
return
true
;
}
}
var
httpHeaders
=
session
.
WebSession
.
Request
.
Request
Headers
.
ToArray
();
var
httpHeaders
=
session
.
WebSession
.
Request
.
Headers
.
ToArray
();
try
try
{
{
...
@@ -68,12 +68,12 @@ namespace Titanium.Web.Proxy
...
@@ -68,12 +68,12 @@ namespace Titanium.Web.Proxy
var
response
=
new
Response
var
response
=
new
Response
{
{
HttpVersion
=
HttpHeader
.
Version11
,
HttpVersion
=
HttpHeader
.
Version11
,
Response
StatusCode
=
(
int
)
HttpStatusCode
.
ProxyAuthenticationRequired
,
StatusCode
=
(
int
)
HttpStatusCode
.
ProxyAuthenticationRequired
,
Response
StatusDescription
=
description
StatusDescription
=
description
};
};
response
.
Response
Headers
.
AddHeader
(
"Proxy-Authenticate"
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Headers
.
AddHeader
(
"Proxy-Authenticate"
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Response
Headers
.
AddHeader
(
"Proxy-Connection"
,
"close"
);
response
.
Headers
.
AddHeader
(
"Proxy-Connection"
,
"close"
);
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
return
response
;
return
response
;
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
730d4866
...
@@ -81,11 +81,11 @@ namespace Titanium.Web.Proxy
...
@@ -81,11 +81,11 @@ namespace Titanium.Web.Proxy
connectRequest
=
new
ConnectRequest
connectRequest
=
new
ConnectRequest
{
{
RequestUri
=
httpRemoteUri
,
RequestUri
=
httpRemoteUri
,
Original
Request
Url
=
httpUrl
,
OriginalUrl
=
httpUrl
,
HttpVersion
=
version
,
HttpVersion
=
version
,
};
};
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
connectRequest
.
Request
Headers
);
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
connectRequest
.
Headers
);
var
connectArgs
=
new
TunnelConnectSessionEventArgs
(
BufferSize
,
endPoint
,
connectRequest
);
var
connectArgs
=
new
TunnelConnectSessionEventArgs
(
BufferSize
,
endPoint
,
connectRequest
);
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
...
@@ -312,14 +312,14 @@ namespace Titanium.Web.Proxy
...
@@ -312,14 +312,14 @@ namespace Titanium.Web.Proxy
Request
.
ParseRequestLine
(
httpCmd
,
out
httpMethod
,
out
httpUrl
,
out
version
);
Request
.
ParseRequestLine
(
httpCmd
,
out
httpMethod
,
out
httpUrl
,
out
version
);
//Read the request headers in to unique and non-unique header collections
//Read the request headers in to unique and non-unique header collections
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
args
.
WebSession
.
Request
.
Request
Headers
);
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
args
.
WebSession
.
Request
.
Headers
);
var
httpRemoteUri
=
new
Uri
(
httpsConnectHostname
==
null
var
httpRemoteUri
=
new
Uri
(
httpsConnectHostname
==
null
?
isTransparentEndPoint
?
string
.
Concat
(
"http://"
,
args
.
WebSession
.
Request
.
Host
,
httpUrl
)
:
httpUrl
?
isTransparentEndPoint
?
string
.
Concat
(
"http://"
,
args
.
WebSession
.
Request
.
Host
,
httpUrl
)
:
httpUrl
:
string
.
Concat
(
"https://"
,
args
.
WebSession
.
Request
.
Host
??
httpsConnectHostname
,
httpUrl
));
:
string
.
Concat
(
"https://"
,
args
.
WebSession
.
Request
.
Host
??
httpsConnectHostname
,
httpUrl
));
args
.
WebSession
.
Request
.
RequestUri
=
httpRemoteUri
;
args
.
WebSession
.
Request
.
RequestUri
=
httpRemoteUri
;
args
.
WebSession
.
Request
.
Original
Request
Url
=
httpUrl
;
args
.
WebSession
.
Request
.
OriginalUrl
=
httpUrl
;
args
.
WebSession
.
Request
.
Method
=
httpMethod
;
args
.
WebSession
.
Request
.
Method
=
httpMethod
;
args
.
WebSession
.
Request
.
HttpVersion
=
version
;
args
.
WebSession
.
Request
.
HttpVersion
=
version
;
...
@@ -334,7 +334,7 @@ namespace Titanium.Web.Proxy
...
@@ -334,7 +334,7 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
Request
Headers
);
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
Headers
);
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
//if win auth is enabled
//if win auth is enabled
...
@@ -377,7 +377,7 @@ namespace Titanium.Web.Proxy
...
@@ -377,7 +377,7 @@ namespace Titanium.Web.Proxy
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
{
{
//prepare the prefix content
//prepare the prefix content
var
requestHeaders
=
args
.
WebSession
.
Request
.
Request
Headers
;
var
requestHeaders
=
args
.
WebSession
.
Request
.
Headers
;
byte
[]
requestBytes
;
byte
[]
requestBytes
;
using
(
var
ms
=
new
MemoryStream
())
using
(
var
ms
=
new
MemoryStream
())
using
(
var
writer
=
new
HttpRequestWriter
(
ms
,
BufferSize
))
using
(
var
writer
=
new
HttpRequestWriter
(
ms
,
BufferSize
))
...
@@ -395,10 +395,10 @@ namespace Titanium.Web.Proxy
...
@@ -395,10 +395,10 @@ namespace Titanium.Web.Proxy
string
responseStatusDescription
;
string
responseStatusDescription
;
Response
.
ParseResponseLine
(
httpStatus
,
out
responseVersion
,
out
responseStatusCode
,
out
responseStatusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
responseVersion
,
out
responseStatusCode
,
out
responseStatusDescription
);
args
.
WebSession
.
Response
.
HttpVersion
=
responseVersion
;
args
.
WebSession
.
Response
.
HttpVersion
=
responseVersion
;
args
.
WebSession
.
Response
.
Response
StatusCode
=
responseStatusCode
;
args
.
WebSession
.
Response
.
StatusCode
=
responseStatusCode
;
args
.
WebSession
.
Response
.
Response
StatusDescription
=
responseStatusDescription
;
args
.
WebSession
.
Response
.
StatusDescription
=
responseStatusDescription
;
await
HeaderParser
.
ReadHeaders
(
connection
.
StreamReader
,
args
.
WebSession
.
Response
.
Response
Headers
);
await
HeaderParser
.
ReadHeaders
(
connection
.
StreamReader
,
args
.
WebSession
.
Response
.
Headers
);
await
clientStreamWriter
.
WriteResponseAsync
(
args
.
WebSession
.
Response
);
await
clientStreamWriter
.
WriteResponseAsync
(
args
.
WebSession
.
Response
);
...
@@ -426,7 +426,7 @@ namespace Titanium.Web.Proxy
...
@@ -426,7 +426,7 @@ namespace Titanium.Web.Proxy
}
}
//if connection is closing exit
//if connection is closing exit
if
(
args
.
WebSession
.
Response
.
Response
KeepAlive
==
false
)
if
(
args
.
WebSession
.
Response
.
KeepAlive
==
false
)
{
{
args
.
Dispose
();
args
.
Dispose
();
break
;
break
;
...
@@ -502,15 +502,15 @@ namespace Titanium.Web.Proxy
...
@@ -502,15 +502,15 @@ namespace Titanium.Web.Proxy
if
(
args
.
WebSession
.
Request
.
ContentLength
>
0
)
if
(
args
.
WebSession
.
Request
.
ContentLength
>
0
)
{
{
//If request was modified by user
//If request was modified by user
if
(
args
.
WebSession
.
Request
.
Request
BodyRead
)
if
(
args
.
WebSession
.
Request
.
Is
BodyRead
)
{
{
if
(
args
.
WebSession
.
Request
.
ContentEncoding
!=
null
)
if
(
args
.
WebSession
.
Request
.
ContentEncoding
!=
null
)
{
{
args
.
WebSession
.
Request
.
Request
Body
=
args
.
WebSession
.
Request
.
Body
=
await
GetCompressedResponseBody
(
args
.
WebSession
.
Request
.
ContentEncoding
,
args
.
WebSession
.
Request
.
Request
Body
);
await
GetCompressedResponseBody
(
args
.
WebSession
.
Request
.
ContentEncoding
,
args
.
WebSession
.
Request
.
Body
);
}
}
var
body
=
args
.
WebSession
.
Request
.
Request
Body
;
var
body
=
args
.
WebSession
.
Request
.
Body
;
//chunked send is not supported as of now
//chunked send is not supported as of now
args
.
WebSession
.
Request
.
ContentLength
=
body
.
Length
;
args
.
WebSession
.
Request
.
ContentLength
=
body
.
Length
;
...
@@ -544,7 +544,7 @@ namespace Titanium.Web.Proxy
...
@@ -544,7 +544,7 @@ namespace Titanium.Web.Proxy
}
}
//if connection is closing exit
//if connection is closing exit
if
(
args
.
WebSession
.
Response
.
Response
KeepAlive
==
false
)
if
(
args
.
WebSession
.
Response
.
KeepAlive
==
false
)
{
{
return
true
;
return
true
;
}
}
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
730d4866
...
@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy
...
@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy
var
response
=
args
.
WebSession
.
Response
;
var
response
=
args
.
WebSession
.
Response
;
//check for windows authentication
//check for windows authentication
if
(
IsWindowsAuthenticationEnabledAndSupported
&&
response
.
Response
StatusCode
==
(
int
)
HttpStatusCode
.
Unauthorized
)
if
(
IsWindowsAuthenticationEnabledAndSupported
&&
response
.
StatusCode
==
(
int
)
HttpStatusCode
.
Unauthorized
)
{
{
bool
disposed
=
await
Handle401UnAuthorized
(
args
);
bool
disposed
=
await
Handle401UnAuthorized
(
args
);
...
@@ -74,21 +74,21 @@ namespace Titanium.Web.Proxy
...
@@ -74,21 +74,21 @@ namespace Titanium.Web.Proxy
}
}
//Write back response status to client
//Write back response status to client
await
clientStreamWriter
.
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
ResponseStatusCode
,
response
.
Response
StatusDescription
);
await
clientStreamWriter
.
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
response
.
Response
Headers
.
FixProxyHeaders
();
response
.
Headers
.
FixProxyHeaders
();
if
(
response
.
Response
BodyRead
)
if
(
response
.
Is
BodyRead
)
{
{
bool
isChunked
=
response
.
IsChunked
;
bool
isChunked
=
response
.
IsChunked
;
string
contentEncoding
=
response
.
ContentEncoding
;
string
contentEncoding
=
response
.
ContentEncoding
;
if
(
contentEncoding
!=
null
)
if
(
contentEncoding
!=
null
)
{
{
response
.
ResponseBody
=
await
GetCompressedResponseBody
(
contentEncoding
,
response
.
Response
Body
);
response
.
Body
=
await
GetCompressedResponseBody
(
contentEncoding
,
response
.
Body
);
if
(
isChunked
==
false
)
if
(
isChunked
==
false
)
{
{
response
.
ContentLength
=
response
.
Response
Body
.
Length
;
response
.
ContentLength
=
response
.
Body
.
Length
;
}
}
else
else
{
{
...
@@ -96,12 +96,12 @@ namespace Titanium.Web.Proxy
...
@@ -96,12 +96,12 @@ namespace Titanium.Web.Proxy
}
}
}
}
await
clientStreamWriter
.
WriteHeadersAsync
(
response
.
Response
Headers
);
await
clientStreamWriter
.
WriteHeadersAsync
(
response
.
Headers
);
await
clientStreamWriter
.
WriteResponseBodyAsync
(
response
.
Response
Body
,
isChunked
);
await
clientStreamWriter
.
WriteResponseBodyAsync
(
response
.
Body
,
isChunked
);
}
}
else
else
{
{
await
clientStreamWriter
.
WriteHeadersAsync
(
response
.
Response
Headers
);
await
clientStreamWriter
.
WriteHeadersAsync
(
response
.
Headers
);
//Write body if exists
//Write body if exists
if
(
response
.
HasBody
)
if
(
response
.
HasBody
)
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
730d4866
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<AssemblyOriginatorKeyFile>StrongNameKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>StrongNameKey.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign>
<DelaySign>False</DelaySign>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>
6
</LangVersion>
<LangVersion>
7.1
</LangVersion>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
730d4866
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy
//check in non-unique headers first
//check in non-unique headers first
var
header
=
var
header
=
args
.
WebSession
.
Response
.
Response
Headers
.
NonUniqueHeaders
.
FirstOrDefault
(
args
.
WebSession
.
Response
.
Headers
.
NonUniqueHeaders
.
FirstOrDefault
(
x
=>
authHeaderNames
.
Any
(
y
=>
x
.
Key
.
Equals
(
y
,
StringComparison
.
OrdinalIgnoreCase
)));
x
=>
authHeaderNames
.
Any
(
y
=>
x
.
Key
.
Equals
(
y
,
StringComparison
.
OrdinalIgnoreCase
)));
if
(!
header
.
Equals
(
new
KeyValuePair
<
string
,
List
<
HttpHeader
>>()))
if
(!
header
.
Equals
(
new
KeyValuePair
<
string
,
List
<
HttpHeader
>>()))
...
@@ -54,7 +54,7 @@ namespace Titanium.Web.Proxy
...
@@ -54,7 +54,7 @@ namespace Titanium.Web.Proxy
if
(
headerName
!=
null
)
if
(
headerName
!=
null
)
{
{
authHeader
=
args
.
WebSession
.
Response
.
Response
Headers
.
NonUniqueHeaders
[
headerName
]
authHeader
=
args
.
WebSession
.
Response
.
Headers
.
NonUniqueHeaders
[
headerName
]
.
FirstOrDefault
(
x
=>
authSchemes
.
Any
(
y
=>
x
.
Value
.
StartsWith
(
y
,
StringComparison
.
OrdinalIgnoreCase
)));
.
FirstOrDefault
(
x
=>
authSchemes
.
Any
(
y
=>
x
.
Value
.
StartsWith
(
y
,
StringComparison
.
OrdinalIgnoreCase
)));
}
}
...
@@ -63,7 +63,7 @@ namespace Titanium.Web.Proxy
...
@@ -63,7 +63,7 @@ namespace Titanium.Web.Proxy
{
{
//check in non-unique headers first
//check in non-unique headers first
var
uHeader
=
var
uHeader
=
args
.
WebSession
.
Response
.
Response
Headers
.
Headers
.
FirstOrDefault
(
x
=>
authHeaderNames
.
Any
(
y
=>
x
.
Key
.
Equals
(
y
,
StringComparison
.
OrdinalIgnoreCase
)));
args
.
WebSession
.
Response
.
Headers
.
Headers
.
FirstOrDefault
(
x
=>
authHeaderNames
.
Any
(
y
=>
x
.
Key
.
Equals
(
y
,
StringComparison
.
OrdinalIgnoreCase
)));
if
(!
uHeader
.
Equals
(
new
KeyValuePair
<
string
,
HttpHeader
>()))
if
(!
uHeader
.
Equals
(
new
KeyValuePair
<
string
,
HttpHeader
>()))
{
{
...
@@ -72,9 +72,9 @@ namespace Titanium.Web.Proxy
...
@@ -72,9 +72,9 @@ namespace Titanium.Web.Proxy
if
(
headerName
!=
null
)
if
(
headerName
!=
null
)
{
{
authHeader
=
authSchemes
.
Any
(
x
=>
args
.
WebSession
.
Response
.
Response
Headers
.
Headers
[
headerName
].
Value
authHeader
=
authSchemes
.
Any
(
x
=>
args
.
WebSession
.
Response
.
Headers
.
Headers
[
headerName
].
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
))
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
))
?
args
.
WebSession
.
Response
.
Response
Headers
.
Headers
[
headerName
]
?
args
.
WebSession
.
Response
.
Headers
.
Headers
[
headerName
]
:
null
;
:
null
;
}
}
}
}
...
@@ -84,9 +84,9 @@ namespace Titanium.Web.Proxy
...
@@ -84,9 +84,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
.
Request
Headers
.
NonUniqueHeaders
.
ContainsKey
(
"Authorization"
))
if
(
args
.
WebSession
.
Request
.
Headers
.
NonUniqueHeaders
.
ContainsKey
(
"Authorization"
))
{
{
args
.
WebSession
.
Request
.
Request
Headers
.
NonUniqueHeaders
.
Remove
(
"Authorization"
);
args
.
WebSession
.
Request
.
Headers
.
NonUniqueHeaders
.
Remove
(
"Authorization"
);
}
}
//initial value will match exactly any of the schemes
//initial value will match exactly any of the schemes
...
@@ -97,13 +97,13 @@ namespace Titanium.Web.Proxy
...
@@ -97,13 +97,13 @@ namespace Titanium.Web.Proxy
var
auth
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
var
auth
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
//replace existing authorization header if any
//replace existing authorization header if any
if
(
args
.
WebSession
.
Request
.
Request
Headers
.
Headers
.
ContainsKey
(
"Authorization"
))
if
(
args
.
WebSession
.
Request
.
Headers
.
Headers
.
ContainsKey
(
"Authorization"
))
{
{
args
.
WebSession
.
Request
.
Request
Headers
.
Headers
[
"Authorization"
]
=
auth
;
args
.
WebSession
.
Request
.
Headers
.
Headers
[
"Authorization"
]
=
auth
;
}
}
else
else
{
{
args
.
WebSession
.
Request
.
Request
Headers
.
Headers
.
Add
(
"Authorization"
,
auth
);
args
.
WebSession
.
Request
.
Headers
.
Headers
.
Add
(
"Authorization"
,
auth
);
}
}
//don't need to send body for Authorization request
//don't need to send body for Authorization request
...
@@ -122,12 +122,12 @@ namespace Titanium.Web.Proxy
...
@@ -122,12 +122,12 @@ 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
.
Request
Headers
.
Headers
[
"Authorization"
]
=
new
HttpHeader
(
"Authorization"
,
string
.
Concat
(
scheme
,
clientToken
));
args
.
WebSession
.
Request
.
Headers
.
Headers
[
"Authorization"
]
=
new
HttpHeader
(
"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
)
{
{
args
.
WebSession
.
Request
.
ContentLength
=
args
.
WebSession
.
Request
.
Request
Body
.
Length
;
args
.
WebSession
.
Request
.
ContentLength
=
args
.
WebSession
.
Request
.
Body
.
Length
;
}
}
}
}
...
...
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