Commit 3eeebcce authored by justcoding121's avatar justcoding121

use original isBodyRead when siphoning & refactor

parent 22dc6661
......@@ -179,7 +179,7 @@ namespace Titanium.Web.Proxy.EventArguments
internal async Task SyphonOutBodyAsync(bool isRequest, CancellationToken cancellationToken)
{
var requestResponse = isRequest ? (RequestResponseBase)WebSession.Request : WebSession.Response;
if (requestResponse.IsBodyRead || !requestResponse.OriginalHasBody)
if (requestResponse.OriginalIsBodyRead || !requestResponse.OriginalHasBody)
{
return;
}
......@@ -583,10 +583,7 @@ namespace Titanium.Web.Proxy.EventArguments
TerminateServerConnection();
}
response.OriginalHasBody = WebSession.Response.OriginalHasBody;
response.OriginalIsChunked = WebSession.Response.OriginalIsChunked;
response.OriginalContentLength = WebSession.Response.OriginalContentLength;
response.OriginalContentEncoding = WebSession.Response.OriginalContentEncoding;
response.SetOriginalHeaders(WebSession.Response);
//response already received from server but not yet ready to sent to client.
WebSession.Response = response;
......
......@@ -233,5 +233,6 @@ namespace Titanium.Web.Proxy.Http
return true;
}
}
}
......@@ -24,7 +24,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Store whether the original request/response has body or not, since the user may change the parameters.
/// We need this detail to tcp syphon out attached connection for reuse.
/// We need this detail to syphon out attached tcp connection for reuse.
/// </summary>
internal bool OriginalHasBody { get; set; }
......@@ -36,16 +36,22 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Store whether the original request/response was a chunked body, since the user may change the parameters.
/// We need this detail to tcp syphon out attached connection for reuse.
/// We need this detail to syphon out attached tcp connection for reuse.
/// </summary>
internal bool OriginalIsChunked { get; set; }
/// <summary>
/// Store whether the original request/response content-encoding, since the user may change the parameters.
/// We need this detail to tcp syphon out attached connection for reuse.
/// We need this detail to syphon out attached tcp connection for reuse.
/// </summary>
internal string OriginalContentEncoding { get; set; }
/// <summary>
/// Store whether the original request/response body was read by user.
/// We need this detail to syphon out attached tcp connection for reuse.
/// </summary>
public bool OriginalIsBodyRead { get; internal set; }
/// <summary>
/// Keeps the body data after the session is finished.
/// </summary>
......@@ -251,6 +257,31 @@ namespace Titanium.Web.Proxy.Http
ContentLength = IsChunked ? -1 : BodyInternal?.Length ?? 0;
}
/// <summary>
/// Set values for original headers using current headers.
/// </summary>
internal void SetOriginalHeaders()
{
OriginalHasBody = HasBody;
OriginalContentLength = ContentLength;
OriginalIsChunked = IsChunked;
OriginalContentEncoding = ContentEncoding;
OriginalIsBodyRead = IsBodyRead;
}
/// <summary>
/// Copy original header values.
/// </summary>
/// <param name="requestResponseBase"></param>
internal void SetOriginalHeaders(RequestResponseBase requestResponseBase)
{
OriginalHasBody = requestResponseBase.OriginalHasBody;
OriginalContentLength = requestResponseBase.OriginalContentLength;
OriginalIsChunked = requestResponseBase.OriginalIsChunked;
OriginalContentEncoding = requestResponseBase.OriginalContentEncoding;
OriginalIsBodyRead = requestResponseBase.OriginalIsBodyRead;
}
/// <summary>
/// Finish the session
/// </summary>
......
......@@ -163,10 +163,7 @@ namespace Titanium.Web.Proxy
}
//we need this to syphon out data from connection if API user changes them.
request.OriginalHasBody = request.HasBody;
request.OriginalContentLength = request.ContentLength;
request.OriginalIsChunked = request.IsChunked;
request.OriginalContentEncoding = request.ContentEncoding;
request.SetOriginalHeaders();
// If user requested interception do it
await invokeBeforeRequest(args);
......
......@@ -41,10 +41,7 @@ namespace Titanium.Web.Proxy
//save original values so that if user changes them
//we can still use original values when syphoning out data from attached tcp connection.
response.OriginalHasBody = response.HasBody;
response.OriginalContentLength = response.ContentLength;
response.OriginalIsChunked = response.IsChunked;
response.OriginalContentEncoding = response.ContentEncoding;
response.SetOriginalHeaders();
// if user requested call back then do it
if (!response.Locked)
......
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