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) {