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
d1db0843
Commit
d1db0843
authored
Mar 24, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support chunked request
parent
196570c7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
27 deletions
+41
-27
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+10
-14
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+5
-0
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+5
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+15
-7
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+6
-6
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
d1db0843
...
@@ -452,19 +452,20 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -452,19 +452,20 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="body"></param>
/// <param name="body"></param>
public
async
Task
SetRequestBody
(
byte
[]
body
)
public
async
Task
SetRequestBody
(
byte
[]
body
)
{
{
if
(
WebSession
.
Request
.
RequestLocked
)
var
request
=
WebSession
.
Request
;
if
(
request
.
RequestLocked
)
{
{
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
}
}
//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
.
R
equest
.
IsBodyRead
)
if
(!
r
equest
.
IsBodyRead
)
{
{
await
ReadRequestBodyAsync
();
await
ReadRequestBodyAsync
();
}
}
WebSession
.
R
equest
.
Body
=
body
;
r
equest
.
Body
=
body
;
WebSession
.
Request
.
ContentLength
=
WebSession
.
Request
.
IsChunked
?
-
1
:
body
.
Length
;
request
.
UpdateContentLength
()
;
}
}
/// <summary>
/// <summary>
...
@@ -526,23 +527,18 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -526,23 +527,18 @@ namespace Titanium.Web.Proxy.EventArguments
throw
new
Exception
(
"You cannot call this function before request is made to server."
);
throw
new
Exception
(
"You cannot call this function before request is made to server."
);
}
}
var
response
=
WebSession
.
Response
;
//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
.
R
esponse
.
Body
==
null
)
if
(
r
esponse
.
Body
==
null
)
{
{
await
GetResponseBody
();
await
GetResponseBody
();
}
}
WebSession
.
R
esponse
.
Body
=
body
;
r
esponse
.
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
)
response
.
UpdateContentLength
();
{
WebSession
.
Response
.
ContentLength
=
body
.
Length
;
}
else
{
WebSession
.
Response
.
ContentLength
=
-
1
;
}
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
d1db0843
...
@@ -368,6 +368,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -368,6 +368,11 @@ namespace Titanium.Web.Proxy.Http
return
true
;
return
true
;
}
}
internal
void
UpdateContentLength
()
{
ContentLength
=
IsChunked
?
-
1
:
body
.
Length
;
}
/// <summary>
/// <summary>
/// Finish the session
/// Finish the session
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
d1db0843
...
@@ -281,6 +281,11 @@ namespace Titanium.Web.Proxy.Http
...
@@ -281,6 +281,11 @@ namespace Titanium.Web.Proxy.Http
statusDescription
=
httpResult
[
2
];
statusDescription
=
httpResult
[
2
];
}
}
internal
void
UpdateContentLength
()
{
ContentLength
=
IsChunked
?
-
1
:
body
.
Length
;
}
/// <summary>
/// <summary>
/// Finish the session
/// Finish the session
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
d1db0843
...
@@ -530,17 +530,25 @@ namespace Titanium.Web.Proxy
...
@@ -530,17 +530,25 @@ namespace Titanium.Web.Proxy
//If request was modified by user
//If request was modified by user
if
(
request
.
IsBodyRead
)
if
(
request
.
IsBodyRead
)
{
{
var
body
=
request
.
Body
;
bool
isChunked
=
request
.
IsChunked
;
string
contentEncoding
=
request
.
ContentEncoding
;
if
(
request
.
ContentEncoding
!=
null
)
var
body
=
request
.
Body
;
if
(
contentEncoding
!=
null
&&
body
!=
null
)
{
{
body
=
GetCompressedResponseBody
(
request
.
ContentEncoding
,
body
);
body
=
GetCompressedBody
(
contentEncoding
,
body
);
}
//chunked send is not supported as of now
if
(
isChunked
==
false
)
{
request
.
ContentLength
=
body
.
Length
;
request
.
ContentLength
=
body
.
Length
;
}
else
{
request
.
ContentLength
=
-
1
;
}
}
await
args
.
WebSession
.
ServerConnection
.
StreamWriter
.
Write
Async
(
body
);
await
args
.
WebSession
.
ServerConnection
.
StreamWriter
.
Write
BodyAsync
(
body
,
isChunked
);
}
}
else
else
{
{
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
d1db0843
...
@@ -83,9 +83,9 @@ namespace Titanium.Web.Proxy
...
@@ -83,9 +83,9 @@ namespace Titanium.Web.Proxy
string
contentEncoding
=
response
.
ContentEncoding
;
string
contentEncoding
=
response
.
ContentEncoding
;
var
body
=
response
.
Body
;
var
body
=
response
.
Body
;
if
(
contentEncoding
!=
null
)
if
(
contentEncoding
!=
null
&&
body
!=
null
)
{
{
body
=
GetCompressed
Response
Body
(
contentEncoding
,
body
);
body
=
GetCompressedBody
(
contentEncoding
,
body
);
if
(
isChunked
==
false
)
if
(
isChunked
==
false
)
{
{
...
@@ -118,19 +118,19 @@ namespace Titanium.Web.Proxy
...
@@ -118,19 +118,19 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <summary>
/// get the compressed
response body from give response
bytes
/// get the compressed
body from given
bytes
/// </summary>
/// </summary>
/// <param name="encodingType"></param>
/// <param name="encodingType"></param>
/// <param name="
responseB
ody"></param>
/// <param name="
b
ody"></param>
/// <returns></returns>
/// <returns></returns>
private
byte
[]
GetCompressed
ResponseBody
(
string
encodingType
,
byte
[]
responseB
ody
)
private
byte
[]
GetCompressed
Body
(
string
encodingType
,
byte
[]
b
ody
)
{
{
var
compressor
=
CompressionFactory
.
GetCompression
(
encodingType
);
var
compressor
=
CompressionFactory
.
GetCompression
(
encodingType
);
using
(
var
ms
=
new
MemoryStream
())
using
(
var
ms
=
new
MemoryStream
())
{
{
using
(
var
zip
=
compressor
.
GetStream
(
ms
))
using
(
var
zip
=
compressor
.
GetStream
(
ms
))
{
{
zip
.
Write
(
responseBody
,
0
,
responseB
ody
.
Length
);
zip
.
Write
(
body
,
0
,
b
ody
.
Length
);
}
}
return
ms
.
ToArray
();
return
ms
.
ToArray
();
...
...
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