Commit 216b8c90 authored by justcoding121's avatar justcoding121 Committed by GitHub

Merge pull request #93 from KirovAir/Read_request_from_response

Only check for locked request if not read already.
parents afe22a41 1073c975
......@@ -63,7 +63,6 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession = new HttpWebClient();
}
/// <summary>
/// Read request body content as bytes[] for current session
/// </summary>
......@@ -98,7 +97,7 @@ namespace Titanium.Web.Proxy.EventArguments
await this.ProxyClient.ClientStreamReader.CopyBytesToStream(bufferSize, requestBodyStream, WebSession.Request.ContentLength);
}
else if(WebSession.Request.HttpVersion.Major == 1 && WebSession.Request.HttpVersion.Minor == 0)
else if (WebSession.Request.HttpVersion.Major == 1 && WebSession.Request.HttpVersion.Minor == 0)
await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, requestBodyStream, long.MaxValue);
}
WebSession.Request.RequestBody = await GetDecompressedResponseBody(WebSession.Request.ContentEncoding, requestBodyStream.ToArray());
......@@ -134,7 +133,7 @@ namespace Titanium.Web.Proxy.EventArguments
await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, responseBodyStream, WebSession.Response.ContentLength);
}
else if(WebSession.Response.HttpVersion.Major == 1 && WebSession.Response.HttpVersion.Minor == 0)
else if (WebSession.Response.HttpVersion.Major == 1 && WebSession.Response.HttpVersion.Minor == 0)
await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, responseBodyStream, long.MaxValue);
}
......@@ -151,11 +150,14 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// <returns></returns>
public async Task<byte[]> GetRequestBody()
{
if (!WebSession.Request.RequestBodyRead)
{
if (WebSession.Request.RequestLocked)
throw new Exception("You cannot call this function after request is made to server.");
await ReadRequestBody();
}
return WebSession.Request.RequestBody;
}
/// <summary>
......@@ -163,13 +165,14 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// <returns></returns>
public async Task<string> GetRequestBodyAsString()
{
if (!WebSession.Request.RequestBodyRead)
{
if (WebSession.Request.RequestLocked)
throw new Exception("You cannot call this function after request is made to server.");
await ReadRequestBody();
}
//Use the encoding specified in request to decode the byte[] data to string
return WebSession.Request.RequestBodyString ?? (WebSession.Request.RequestBodyString = WebSession.Request.Encoding.GetString(WebSession.Request.RequestBody));
}
......
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