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
Show 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
...
@@ -183,8 +183,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
internal
async
Task
ClearResponse
()
internal
async
Task
ClearResponse
()
{
{
//s
iphon out the body
//s
yphon out the response body from server
await
ReadResponseBodyAsync
(
);
await
SyphonOutBodyAsync
(
false
);
WebSession
.
Response
=
new
Response
();
WebSession
.
Response
=
new
Response
();
}
}
...
@@ -263,7 +263,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -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
;
var
requestResponse
=
isRequest
?
(
RequestResponseBase
)
WebSession
.
Request
:
WebSession
.
Response
;
if
(
requestResponse
.
IsBodyRead
||
!
requestResponse
.
OriginalHasBody
)
if
(
requestResponse
.
IsBodyRead
||
!
requestResponse
.
OriginalHasBody
)
...
@@ -476,7 +476,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -476,7 +476,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// Sets the request body
/// Sets the request body
/// </summary>
/// </summary>
/// <param name="body"></param>
/// <param name="body"></param>
public
async
Task
SetRequestBody
(
byte
[]
body
)
public
void
SetRequestBody
(
byte
[]
body
)
{
{
var
request
=
WebSession
.
Request
;
var
request
=
WebSession
.
Request
;
if
(
request
.
Locked
)
if
(
request
.
Locked
)
...
@@ -484,12 +484,6 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -484,12 +484,6 @@ namespace Titanium.Web.Proxy.EventArguments
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
if
(!
request
.
IsBodyRead
)
{
await
ReadRequestBodyAsync
();
}
request
.
Body
=
body
;
request
.
Body
=
body
;
request
.
UpdateContentLength
();
request
.
UpdateContentLength
();
}
}
...
@@ -498,20 +492,14 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -498,20 +492,14 @@ namespace Titanium.Web.Proxy.EventArguments
/// Sets the body with the specified string
/// Sets the body with the specified string
/// </summary>
/// </summary>
/// <param name="body"></param>
/// <param name="body"></param>
public
async
Task
SetRequestBodyString
(
string
body
)
public
void
SetRequestBodyString
(
string
body
)
{
{
if
(
WebSession
.
Request
.
Locked
)
if
(
WebSession
.
Request
.
Locked
)
{
{
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
SetRequestBody
(
WebSession
.
Request
.
Encoding
.
GetBytes
(
body
));
if
(!
WebSession
.
Request
.
IsBodyRead
)
{
await
ReadRequestBodyAsync
();
}
await
SetRequestBody
(
WebSession
.
Request
.
Encoding
.
GetBytes
(
body
));
}
}
/// <summary>
/// <summary>
...
@@ -546,7 +534,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -546,7 +534,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// Set the response body bytes
/// Set the response body bytes
/// </summary>
/// </summary>
/// <param name="body"></param>
/// <param name="body"></param>
public
async
Task
SetResponseBody
(
byte
[]
body
)
public
void
SetResponseBody
(
byte
[]
body
)
{
{
if
(!
WebSession
.
Request
.
Locked
)
if
(!
WebSession
.
Request
.
Locked
)
{
{
...
@@ -554,17 +542,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -554,17 +542,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
var
response
=
WebSession
.
Response
;
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
;
response
.
Body
=
body
;
//If there is a content length header update it
response
.
UpdateContentLength
();
}
}
/// <summary>
/// <summary>
...
@@ -586,7 +564,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -586,7 +564,7 @@ namespace Titanium.Web.Proxy.EventArguments
var
bodyBytes
=
WebSession
.
Response
.
Encoding
.
GetBytes
(
body
);
var
bodyBytes
=
WebSession
.
Response
.
Encoding
.
GetBytes
(
body
);
await
SetResponseBody
(
bodyBytes
);
SetResponseBody
(
bodyBytes
);
}
}
/// <summary>
/// <summary>
...
@@ -687,9 +665,15 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -687,9 +665,15 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
if
(
WebSession
.
Request
.
Locked
)
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
.
Response
=
response
;
}
else
{
WebSession
.
Request
.
Locked
=
true
;
WebSession
.
Request
.
Locked
=
true
;
response
.
Locked
=
true
;
response
.
Locked
=
true
;
...
@@ -699,6 +683,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -699,6 +683,7 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession
.
Request
.
CancelRequest
=
true
;
WebSession
.
Request
.
CancelRequest
=
true
;
}
}
}
/// <summary>
/// <summary>
/// implement any cleanup here
/// implement any cleanup here
...
...
Titanium.Web.Proxy/Http/RequestResponseBase.cs
View file @
ae80fbe1
...
@@ -132,6 +132,9 @@ namespace Titanium.Web.Proxy.Http
...
@@ -132,6 +132,9 @@ namespace Titanium.Web.Proxy.Http
{
{
body
=
value
;
body
=
value
;
bodyString
=
null
;
bodyString
=
null
;
//If there is a content length header update it
UpdateContentLength
();
}
}
}
}
...
@@ -166,7 +169,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -166,7 +169,7 @@ namespace Titanium.Web.Proxy.Http
internal
void
UpdateContentLength
()
internal
void
UpdateContentLength
()
{
{
ContentLength
=
IsChunked
?
-
1
:
body
.
Length
;
ContentLength
=
IsChunked
?
-
1
:
body
?.
Length
??
0
;
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
ae80fbe1
...
@@ -77,6 +77,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -77,6 +77,8 @@ namespace Titanium.Web.Proxy.Http
}
}
}
}
internal
bool
TerminateResponse
{
get
;
set
;
}
internal
override
void
EnsureBodyAvailable
(
bool
throwWhenNotReadYet
=
true
)
internal
override
void
EnsureBodyAvailable
(
bool
throwWhenNotReadYet
=
true
)
{
{
if
(!
IsBodyRead
&&
throwWhenNotReadYet
)
if
(!
IsBodyRead
&&
throwWhenNotReadYet
)
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
ae80fbe1
...
@@ -390,7 +390,9 @@ namespace Titanium.Web.Proxy
...
@@ -390,7 +390,9 @@ namespace Titanium.Web.Proxy
if
(
request
.
CancelRequest
)
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
);
await
HandleHttpSessionResponse
(
args
);
if
(!
response
.
KeepAlive
)
if
(!
response
.
KeepAlive
)
...
@@ -403,7 +405,7 @@ namespace Titanium.Web.Proxy
...
@@ -403,7 +405,7 @@ namespace Titanium.Web.Proxy
//create a new connection if hostname/upstream end point changes
//create a new connection if hostname/upstream end point changes
if
(
connection
!=
null
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
!=
null
&&
!
args
.
WebSession
.
UpStreamEndPoint
.
Equals
(
connection
.
UpStreamEndPoint
))))
&&
!
args
.
WebSession
.
UpStreamEndPoint
.
Equals
(
connection
.
UpStreamEndPoint
))))
{
{
...
@@ -420,7 +422,7 @@ namespace Titanium.Web.Proxy
...
@@ -420,7 +422,7 @@ namespace Titanium.Web.Proxy
if
(
request
.
UpgradeToWebSocket
)
if
(
request
.
UpgradeToWebSocket
)
{
{
//prepare the prefix content
//prepare the prefix content
var
requestHeaders
=
args
.
WebSession
.
R
equest
.
Headers
;
var
requestHeaders
=
r
equest
.
Headers
;
await
connection
.
StreamWriter
.
WriteLineAsync
(
httpCmd
);
await
connection
.
StreamWriter
.
WriteLineAsync
(
httpCmd
);
await
connection
.
StreamWriter
.
WriteHeadersAsync
(
requestHeaders
);
await
connection
.
StreamWriter
.
WriteHeadersAsync
(
requestHeaders
);
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
ae80fbe1
...
@@ -43,6 +43,12 @@ namespace Titanium.Web.Proxy
...
@@ -43,6 +43,12 @@ namespace Titanium.Web.Proxy
await
InvokeBeforeResponse
(
args
);
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
//if user requested to send request again
//likely after making modifications from User Response Handler
//likely after making modifications from User Response Handler
if
(
args
.
ReRequest
)
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