Commit 44fd116c authored by justcoding121's avatar justcoding121

use original isBodyRead when siphoning & refactor

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