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
ae80fbe1
Commit
ae80fbe1
authored
Mar 27, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Terminate response property added
parent
4306e64c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
41 deletions
+39
-41
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+22
-37
RequestResponseBase.cs
Titanium.Web.Proxy/Http/RequestResponseBase.cs
+4
-1
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+2
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+5
-3
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+6
-0
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
ae80fbe1
...
...
@@ -183,8 +183,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
internal
async
Task
ClearResponse
()
{
//s
iphon out the body
await
ReadResponseBodyAsync
(
);
//s
yphon out the response body from server
await
SyphonOutBodyAsync
(
false
);
WebSession
.
Response
=
new
Response
();
}
...
...
@@ -263,7 +263,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
internal
async
Task
S
iphon
BodyAsync
(
bool
isRequest
)
internal
async
Task
S
yphonOut
BodyAsync
(
bool
isRequest
)
{
var
requestResponse
=
isRequest
?
(
RequestResponseBase
)
WebSession
.
Request
:
WebSession
.
Response
;
if
(
requestResponse
.
IsBodyRead
||
!
requestResponse
.
OriginalHasBody
)
...
...
@@ -476,7 +476,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// Sets the request body
/// </summary>
/// <param name="body"></param>
public
async
Task
SetRequestBody
(
byte
[]
body
)
public
void
SetRequestBody
(
byte
[]
body
)
{
var
request
=
WebSession
.
Request
;
if
(
request
.
Locked
)
...
...
@@ -484,12 +484,6 @@ namespace Titanium.Web.Proxy.EventArguments
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
if
(!
request
.
IsBodyRead
)
{
await
ReadRequestBodyAsync
();
}
request
.
Body
=
body
;
request
.
UpdateContentLength
();
}
...
...
@@ -498,20 +492,14 @@ namespace Titanium.Web.Proxy.EventArguments
/// Sets the body with the specified string
/// </summary>
/// <param name="body"></param>
public
async
Task
SetRequestBodyString
(
string
body
)
public
void
SetRequestBodyString
(
string
body
)
{
if
(
WebSession
.
Request
.
Locked
)
{
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
if
(!
WebSession
.
Request
.
IsBodyRead
)
{
await
ReadRequestBodyAsync
();
}
await
SetRequestBody
(
WebSession
.
Request
.
Encoding
.
GetBytes
(
body
));
SetRequestBody
(
WebSession
.
Request
.
Encoding
.
GetBytes
(
body
));
}
/// <summary>
...
...
@@ -546,7 +534,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// Set the response body bytes
/// </summary>
/// <param name="body"></param>
public
async
Task
SetResponseBody
(
byte
[]
body
)
public
void
SetResponseBody
(
byte
[]
body
)
{
if
(!
WebSession
.
Request
.
Locked
)
{
...
...
@@ -554,17 +542,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
var
response
=
WebSession
.
Response
;
//syphon out the response body from server before setting the new body
if
(
response
.
Body
==
null
)
{
await
GetResponseBody
();
}
response
.
Body
=
body
;
//If there is a content length header update it
response
.
UpdateContentLength
();
}
/// <summary>
...
...
@@ -586,7 +564,7 @@ namespace Titanium.Web.Proxy.EventArguments
var
bodyBytes
=
WebSession
.
Response
.
Encoding
.
GetBytes
(
body
);
await
SetResponseBody
(
bodyBytes
);
SetResponseBody
(
bodyBytes
);
}
/// <summary>
...
...
@@ -687,17 +665,24 @@ namespace Titanium.Web.Proxy.EventArguments
{
if
(
WebSession
.
Request
.
Locked
)
{
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
}
if
(
WebSession
.
Response
.
Locked
)
{
throw
new
Exception
(
"You cannot call this function after response is sent to the client."
);
}
WebSession
.
Request
.
Locked
=
true
;
WebSession
.
Response
=
response
;
}
else
{
WebSession
.
Request
.
Locked
=
true
;
response
.
Locked
=
true
;
response
.
IsBodyRead
=
true
;
response
.
Locked
=
true
;
response
.
IsBodyRead
=
true
;
WebSession
.
Response
=
response
;
WebSession
.
Response
=
response
;
WebSession
.
Request
.
CancelRequest
=
true
;
WebSession
.
Request
.
CancelRequest
=
true
;
}
}
/// <summary>
...
...
Titanium.Web.Proxy/Http/RequestResponseBase.cs
View file @
ae80fbe1
...
...
@@ -132,6 +132,9 @@ namespace Titanium.Web.Proxy.Http
{
body
=
value
;
bodyString
=
null
;
//If there is a content length header update it
UpdateContentLength
();
}
}
...
...
@@ -166,7 +169,7 @@ namespace Titanium.Web.Proxy.Http
internal
void
UpdateContentLength
()
{
ContentLength
=
IsChunked
?
-
1
:
body
.
Length
;
ContentLength
=
IsChunked
?
-
1
:
body
?.
Length
??
0
;
}
/// <summary>
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
ae80fbe1
...
...
@@ -77,6 +77,8 @@ namespace Titanium.Web.Proxy.Http
}
}
internal
bool
TerminateResponse
{
get
;
set
;
}
internal
override
void
EnsureBodyAvailable
(
bool
throwWhenNotReadYet
=
true
)
{
if
(!
IsBodyRead
&&
throwWhenNotReadYet
)
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
ae80fbe1
...
...
@@ -390,7 +390,9 @@ namespace Titanium.Web.Proxy
if
(
request
.
CancelRequest
)
{
await
args
.
SiphonBodyAsync
(
true
);
//syphon out the request body from client before setting the new body
await
args
.
SyphonOutBodyAsync
(
true
);
await
HandleHttpSessionResponse
(
args
);
if
(!
response
.
KeepAlive
)
...
...
@@ -403,7 +405,7 @@ namespace Titanium.Web.Proxy
//create a new connection if hostname/upstream end point changes
if
(
connection
!=
null
&&
(!
connection
.
HostName
.
Equals
(
args
.
WebSession
.
R
equest
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
)
&&
(!
connection
.
HostName
.
Equals
(
r
equest
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
)
||
(
args
.
WebSession
.
UpStreamEndPoint
!=
null
&&
!
args
.
WebSession
.
UpStreamEndPoint
.
Equals
(
connection
.
UpStreamEndPoint
))))
{
...
...
@@ -420,7 +422,7 @@ namespace Titanium.Web.Proxy
if
(
request
.
UpgradeToWebSocket
)
{
//prepare the prefix content
var
requestHeaders
=
args
.
WebSession
.
R
equest
.
Headers
;
var
requestHeaders
=
r
equest
.
Headers
;
await
connection
.
StreamWriter
.
WriteLineAsync
(
httpCmd
);
await
connection
.
StreamWriter
.
WriteHeadersAsync
(
requestHeaders
);
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
ae80fbe1
...
...
@@ -43,6 +43,12 @@ namespace Titanium.Web.Proxy
await
InvokeBeforeResponse
(
args
);
}
if
(
response
.
TerminateResponse
)
{
//syphon out the response body from server before setting the new body
await
args
.
SyphonOutBodyAsync
(
false
);
}
//if user requested to send request again
//likely after making modifications from User Response Handler
if
(
args
.
ReRequest
)
...
...
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