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
387d6618
Commit
387d6618
authored
Nov 16, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
throw BodyNotFoundException in Request.Body when it has no body
parent
730d4866
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
28 deletions
+37
-28
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-11
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+25
-10
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+11
-7
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
387d6618
...
@@ -136,17 +136,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -136,17 +136,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
private
async
Task
ReadRequestBody
()
private
async
Task
ReadRequestBody
()
{
{
//GET request don't have a request body to read
WebSession
.
Request
.
EnsureBodyAvailable
(
false
);
if
(!
WebSession
.
Request
.
HasBody
)
{
throw
new
BodyNotFoundException
(
"Request don't have a body. "
+
"Please verify that this request is a Http POST/PUT/PATCH and request "
+
"content length is greater than zero before accessing the body."
);
}
if
(
WebSession
.
Request
.
RequestLocked
)
{
throw
new
Exception
(
"You cannot get the request body after request is made to server."
);
}
//Caching check
//Caching check
if
(!
WebSession
.
Request
.
IsBodyRead
)
if
(!
WebSession
.
Request
.
IsBodyRead
)
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
387d6618
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Shared
;
using
Titanium.Web.Proxy.Shared
;
...
@@ -181,25 +182,39 @@ namespace Titanium.Web.Proxy.Http
...
@@ -181,25 +182,39 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
internal
bool
CancelRequest
{
get
;
set
;
}
internal
bool
CancelRequest
{
get
;
set
;
}
/// <summary>
internal
void
EnsureBodyAvailable
(
bool
throwWhenNotReadYet
=
true
)
/// Request body as byte array
/// </summary>
public
byte
[]
Body
{
{
get
//GET request don't have a request body to read
if
(!
HasBody
)
{
{
if
(!
IsBodyRead
)
throw
new
BodyNotFoundException
(
"Request don't have a body. "
+
"Please verify that this request is a Http POST/PUT/PATCH and request "
+
"content length is greater than zero before accessing the body."
);
}
if
(!
IsBodyRead
)
{
if
(
RequestLocked
)
{
{
if
(
RequestLocked
)
throw
new
Exception
(
"You cannot get the request body after request is made to server."
);
{
}
throw
new
Exception
(
"You cannot get the request body after request is made to server."
);
}
if
(
throwWhenNotReadYet
)
{
throw
new
Exception
(
"Request body is not read yet. "
+
throw
new
Exception
(
"Request body is not read yet. "
+
"Use SessionEventArgs.GetRequestBody() or SessionEventArgs.GetRequestBodyAsString() "
+
"Use SessionEventArgs.GetRequestBody() or SessionEventArgs.GetRequestBodyAsString() "
+
"method to read the request body."
);
"method to read the request body."
);
}
}
}
}
/// <summary>
/// Request body as byte array
/// </summary>
public
byte
[]
Body
{
get
{
EnsureBodyAvailable
();
return
body
;
return
body
;
}
}
internal
set
internal
set
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
387d6618
...
@@ -168,6 +168,16 @@ namespace Titanium.Web.Proxy.Http
...
@@ -168,6 +168,16 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
HeaderCollection
Headers
{
get
;
}
=
new
HeaderCollection
();
public
HeaderCollection
Headers
{
get
;
}
=
new
HeaderCollection
();
internal
void
EnsureBodyAvailable
()
{
if
(!
IsBodyRead
)
{
throw
new
Exception
(
"Response body is not read yet. "
+
"Use SessionEventArgs.GetResponseBody() or SessionEventArgs.GetResponseBodyAsString() "
+
"method to read the response body."
);
}
}
/// <summary>
/// <summary>
/// Response body as byte array
/// Response body as byte array
/// </summary>
/// </summary>
...
@@ -175,13 +185,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -175,13 +185,7 @@ namespace Titanium.Web.Proxy.Http
{
{
get
get
{
{
if
(!
IsBodyRead
)
EnsureBodyAvailable
();
{
throw
new
Exception
(
"Response body is not read yet. "
+
"Use SessionEventArgs.GetResponseBody() or SessionEventArgs.GetResponseBodyAsString() "
+
"method to read the response body."
);
}
return
body
;
return
body
;
}
}
internal
set
internal
set
...
...
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