From 21f8190769d271fbd6a9763a7f60d8c2f2d4e5f6 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sat, 16 Nov 2019 23:01:39 +0100 Subject: [PATCH] fi for #652 --- .../EventArguments/SessionEventArgs.cs | 14 +++++++++----- src/Titanium.Web.Proxy/Http2/Http2Helper.cs | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs index edb24679d..ab872705b 100644 --- a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs @@ -22,8 +22,6 @@ namespace Titanium.Web.Proxy.EventArguments /// public class SessionEventArgs : SessionEventArgsBase { - private static readonly byte[] emptyData = new byte[0]; - /// /// Backing field for corresponding public property /// @@ -110,7 +108,10 @@ private async Task readRequestBodyAsync(CancellationToken cancellationToken) else { var body = await readBodyAsync(true, cancellationToken); - request.Body = body; + if (!request.BodyAvailable) + { + request.Body = body; + } // Now set the flag to true // So that next time we can deliver body from cache @@ -182,7 +183,10 @@ private async Task readResponseBodyAsync(CancellationToken cancellationToken) else { var body = await readBodyAsync(false, cancellationToken); - response.Body = body; + if (!response.BodyAvailable) + { + response.Body = body; + } // Now set the flag to true // So that next time we can deliver body from cache @@ -595,7 +599,7 @@ public void Redirect(string url, bool closeServerConnection = false) var response = new RedirectResponse(); response.HttpVersion = HttpClient.Request.HttpVersion; response.Headers.AddHeader(KnownHeaders.Location, url); - response.Body = emptyData; + response.Body = Array.Empty(); Respond(response, closeServerConnection); } diff --git a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs index a0081aed4..5dfb0e6fb 100644 --- a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs +++ b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs @@ -389,7 +389,10 @@ private static async Task copyHttp2FrameAsync(Stream input, Stream output, } } - rr.Body = body; + if (!rr.BodyAvailable) + { + rr.Body = body; + } } rr.IsBodyRead = true;