From ffd48eabcafa24fbd23a1f9c70c09d0d1df94f3b Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Wed, 15 Feb 2023 14:31:35 -0800 Subject: [PATCH] update HandleRecordRequestAsync and HandlePlaybackRequestAsync to not stricly set Content-Length header --- .../RecordingHandler.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index b323fd366da..2a2db44b813 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -263,12 +263,13 @@ public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incom entry.Response.Headers.Add(header.Key, values); } - outgoingResponse.Headers.Remove("Transfer-Encoding"); - if (entry.Response.Body?.Length > 0) { var bodyData = CompressionUtilities.CompressBody(entry.Response.Body, entry.Response.Headers); - outgoingResponse.ContentLength = bodyData.Length; + + if (entry.Response.Headers.ContainsKey("Content-Length")){ + outgoingResponse.ContentLength = bodyData.Length; + } await outgoingResponse.Body.WriteAsync(bodyData).ConfigureAwait(false); } } @@ -458,13 +459,14 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming outgoingResponse.Headers.Add(header.Key, header.Value.ToArray()); } - outgoingResponse.Headers.Remove("Transfer-Encoding"); - if (match.Response.Body?.Length > 0) { var bodyData = CompressionUtilities.CompressBody(match.Response.Body, match.Response.Headers); - outgoingResponse.ContentLength = bodyData.Length; + if (match.Response.Headers.ContainsKey("Content-Length")) + { + outgoingResponse.ContentLength = bodyData.Length; + } await WriteBodyBytes(bodyData, session.PlaybackResponseTime, outgoingResponse); } @@ -769,10 +771,6 @@ public void SetTransportOptions(TransportCustomizations customizations, string s Timeout = timeoutSpan }; } - else - { - throw new HttpException(HttpStatusCode.BadRequest, $"Unable to set a transport customization on a recording session that is not active. Id: \"{sessionId}\""); - } if (customizations.PlaybackResponseTime > 0) {