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
1073c975
Commit
1073c975
authored
Jul 06, 2016
by
j.sander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only check for locked request if not read already.
parent
afe22a41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+18
-15
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
1073c975
...
@@ -62,8 +62,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -62,8 +62,7 @@ namespace Titanium.Web.Proxy.EventArguments
ProxyClient
=
new
ProxyClient
();
ProxyClient
=
new
ProxyClient
();
WebSession
=
new
HttpWebClient
();
WebSession
=
new
HttpWebClient
();
}
}
/// <summary>
/// <summary>
/// Read request body content as bytes[] for current session
/// Read request body content as bytes[] for current session
/// </summary>
/// </summary>
...
@@ -98,7 +97,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -98,7 +97,7 @@ namespace Titanium.Web.Proxy.EventArguments
await
this
.
ProxyClient
.
ClientStreamReader
.
CopyBytesToStream
(
bufferSize
,
requestBodyStream
,
WebSession
.
Request
.
ContentLength
);
await
this
.
ProxyClient
.
ClientStreamReader
.
CopyBytesToStream
(
bufferSize
,
requestBodyStream
,
WebSession
.
Request
.
ContentLength
);
}
}
else
if
(
WebSession
.
Request
.
HttpVersion
.
Major
==
1
&&
WebSession
.
Request
.
HttpVersion
.
Minor
==
0
)
else
if
(
WebSession
.
Request
.
HttpVersion
.
Major
==
1
&&
WebSession
.
Request
.
HttpVersion
.
Minor
==
0
)
await
WebSession
.
ServerConnection
.
StreamReader
.
CopyBytesToStream
(
bufferSize
,
requestBodyStream
,
long
.
MaxValue
);
await
WebSession
.
ServerConnection
.
StreamReader
.
CopyBytesToStream
(
bufferSize
,
requestBodyStream
,
long
.
MaxValue
);
}
}
WebSession
.
Request
.
RequestBody
=
await
GetDecompressedResponseBody
(
WebSession
.
Request
.
ContentEncoding
,
requestBodyStream
.
ToArray
());
WebSession
.
Request
.
RequestBody
=
await
GetDecompressedResponseBody
(
WebSession
.
Request
.
ContentEncoding
,
requestBodyStream
.
ToArray
());
...
@@ -108,7 +107,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -108,7 +107,7 @@ namespace Titanium.Web.Proxy.EventArguments
//So that next time we can deliver body from cache
//So that next time we can deliver body from cache
WebSession
.
Request
.
RequestBodyRead
=
true
;
WebSession
.
Request
.
RequestBodyRead
=
true
;
}
}
}
}
/// <summary>
/// <summary>
...
@@ -134,7 +133,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -134,7 +133,7 @@ namespace Titanium.Web.Proxy.EventArguments
await
WebSession
.
ServerConnection
.
StreamReader
.
CopyBytesToStream
(
bufferSize
,
responseBodyStream
,
WebSession
.
Response
.
ContentLength
);
await
WebSession
.
ServerConnection
.
StreamReader
.
CopyBytesToStream
(
bufferSize
,
responseBodyStream
,
WebSession
.
Response
.
ContentLength
);
}
}
else
if
(
WebSession
.
Response
.
HttpVersion
.
Major
==
1
&&
WebSession
.
Response
.
HttpVersion
.
Minor
==
0
)
else
if
(
WebSession
.
Response
.
HttpVersion
.
Major
==
1
&&
WebSession
.
Response
.
HttpVersion
.
Minor
==
0
)
await
WebSession
.
ServerConnection
.
StreamReader
.
CopyBytesToStream
(
bufferSize
,
responseBodyStream
,
long
.
MaxValue
);
await
WebSession
.
ServerConnection
.
StreamReader
.
CopyBytesToStream
(
bufferSize
,
responseBodyStream
,
long
.
MaxValue
);
}
}
...
@@ -152,10 +151,13 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -152,10 +151,13 @@ namespace Titanium.Web.Proxy.EventArguments
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
byte
[
]>
GetRequestBody
()
public
async
Task
<
byte
[
]>
GetRequestBody
()
{
{
if
(
WebSession
.
Request
.
RequestLocked
)
if
(!
WebSession
.
Request
.
RequestBodyRead
)
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
{
if
(
WebSession
.
Request
.
RequestLocked
)
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
await
ReadRequestBody
();
await
ReadRequestBody
();
}
return
WebSession
.
Request
.
RequestBody
;
return
WebSession
.
Request
.
RequestBody
;
}
}
/// <summary>
/// <summary>
...
@@ -164,12 +166,13 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -164,12 +166,13 @@ namespace Titanium.Web.Proxy.EventArguments
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
string
>
GetRequestBodyAsString
()
public
async
Task
<
string
>
GetRequestBodyAsString
()
{
{
if
(
WebSession
.
Request
.
RequestLocked
)
if
(!
WebSession
.
Request
.
RequestBodyRead
)
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
{
if
(
WebSession
.
Request
.
RequestLocked
)
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
await
ReadRequestBody
();
await
ReadRequestBody
();
}
//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
return
WebSession
.
Request
.
RequestBodyString
??
(
WebSession
.
Request
.
RequestBodyString
=
WebSession
.
Request
.
Encoding
.
GetString
(
WebSession
.
Request
.
RequestBody
));
return
WebSession
.
Request
.
RequestBodyString
??
(
WebSession
.
Request
.
RequestBodyString
=
WebSession
.
Request
.
Encoding
.
GetString
(
WebSession
.
Request
.
RequestBody
));
}
}
...
@@ -285,7 +288,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -285,7 +288,7 @@ namespace Titanium.Web.Proxy.EventArguments
var
bodyBytes
=
WebSession
.
Response
.
Encoding
.
GetBytes
(
body
);
var
bodyBytes
=
WebSession
.
Response
.
Encoding
.
GetBytes
(
body
);
await
SetResponseBody
(
bodyBytes
);
await
SetResponseBody
(
bodyBytes
);
}
}
private
async
Task
<
byte
[
]>
GetDecompressedResponseBody
(
string
encodingType
,
byte
[]
responseBodyStream
)
private
async
Task
<
byte
[
]>
GetDecompressedResponseBody
(
string
encodingType
,
byte
[]
responseBodyStream
)
{
{
...
@@ -345,7 +348,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -345,7 +348,7 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession
.
Request
.
CancelRequest
=
true
;
WebSession
.
Request
.
CancelRequest
=
true
;
}
}
/// a generic responder method
/// a generic responder method
public
async
Task
Respond
(
Response
response
)
public
async
Task
Respond
(
Response
response
)
{
{
...
...
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