Commit 545f5b66 authored by Nordin Rahman's avatar Nordin Rahman

Add support for request with PATCH method - treat it similar to POST and PUT method

parent fa9a02c4
...@@ -79,7 +79,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -79,7 +79,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
////read request headers ////read request headers
var requestHeaders = e.WebSession.Request.RequestHeaders; var requestHeaders = e.WebSession.Request.RequestHeaders;
if ((e.WebSession.Request.Method == "POST" || e.WebSession.Request.Method == "PUT")) var method = e.WebSession.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH"))
{ {
//Get/Set request body bytes //Get/Set request body bytes
byte[] bodyBytes = await e.GetRequestBody(); byte[] bodyBytes = await e.GetRequestBody();
......
...@@ -107,8 +107,9 @@ Sample request and response event handlers ...@@ -107,8 +107,9 @@ Sample request and response event handlers
////read request headers ////read request headers
var requestHeaders = e.WebSession.Request.RequestHeaders; var requestHeaders = e.WebSession.Request.RequestHeaders;
if ((e.WebSession.Request.Method == "POST" || e.WebSession.Request.Method == "PUT")) var method = e.WebSession.Request.Method.ToUpper();
if ((method == "POST" || method == "PUT" || method == "PATCH"))
{ {
//Get/Set request body bytes //Get/Set request body bytes
byte[] bodyBytes = await e.GetRequestBody(); byte[] bodyBytes = await e.GetRequestBody();
......
...@@ -81,10 +81,11 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -81,10 +81,11 @@ namespace Titanium.Web.Proxy.EventArguments
private async Task ReadRequestBody() private async Task ReadRequestBody()
{ {
//GET request don't have a request body to read //GET request don't have a request body to read
if ((WebSession.Request.Method.ToUpper() != "POST" && WebSession.Request.Method.ToUpper() != "PUT")) var method = WebSession.Request.Method.ToUpper();
if ((method != "POST" && method != "PUT" && method != "PATCH"))
{ {
throw new BodyNotFoundException("Request don't have a body." + throw new BodyNotFoundException("Request don't have a body. " +
"Please verify that this request is a Http POST/PUT and request " + "Please verify that this request is a Http POST/PUT/PATCH and request " +
"content length is greater than zero before accessing the body."); "content length is greater than zero before accessing the body.");
} }
......
...@@ -312,8 +312,9 @@ namespace Titanium.Web.Proxy ...@@ -312,8 +312,9 @@ namespace Titanium.Web.Proxy
{ {
if (!args.WebSession.Request.ExpectationFailed) if (!args.WebSession.Request.ExpectationFailed)
{ {
//If its a post/put request, then read the client html body and send it to server //If its a post/put/patch request, then read the client html body and send it to server
if (args.WebSession.Request.Method.ToUpper() == "POST" || args.WebSession.Request.Method.ToUpper() == "PUT") var method = args.WebSession.Request.Method.ToUpper();
if (method == "POST" || method == "PUT" || method == "PATCH")
{ {
await SendClientRequestBody(args); await SendClientRequestBody(args);
} }
...@@ -570,7 +571,7 @@ namespace Titanium.Web.Proxy ...@@ -570,7 +571,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// This is called when the request is PUT/POST to read the body /// This is called when the request is PUT/POST/PATCH to read the body
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
/// <returns></returns> /// <returns></returns>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment