Commit ac56eb82 authored by Honfika's avatar Honfika

fix when body was set by the user

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