Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 9c3a4f2

Browse files
committed
fix when body was set by the user
1 parent ce0bba9 commit 9c3a4f2

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ public void SetRequestBody(byte[] body)
483483
}
484484

485485
request.Body = body;
486-
request.UpdateContentLength();
487486
}
488487

489488
/// <summary>

Titanium.Web.Proxy/Http/Request.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public bool ExpectContinue
102102

103103
internal override void EnsureBodyAvailable(bool throwWhenNotReadYet = true)
104104
{
105+
if (BodyInternal != null)
106+
{
107+
return;
108+
}
109+
105110
//GET request don't have a request body to read
106111
if (!HasBody)
107112
{

Titanium.Web.Proxy/Http/RequestResponseBase.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class RequestResponseBase
1616
/// <summary>
1717
/// Cached body content as byte array
1818
/// </summary>
19-
private byte[] body;
19+
protected byte[] BodyInternal;
2020

2121
/// <summary>
2222
/// Cached body as string
@@ -127,11 +127,11 @@ public byte[] Body
127127
get
128128
{
129129
EnsureBodyAvailable();
130-
return body;
130+
return BodyInternal;
131131
}
132132
internal set
133133
{
134-
body = value;
134+
BodyInternal = value;
135135
bodyString = null;
136136

137137
//If there is a content length header update it
@@ -173,6 +173,11 @@ internal byte[] GetCompressedBody(string encodingType, byte[] body)
173173

174174
internal byte[] CompressBodyAndUpdateContentLength()
175175
{
176+
if (!IsBodyRead)
177+
{
178+
return null;
179+
}
180+
176181
bool isChunked = IsChunked;
177182
string contentEncoding = ContentEncoding;
178183

@@ -219,7 +224,7 @@ internal byte[] CompressBodyAndUpdateContentLength()
219224

220225
internal void UpdateContentLength()
221226
{
222-
ContentLength = IsChunked ? -1 : body?.Length ?? 0;
227+
ContentLength = IsChunked ? -1 : BodyInternal?.Length ?? 0;
223228
}
224229

225230
/// <summary>
@@ -229,7 +234,7 @@ internal void FinishSession()
229234
{
230235
if (!KeepBody)
231236
{
232-
body = null;
237+
BodyInternal = null;
233238
bodyString = null;
234239
}
235240
}

Titanium.Web.Proxy/Http/Response.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public bool KeepAlive
8181

8282
internal override void EnsureBodyAvailable(bool throwWhenNotReadYet = true)
8383
{
84+
if (BodyInternal != null)
85+
{
86+
return;
87+
}
88+
8489
if (!IsBodyRead && throwWhenNotReadYet)
8590
{
8691
throw new Exception("Response body is not read yet. " +

0 commit comments

Comments
 (0)