Skip to content

Commit

Permalink
update HandleRecordRequestAsync and HandlePlaybackRequestAsync to not…
Browse files Browse the repository at this point in the history
… stricly set Content-Length header
  • Loading branch information
scbedd committed Feb 15, 2023
1 parent 111eb8b commit ffd48ea
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit ffd48ea

Please sign in to comment.