Commit 9c3a4f25 authored by Honfika's avatar Honfika

fix when body was set by the user

parent ce0bba9b
...@@ -483,7 +483,6 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -483,7 +483,6 @@ namespace Titanium.Web.Proxy.EventArguments
} }
request.Body = body; request.Body = body;
request.UpdateContentLength();
} }
/// <summary> /// <summary>
......
...@@ -102,6 +102,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -102,6 +102,11 @@ namespace Titanium.Web.Proxy.Http
internal override void EnsureBodyAvailable(bool throwWhenNotReadYet = true) internal override void EnsureBodyAvailable(bool throwWhenNotReadYet = true)
{ {
if (BodyInternal != null)
{
return;
}
//GET request don't have a request body to read //GET request don't have a request body to read
if (!HasBody) if (!HasBody)
{ {
......
...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary> /// <summary>
/// Cached body content as byte array /// Cached body content as byte array
/// </summary> /// </summary>
private byte[] body; protected byte[] BodyInternal;
/// <summary> /// <summary>
/// Cached body as string /// Cached body as string
...@@ -127,11 +127,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -127,11 +127,11 @@ namespace Titanium.Web.Proxy.Http
get get
{ {
EnsureBodyAvailable(); EnsureBodyAvailable();
return body; return BodyInternal;
} }
internal set internal set
{ {
body = value; BodyInternal = value;
bodyString = null; bodyString = null;
//If there is a content length header update it //If there is a content length header update it
...@@ -173,6 +173,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -173,6 +173,11 @@ namespace Titanium.Web.Proxy.Http
internal byte[] CompressBodyAndUpdateContentLength() internal byte[] CompressBodyAndUpdateContentLength()
{ {
if (!IsBodyRead)
{
return null;
}
bool isChunked = IsChunked; bool isChunked = IsChunked;
string contentEncoding = ContentEncoding; string contentEncoding = ContentEncoding;
...@@ -219,7 +224,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -219,7 +224,7 @@ namespace Titanium.Web.Proxy.Http
internal void UpdateContentLength() internal void UpdateContentLength()
{ {
ContentLength = IsChunked ? -1 : body?.Length ?? 0; ContentLength = IsChunked ? -1 : BodyInternal?.Length ?? 0;
} }
/// <summary> /// <summary>
...@@ -229,7 +234,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -229,7 +234,7 @@ namespace Titanium.Web.Proxy.Http
{ {
if (!KeepBody) if (!KeepBody)
{ {
body = null; BodyInternal = null;
bodyString = null; bodyString = null;
} }
} }
......
...@@ -81,6 +81,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -81,6 +81,11 @@ namespace Titanium.Web.Proxy.Http
internal override void EnsureBodyAvailable(bool throwWhenNotReadYet = true) internal override void EnsureBodyAvailable(bool throwWhenNotReadYet = true)
{ {
if (BodyInternal != null)
{
return;
}
if (!IsBodyRead && throwWhenNotReadYet) if (!IsBodyRead && throwWhenNotReadYet)
{ {
throw new Exception("Response body is not read yet. " + throw new Exception("Response body is not read yet. " +
......
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