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
8242536d
Commit
8242536d
authored
Dec 28, 2015
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate Request & Response
parent
27fc293a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
121 additions
and
97 deletions
+121
-97
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+5
-5
HttpWebRequestExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
+3
-3
HttpWebResponseExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebResponseExtensions.cs
+3
-3
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+67
-44
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+25
-24
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+18
-18
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
8242536d
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.EventArguments
internal
bool
RequestBodyRead
{
get
;
set
;
}
internal
bool
RequestBodyRead
{
get
;
set
;
}
public
List
<
HttpHeader
>
RequestHeaders
{
get
;
internal
set
;
}
public
List
<
HttpHeader
>
RequestHeaders
{
get
;
internal
set
;
}
internal
bool
RequestLocked
{
get
;
set
;
}
internal
bool
RequestLocked
{
get
;
set
;
}
internal
HttpWeb
Client
ProxySession
{
get
;
set
;
}
internal
HttpWeb
Session
ProxySession
{
get
;
set
;
}
internal
Encoding
ResponseEncoding
{
get
;
set
;
}
internal
Encoding
ResponseEncoding
{
get
;
set
;
}
internal
Stream
ResponseStream
{
get
;
set
;
}
internal
Stream
ResponseStream
{
get
;
set
;
}
...
@@ -69,13 +69,13 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -69,13 +69,13 @@ namespace Titanium.Web.Proxy.EventArguments
public
string
RequestMethod
public
string
RequestMethod
{
{
get
{
return
ProxySession
.
Method
;
}
get
{
return
ProxySession
.
Request
.
Method
;
}
}
}
public
string
ResponseStatusCode
public
string
ResponseStatusCode
{
{
get
{
return
ProxySession
.
ResponseStatusCode
;
}
get
{
return
ProxySession
.
Response
.
Response
StatusCode
;
}
}
}
public
string
ResponseContentType
public
string
ResponseContentType
...
@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy.EventArguments
private
void
ReadRequestBody
()
private
void
ReadRequestBody
()
{
{
if
((
ProxySession
.
Method
.
ToUpper
()
!=
"POST"
&&
ProxySession
.
Method
.
ToUpper
()
!=
"PUT"
))
if
((
ProxySession
.
Request
.
Method
.
ToUpper
()
!=
"POST"
&&
ProxySession
.
Request
.
Method
.
ToUpper
()
!=
"PUT"
))
{
{
throw
new
BodyNotFoundException
(
"Request don't have a body."
+
throw
new
BodyNotFoundException
(
"Request don't have a body."
+
"Please verify that this request is a Http POST/PUT and request content length is greater than zero before accessing the body."
);
"Please verify that this request is a Http POST/PUT and request content length is greater than zero before accessing the body."
);
...
@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
if
(
ResponseBody
==
null
)
if
(
ResponseBody
==
null
)
{
{
switch
(
ProxySession
.
ResponseContentEncoding
)
switch
(
ProxySession
.
Response
.
Response
ContentEncoding
)
{
{
case
"gzip"
:
case
"gzip"
:
ResponseBody
=
CompressionHelper
.
DecompressGzip
(
ResponseStream
);
ResponseBody
=
CompressionHelper
.
DecompressGzip
(
ResponseStream
);
...
...
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
View file @
8242536d
...
@@ -6,13 +6,13 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -6,13 +6,13 @@ namespace Titanium.Web.Proxy.Extensions
{
{
public
static
class
HttpWebRequestExtensions
public
static
class
HttpWebRequestExtensions
{
{
public
static
Encoding
GetEncoding
(
this
HttpWeb
Client
request
)
public
static
Encoding
GetEncoding
(
this
HttpWeb
Session
request
)
{
{
try
try
{
{
if
(
request
.
RequestContentType
==
null
)
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
if
(
request
.
Request
.
Request
ContentType
==
null
)
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
var
contentTypes
=
request
.
RequestContentType
.
Split
(
';'
);
var
contentTypes
=
request
.
Request
.
Request
ContentType
.
Split
(
';'
);
foreach
(
var
contentType
in
contentTypes
)
foreach
(
var
contentType
in
contentTypes
)
{
{
var
encodingSplit
=
contentType
.
Split
(
'='
);
var
encodingSplit
=
contentType
.
Split
(
'='
);
...
...
Titanium.Web.Proxy/Extensions/HttpWebResponseExtensions.cs
View file @
8242536d
...
@@ -6,10 +6,10 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -6,10 +6,10 @@ namespace Titanium.Web.Proxy.Extensions
{
{
public
static
class
HttpWebResponseExtensions
public
static
class
HttpWebResponseExtensions
{
{
public
static
Encoding
GetResponseEncoding
(
this
HttpWeb
Client
response
)
public
static
Encoding
GetResponseEncoding
(
this
HttpWeb
Session
response
)
{
{
if
(
string
.
IsNullOrEmpty
(
response
.
ResponseCharacterSet
))
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
if
(
string
.
IsNullOrEmpty
(
response
.
Response
.
Response
CharacterSet
))
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
return
Encoding
.
GetEncoding
(
response
.
Response
CharacterSet
.
Replace
(
@""""
,
string
.
Empty
));
return
Encoding
.
GetEncoding
(
response
.
Response
.
ResponseCharacterSet
.
Replace
(
@""""
,
string
.
Empty
));
}
}
}
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
8242536d
...
@@ -12,10 +12,8 @@ using Titanium.Web.Proxy.Models;
...
@@ -12,10 +12,8 @@ using Titanium.Web.Proxy.Models;
namespace
Titanium.Web.Proxy.Http
namespace
Titanium.Web.Proxy.Http
{
{
public
class
HttpWebClien
t
public
class
Reques
t
{
{
private
const
string
Space
=
" "
;
public
string
Method
{
get
;
set
;
}
public
string
Method
{
get
;
set
;
}
public
Uri
RequestUri
{
get
;
set
;
}
public
Uri
RequestUri
{
get
;
set
;
}
...
@@ -24,30 +22,75 @@ namespace Titanium.Web.Proxy.Http
...
@@ -24,30 +22,75 @@ namespace Titanium.Web.Proxy.Http
public
List
<
HttpHeader
>
RequestHeaders
{
get
;
set
;
}
public
List
<
HttpHeader
>
RequestHeaders
{
get
;
set
;
}
public
bool
IsSecure
public
string
RequestStatus
{
get
;
set
;
}
public
int
RequestContentLength
{
get
;
set
;
}
public
bool
RequestSendChunked
{
get
;
set
;
}
public
string
RequestContentType
{
get
;
set
;
}
public
bool
RequestKeepAlive
{
get
;
set
;
}
public
string
RequestHost
{
get
;
set
;
}
public
Request
()
{
{
get
this
.
RequestHeaders
=
new
List
<
HttpHeader
>();
{
return
this
.
RequestUri
.
Scheme
==
Uri
.
UriSchemeHttps
;
}
}
}
}
public
TcpClient
Client
{
get
;
set
;
}
public
class
Response
{
public
string
RequestStatus
{
get
;
set
;
}
public
List
<
HttpHeader
>
ResponseHeaders
{
get
;
set
;
}
public
List
<
HttpHeader
>
ResponseHeaders
{
get
;
set
;
}
public
int
RequestContentLength
{
get
;
set
;
}
public
string
ResponseCharacterSet
{
get
;
set
;
}
public
bool
RequestSendChunked
{
get
;
set
;
}
public
string
ResponseContentEncoding
{
get
;
set
;
}
public
System
.
Version
ResponseProtocolVersion
{
get
;
set
;
}
public
string
ResponseStatusCode
{
get
;
set
;
}
public
string
ResponseStatusDescription
{
get
;
set
;
}
public
bool
ResponseKeepAlive
{
get
;
set
;
}
public
string
ResponseContentType
{
get
;
set
;
}
public
HttpWebClient
()
public
Response
()
{
{
this
.
RequestHeaders
=
new
List
<
HttpHeader
>();
this
.
ResponseHeaders
=
new
List
<
HttpHeader
>();
this
.
ResponseHeaders
=
new
List
<
HttpHeader
>();
}
}
public
int
ContentLength
{
get
;
set
;
}
}
public
class
HttpWebSession
{
private
const
string
Space
=
" "
;
public
bool
IsSecure
{
get
{
return
this
.
Request
.
RequestUri
.
Scheme
==
Uri
.
UriSchemeHttps
;
}
}
public
Request
Request
{
get
;
set
;
}
public
Response
Response
{
get
;
set
;
}
public
TcpClient
Client
{
get
;
set
;
}
public
HttpWebSession
()
{
this
.
Request
=
new
Request
();
this
.
Response
=
new
Response
();
}
public
CustomBinaryReader
ServerStreamReader
{
get
;
set
;
}
public
CustomBinaryReader
ServerStreamReader
{
get
;
set
;
}
public
async
Task
SendRequest
()
public
async
Task
SendRequest
()
...
@@ -58,12 +101,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -58,12 +101,12 @@ namespace Titanium.Web.Proxy.Http
requestLines
.
AppendLine
(
string
.
Join
(
" "
,
new
string
[
3
]
requestLines
.
AppendLine
(
string
.
Join
(
" "
,
new
string
[
3
]
{
{
this
.
Method
,
this
.
Request
.
Method
,
this
.
RequestUri
.
AbsolutePath
,
this
.
Request
.
Request
Uri
.
AbsolutePath
,
this
.
Version
this
.
Request
.
Version
}));
}));
foreach
(
HttpHeader
httpHeader
in
this
.
RequestHeaders
)
foreach
(
HttpHeader
httpHeader
in
this
.
Request
.
Request
Headers
)
{
{
requestLines
.
AppendLine
(
httpHeader
.
Name
+
':'
+
httpHeader
.
Value
);
requestLines
.
AppendLine
(
httpHeader
.
Name
+
':'
+
httpHeader
.
Value
);
...
@@ -77,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -77,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
await
AsyncExtensions
.
FlushAsync
((
Stream
)
stream
);
await
AsyncExtensions
.
FlushAsync
((
Stream
)
stream
);
}
}
public
void
ReceiveResponse
()
public
void
ReceiveResponse
()
{
{
Stream
stream
=
Client
.
GetStream
();
Stream
stream
=
Client
.
GetStream
();
ServerStreamReader
=
new
CustomBinaryReader
(
stream
,
Encoding
.
ASCII
);
ServerStreamReader
=
new
CustomBinaryReader
(
stream
,
Encoding
.
ASCII
);
...
@@ -95,46 +138,26 @@ namespace Titanium.Web.Proxy.Http
...
@@ -95,46 +138,26 @@ namespace Titanium.Web.Proxy.Http
version
=
new
Version
(
1
,
0
);
version
=
new
Version
(
1
,
0
);
}
}
this
.
ResponseProtocolVersion
=
version
;
this
.
Response
.
Response
ProtocolVersion
=
version
;
this
.
ResponseStatusCode
=
httpResult
[
1
];
this
.
Response
.
Response
StatusCode
=
httpResult
[
1
];
string
status
=
httpResult
[
2
];
string
status
=
httpResult
[
2
];
for
(
int
i
=
3
;
i
<
httpResult
.
Length
;
i
++)
for
(
int
i
=
3
;
i
<
httpResult
.
Length
;
i
++)
{
{
status
=
status
+
Space
+
httpResult
[
i
];
status
=
status
+
Space
+
httpResult
[
i
];
}
}
this
.
ResponseStatusDescription
=
status
;
this
.
Response
.
Response
StatusDescription
=
status
;
List
<
string
>
responseLines
=
ServerStreamReader
.
ReadAllLines
();
List
<
string
>
responseLines
=
ServerStreamReader
.
ReadAllLines
();
for
(
int
index
=
0
;
index
<
responseLines
.
Count
;
++
index
)
for
(
int
index
=
0
;
index
<
responseLines
.
Count
;
++
index
)
{
{
string
[]
strArray
=
responseLines
[
index
].
Split
(
':'
);
string
[]
strArray
=
responseLines
[
index
].
Split
(
':'
);
this
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
strArray
[
0
],
strArray
[
1
]));
this
.
Response
.
Response
Headers
.
Add
(
new
HttpHeader
(
strArray
[
0
],
strArray
[
1
]));
}
}
}
}
public
string
RequestContentType
{
get
;
set
;
}
public
bool
RequestKeepAlive
{
get
;
set
;
}
public
string
RequestHost
{
get
;
set
;
}
public
string
ResponseCharacterSet
{
get
;
set
;
}
public
string
ResponseContentEncoding
{
get
;
set
;
}
public
System
.
Version
ResponseProtocolVersion
{
get
;
set
;
}
public
string
ResponseStatusCode
{
get
;
set
;
}
public
string
ResponseStatusDescription
{
get
;
set
;
}
public
bool
ResponseKeepAlive
{
get
;
set
;
}
public
string
ResponseContentType
{
get
;
set
;
}
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
8242536d
...
@@ -176,28 +176,28 @@ namespace Titanium.Web.Proxy
...
@@ -176,28 +176,28 @@ namespace Titanium.Web.Proxy
}
}
//construct the web request that we are going to issue on behalf of the client.
//construct the web request that we are going to issue on behalf of the client.
args
.
ProxySession
=
new
Http
.
HttpWeb
Client
();
args
.
ProxySession
=
new
Http
.
HttpWeb
Session
();
args
.
ProxySession
.
RequestUri
=
httpRemoteUri
;
args
.
ProxySession
.
Request
.
Request
Uri
=
httpRemoteUri
;
//args.ProxyRequest.Proxy = null;
//args.ProxyRequest.Proxy = null;
//args.ProxyRequest.UseDefaultCredentials = true;
//args.ProxyRequest.UseDefaultCredentials = true;
args
.
ProxySession
.
Method
=
httpMethod
;
args
.
ProxySession
.
Request
.
Method
=
httpMethod
;
args
.
ProxySession
.
Version
=
httpVersion
;
args
.
ProxySession
.
Request
.
Version
=
httpVersion
;
// args.ProxyRequest.ProtocolVersion = version;
// args.ProxyRequest.ProtocolVersion = version;
args
.
ClientStream
=
clientStream
;
args
.
ClientStream
=
clientStream
;
args
.
ClientStreamReader
=
clientStreamReader
;
args
.
ClientStreamReader
=
clientStreamReader
;
args
.
ClientStreamWriter
=
clientStreamWriter
;
args
.
ClientStreamWriter
=
clientStreamWriter
;
// args.ProxyRequest.AllowAutoRedirect = false;
// args.ProxyRequest.AllowAutoRedirect = false;
// args.ProxyRequest.AutomaticDecompression = DecompressionMethods.None;
// args.ProxyRequest.AutomaticDecompression = DecompressionMethods.None;
args
.
RequestHostname
=
args
.
ProxySession
.
RequestUri
.
Host
;
args
.
RequestHostname
=
args
.
ProxySession
.
Request
.
Request
Uri
.
Host
;
args
.
RequestUrl
=
args
.
ProxySession
.
RequestUri
.
OriginalString
;
args
.
RequestUrl
=
args
.
ProxySession
.
Request
.
Request
Uri
.
OriginalString
;
args
.
ClientPort
=
((
IPEndPoint
)
client
.
Client
.
RemoteEndPoint
).
Port
;
args
.
ClientPort
=
((
IPEndPoint
)
client
.
Client
.
RemoteEndPoint
).
Port
;
args
.
ClientIpAddress
=
((
IPEndPoint
)
client
.
Client
.
RemoteEndPoint
).
Address
;
args
.
ClientIpAddress
=
((
IPEndPoint
)
client
.
Client
.
RemoteEndPoint
).
Address
;
args
.
RequestHttpVersion
=
version
;
args
.
RequestHttpVersion
=
version
;
//args.RequestIsAlive = args.ProxyRequest.KeepAlive;
//args.RequestIsAlive = args.ProxyRequest.KeepAlive;
//args.ProxyRequest.AllowWriteStreamBuffering = true;
//args.ProxyRequest.AllowWriteStreamBuffering = true;
args
.
Client
=
await
TcpConnectionManager
.
GetClient
(
args
.
ProxySession
.
Request
Uri
.
Host
,
args
.
ProxySession
.
RequestUri
.
Port
,
args
.
IsHttps
);
args
.
Client
=
await
TcpConnectionManager
.
GetClient
(
args
.
ProxySession
.
Request
.
RequestUri
.
Host
,
args
.
ProxySession
.
Request
.
RequestUri
.
Port
,
args
.
IsHttps
);
args
.
ProxySession
.
Client
=
args
.
Client
;
args
.
ProxySession
.
Client
=
args
.
Client
;
//If requested interception
//If requested interception
if
(
BeforeRequest
!=
null
)
if
(
BeforeRequest
!=
null
)
...
@@ -221,7 +221,7 @@ namespace Titanium.Web.Proxy
...
@@ -221,7 +221,7 @@ namespace Titanium.Web.Proxy
//If request was modified by user
//If request was modified by user
if
(
args
.
RequestBodyRead
)
if
(
args
.
RequestBodyRead
)
{
{
args
.
ProxySession
.
RequestContentLength
=
args
.
RequestBody
.
Length
;
args
.
ProxySession
.
Request
.
Request
ContentLength
=
args
.
RequestBody
.
Length
;
var
newStream
=
args
.
ProxySession
.
ServerStreamReader
.
BaseStream
;
var
newStream
=
args
.
ProxySession
.
ServerStreamReader
.
BaseStream
;
newStream
.
Write
(
args
.
RequestBody
,
0
,
args
.
RequestBody
.
Length
);
newStream
.
Write
(
args
.
RequestBody
,
0
,
args
.
RequestBody
.
Length
);
}
}
...
@@ -243,6 +243,7 @@ namespace Titanium.Web.Proxy
...
@@ -243,6 +243,7 @@ namespace Titanium.Web.Proxy
return
;
return
;
}
}
//TcpConnectionManager.AddClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps, args.ProxySession.Client);
// read the next request
// read the next request
httpCmd
=
clientStreamReader
.
ReadLine
();
httpCmd
=
clientStreamReader
.
ReadLine
();
...
@@ -264,7 +265,7 @@ namespace Titanium.Web.Proxy
...
@@ -264,7 +265,7 @@ namespace Titanium.Web.Proxy
clientStreamWriter
.
Flush
();
clientStreamWriter
.
Flush
();
}
}
private
static
void
SetRequestHeaders
(
List
<
HttpHeader
>
requestHeaders
,
HttpWeb
Client
webRequest
)
private
static
void
SetRequestHeaders
(
List
<
HttpHeader
>
requestHeaders
,
HttpWeb
Session
webRequest
)
{
{
for
(
var
i
=
0
;
i
<
requestHeaders
.
Count
;
i
++)
for
(
var
i
=
0
;
i
<
requestHeaders
.
Count
;
i
++)
{
{
...
@@ -281,16 +282,16 @@ namespace Titanium.Web.Proxy
...
@@ -281,16 +282,16 @@ namespace Titanium.Web.Proxy
break
;
break
;
case
"connection"
:
case
"connection"
:
if
(
requestHeaders
[
i
].
Value
.
ToLower
()
==
"keep-alive"
)
if
(
requestHeaders
[
i
].
Value
.
ToLower
()
==
"keep-alive"
)
webRequest
.
RequestKeepAlive
=
true
;
webRequest
.
Request
.
Request
KeepAlive
=
true
;
break
;
break
;
case
"content-length"
:
case
"content-length"
:
int
contentLen
;
int
contentLen
;
int
.
TryParse
(
requestHeaders
[
i
].
Value
,
out
contentLen
);
int
.
TryParse
(
requestHeaders
[
i
].
Value
,
out
contentLen
);
if
(
contentLen
!=
0
)
if
(
contentLen
!=
0
)
webRequest
.
RequestContentLength
=
contentLen
;
webRequest
.
Request
.
Request
ContentLength
=
contentLen
;
break
;
break
;
case
"content-type"
:
case
"content-type"
:
webRequest
.
RequestContentType
=
requestHeaders
[
i
].
Value
;
webRequest
.
Request
.
Request
ContentType
=
requestHeaders
[
i
].
Value
;
break
;
break
;
case
"expect"
:
case
"expect"
:
//if (requestHeaders[i].Value.ToLower() == "100-continue")
//if (requestHeaders[i].Value.ToLower() == "100-continue")
...
@@ -299,7 +300,7 @@ namespace Titanium.Web.Proxy
...
@@ -299,7 +300,7 @@ namespace Titanium.Web.Proxy
// webRequest.Expect = requestHeaders[i].Value;
// webRequest.Expect = requestHeaders[i].Value;
break
;
break
;
case
"host"
:
case
"host"
:
webRequest
.
RequestHost
=
requestHeaders
[
i
].
Value
;
webRequest
.
Request
.
Request
Host
=
requestHeaders
[
i
].
Value
;
break
;
break
;
case
"if-modified-since"
:
case
"if-modified-since"
:
// var sb = requestHeaders[i].Value.Trim().Split(SemiSplit);
// var sb = requestHeaders[i].Value.Trim().Split(SemiSplit);
...
@@ -309,9 +310,9 @@ namespace Titanium.Web.Proxy
...
@@ -309,9 +310,9 @@ namespace Titanium.Web.Proxy
break
;
break
;
case
"proxy-connection"
:
case
"proxy-connection"
:
if
(
requestHeaders
[
i
].
Value
.
ToLower
()
==
"keep-alive"
)
if
(
requestHeaders
[
i
].
Value
.
ToLower
()
==
"keep-alive"
)
webRequest
.
RequestKeepAlive
=
true
;
webRequest
.
Request
.
Request
KeepAlive
=
true
;
else
if
(
requestHeaders
[
i
].
Value
.
ToLower
()
==
"close"
)
else
if
(
requestHeaders
[
i
].
Value
.
ToLower
()
==
"close"
)
webRequest
.
RequestKeepAlive
=
false
;
webRequest
.
Request
.
Request
KeepAlive
=
false
;
break
;
break
;
case
"range"
:
case
"range"
:
// var startEnd = requestHeaders[i].Value.Replace(Environment.NewLine, "").Remove(0, 6).Split('-');
// var startEnd = requestHeaders[i].Value.Replace(Environment.NewLine, "").Remove(0, 6).Split('-');
...
@@ -335,9 +336,9 @@ namespace Titanium.Web.Proxy
...
@@ -335,9 +336,9 @@ namespace Titanium.Web.Proxy
//But how to identify if client is sending chunked body for PUT/POST?
//But how to identify if client is sending chunked body for PUT/POST?
case
"transfer-encoding"
:
case
"transfer-encoding"
:
if
(
requestHeaders
[
i
].
Value
.
ToLower
().
Contains
(
"chunked"
))
if
(
requestHeaders
[
i
].
Value
.
ToLower
().
Contains
(
"chunked"
))
webRequest
.
RequestSendChunked
=
true
;
webRequest
.
Request
.
Request
SendChunked
=
true
;
else
else
webRequest
.
RequestSendChunked
=
false
;
webRequest
.
Request
.
Request
SendChunked
=
false
;
break
;
break
;
case
"upgrade"
:
case
"upgrade"
:
// if (requestHeaders[i].Value.ToLower() == "http/1.1")
// if (requestHeaders[i].Value.ToLower() == "http/1.1")
...
@@ -351,7 +352,7 @@ namespace Titanium.Web.Proxy
...
@@ -351,7 +352,7 @@ namespace Titanium.Web.Proxy
}
}
}
}
webRequest
.
RequestHeaders
=
requestHeaders
;
webRequest
.
Request
.
Request
Headers
=
requestHeaders
;
}
}
//This is called when the request is PUT/POST to read the body
//This is called when the request is PUT/POST to read the body
...
@@ -361,7 +362,7 @@ namespace Titanium.Web.Proxy
...
@@ -361,7 +362,7 @@ namespace Titanium.Web.Proxy
var
postStream
=
args
.
ProxySession
.
ServerStreamReader
;
var
postStream
=
args
.
ProxySession
.
ServerStreamReader
;
if
(
args
.
ProxySession
.
RequestContentLength
>
0
)
if
(
args
.
ProxySession
.
Request
.
Request
ContentLength
>
0
)
{
{
//args.ProxyRequest.AllowWriteStreamBuffering = true;
//args.ProxyRequest.AllowWriteStreamBuffering = true;
try
try
...
@@ -369,20 +370,20 @@ namespace Titanium.Web.Proxy
...
@@ -369,20 +370,20 @@ namespace Titanium.Web.Proxy
var
totalbytesRead
=
0
;
var
totalbytesRead
=
0
;
int
bytesToRead
;
int
bytesToRead
;
if
(
args
.
ProxySession
.
RequestContentLength
<
BUFFER_SIZE
)
if
(
args
.
ProxySession
.
Request
.
Request
ContentLength
<
BUFFER_SIZE
)
{
{
bytesToRead
=
(
int
)
args
.
ProxySession
.
RequestContentLength
;
bytesToRead
=
(
int
)
args
.
ProxySession
.
Request
.
Request
ContentLength
;
}
}
else
else
bytesToRead
=
BUFFER_SIZE
;
bytesToRead
=
BUFFER_SIZE
;
while
(
totalbytesRead
<
(
int
)
args
.
ProxySession
.
RequestContentLength
)
while
(
totalbytesRead
<
(
int
)
args
.
ProxySession
.
Request
.
Request
ContentLength
)
{
{
var
buffer
=
args
.
ClientStreamReader
.
ReadBytes
(
bytesToRead
);
var
buffer
=
args
.
ClientStreamReader
.
ReadBytes
(
bytesToRead
);
totalbytesRead
+=
buffer
.
Length
;
totalbytesRead
+=
buffer
.
Length
;
var
remainingBytes
=
(
int
)
args
.
ProxySession
.
RequestContentLength
-
totalbytesRead
;
var
remainingBytes
=
(
int
)
args
.
ProxySession
.
Request
.
Request
ContentLength
-
totalbytesRead
;
if
(
remainingBytes
<
bytesToRead
)
if
(
remainingBytes
<
bytesToRead
)
{
{
bytesToRead
=
remainingBytes
;
bytesToRead
=
remainingBytes
;
...
@@ -400,7 +401,7 @@ namespace Titanium.Web.Proxy
...
@@ -400,7 +401,7 @@ namespace Titanium.Web.Proxy
}
}
}
}
//Need to revist, find any potential bugs
//Need to revist, find any potential bugs
else
if
(
args
.
ProxySession
.
RequestSendChunked
)
else
if
(
args
.
ProxySession
.
Request
.
Request
SendChunked
)
{
{
//args.ProxyRequest.AllowWriteStreamBuffering = true;
//args.ProxyRequest.AllowWriteStreamBuffering = true;
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
8242536d
...
@@ -39,8 +39,8 @@ namespace Titanium.Web.Proxy
...
@@ -39,8 +39,8 @@ namespace Titanium.Web.Proxy
if
(
args
.
ResponseBodyRead
)
if
(
args
.
ResponseBodyRead
)
{
{
var
isChunked
=
args
.
ProxySession
.
ResponseHeaders
.
Any
(
x
=>
x
.
Name
.
ToLower
()
==
"transfer-encoding"
&&
x
.
Value
.
ToLower
().
Contains
(
"chunked"
));
var
isChunked
=
args
.
ProxySession
.
Response
.
Response
Headers
.
Any
(
x
=>
x
.
Name
.
ToLower
()
==
"transfer-encoding"
&&
x
.
Value
.
ToLower
().
Contains
(
"chunked"
));
var
contentEncoding
=
args
.
ProxySession
.
ResponseContentEncoding
;
var
contentEncoding
=
args
.
ProxySession
.
Response
.
Response
ContentEncoding
;
switch
(
contentEncoding
.
ToLower
())
switch
(
contentEncoding
.
ToLower
())
{
{
...
@@ -55,8 +55,8 @@ namespace Titanium.Web.Proxy
...
@@ -55,8 +55,8 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
WriteResponseStatus
(
args
.
ProxySession
.
Response
ProtocolVersion
,
args
.
ProxySession
.
ResponseStatusCode
,
WriteResponseStatus
(
args
.
ProxySession
.
Response
.
ResponseProtocolVersion
,
args
.
ProxySession
.
Response
.
ResponseStatusCode
,
args
.
ProxySession
.
ResponseStatusDescription
,
args
.
ClientStreamWriter
);
args
.
ProxySession
.
Response
.
Response
StatusDescription
,
args
.
ClientStreamWriter
);
WriteResponseHeaders
(
args
.
ClientStreamWriter
,
args
.
ResponseHeaders
,
args
.
ResponseBody
.
Length
,
WriteResponseHeaders
(
args
.
ClientStreamWriter
,
args
.
ResponseHeaders
,
args
.
ResponseBody
.
Length
,
isChunked
);
isChunked
);
WriteResponseBody
(
args
.
ClientStream
,
args
.
ResponseBody
,
isChunked
);
WriteResponseBody
(
args
.
ClientStream
,
args
.
ResponseBody
,
isChunked
);
...
@@ -65,10 +65,10 @@ namespace Titanium.Web.Proxy
...
@@ -65,10 +65,10 @@ namespace Titanium.Web.Proxy
{
{
// var isChunked = args.ProxySession.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked"));
// var isChunked = args.ProxySession.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked"));
WriteResponseStatus
(
args
.
ProxySession
.
Response
ProtocolVersion
,
args
.
ProxySession
.
ResponseStatusCode
,
WriteResponseStatus
(
args
.
ProxySession
.
Response
.
ResponseProtocolVersion
,
args
.
ProxySession
.
Response
.
ResponseStatusCode
,
args
.
ProxySession
.
ResponseStatusDescription
,
args
.
ClientStreamWriter
);
args
.
ProxySession
.
Response
.
Response
StatusDescription
,
args
.
ClientStreamWriter
);
WriteResponseHeaders
(
args
.
ClientStreamWriter
,
args
.
ResponseHeaders
);
WriteResponseHeaders
(
args
.
ClientStreamWriter
,
args
.
ResponseHeaders
);
WriteResponseBody
(
args
.
ResponseStream
,
args
.
ClientStream
,
false
);
WriteResponseBody
(
args
.
ResponseStream
,
args
.
ClientStream
,
false
,
args
.
ProxySession
.
Response
.
ContentLength
);
}
}
args
.
ClientStream
.
Flush
();
args
.
ClientStream
.
Flush
();
...
@@ -84,24 +84,24 @@ namespace Titanium.Web.Proxy
...
@@ -84,24 +84,24 @@ namespace Titanium.Web.Proxy
}
}
}
}
private
static
List
<
HttpHeader
>
ReadResponseHeaders
(
HttpWeb
Client
response
)
private
static
List
<
HttpHeader
>
ReadResponseHeaders
(
HttpWeb
Session
response
)
{
{
for
(
var
i
=
0
;
i
<
response
.
ResponseHeaders
.
Count
;
i
++)
for
(
var
i
=
0
;
i
<
response
.
Response
.
Response
Headers
.
Count
;
i
++)
{
{
switch
(
response
.
ResponseHeaders
[
i
].
Name
.
ToLower
())
switch
(
response
.
Response
.
Response
Headers
[
i
].
Name
.
ToLower
())
{
{
case
"content-encoding"
:
case
"content-encoding"
:
response
.
Response
ContentEncoding
=
r
esponse
.
ResponseHeaders
[
i
].
Value
;
response
.
Response
.
ResponseContentEncoding
=
response
.
R
esponse
.
ResponseHeaders
[
i
].
Value
;
break
;
break
;
case
"content-type"
:
case
"content-type"
:
if
(
response
.
ResponseHeaders
[
i
].
Value
.
Contains
(
";"
))
if
(
response
.
Response
.
Response
Headers
[
i
].
Value
.
Contains
(
";"
))
{
{
response
.
Response
ContentType
=
r
esponse
.
ResponseHeaders
[
i
].
Value
.
Split
(
';'
)[
0
].
Trim
();
response
.
Response
.
ResponseContentType
=
response
.
R
esponse
.
ResponseHeaders
[
i
].
Value
.
Split
(
';'
)[
0
].
Trim
();
response
.
Response
CharacterSet
=
r
esponse
.
ResponseHeaders
[
i
].
Value
.
Split
(
';'
)[
1
].
Replace
(
"charset="
,
string
.
Empty
).
Trim
();
response
.
Response
.
ResponseCharacterSet
=
response
.
R
esponse
.
ResponseHeaders
[
i
].
Value
.
Split
(
';'
)[
1
].
Replace
(
"charset="
,
string
.
Empty
).
Trim
();
}
}
else
else
response
.
Response
ContentType
=
r
esponse
.
ResponseHeaders
[
i
].
Value
.
Trim
();
response
.
Response
.
ResponseContentType
=
response
.
R
esponse
.
ResponseHeaders
[
i
].
Value
.
Trim
();
break
;
break
;
...
@@ -113,8 +113,8 @@ namespace Titanium.Web.Proxy
...
@@ -113,8 +113,8 @@ namespace Titanium.Web.Proxy
}
}
}
}
// response.ResponseHeaders.RemoveAll(x => x.Name.ToLower() == "connection");
// response.ResponseHeaders.RemoveAll(x => x.Name.ToLower() == "connection");
return
response
.
ResponseHeaders
;
return
response
.
Response
.
Response
Headers
;
}
}
private
static
void
WriteResponseStatus
(
Version
version
,
string
code
,
string
description
,
private
static
void
WriteResponseStatus
(
Version
version
,
string
code
,
string
description
,
...
@@ -190,7 +190,7 @@ namespace Titanium.Web.Proxy
...
@@ -190,7 +190,7 @@ namespace Titanium.Web.Proxy
WriteResponseBodyChunked
(
data
,
clientStream
);
WriteResponseBodyChunked
(
data
,
clientStream
);
}
}
private
static
void
WriteResponseBody
(
Stream
inStream
,
Stream
outStream
,
bool
isChunked
)
private
static
void
WriteResponseBody
(
Stream
inStream
,
Stream
outStream
,
bool
isChunked
,
int
BodyLength
)
{
{
if
(!
isChunked
)
if
(!
isChunked
)
{
{
...
...
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