|
7 | 7 | using Azure.Sdk.Tools.TestProxy.Vendored; |
8 | 8 | using Microsoft.AspNetCore.Http; |
9 | 9 | using Microsoft.AspNetCore.Http.Features; |
| 10 | +using Microsoft.AspNetCore.Server.Kestrel.Core.Features; |
10 | 11 | using Microsoft.Extensions.Primitives; |
11 | 12 | using System; |
12 | 13 | using System.Collections.Concurrent; |
@@ -466,10 +467,15 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming |
466 | 467 |
|
467 | 468 | outgoingResponse.ContentLength = bodyData.Length; |
468 | 469 |
|
469 | | - await outgoingResponse.Body.WriteAsync(bodyData).ConfigureAwait(false); |
| 470 | + await WriteBodyBytes(bodyData, session.PlaybackResponseTime, outgoingResponse); |
470 | 471 | } |
471 | 472 | } |
472 | 473 |
|
| 474 | + public async Task WriteBodyBytes(byte[] bodyData, int playbackResponseTime, HttpResponse outgoingResponse) |
| 475 | + { |
| 476 | + await outgoingResponse.Body.WriteAsync(bodyData).ConfigureAwait(false); |
| 477 | + } |
| 478 | + |
473 | 479 | public static async Task<(RecordEntry, byte[])> CreateEntryAsync(HttpRequest request) |
474 | 480 | { |
475 | 481 | var entry = new RecordEntry(); |
@@ -710,10 +716,29 @@ public void SetTransportOptions(TransportCustomizations customizations, string s |
710 | 716 | { |
711 | 717 | var customizedClientHandler = GetTransport(customizations.AllowAutoRedirect, customizations); |
712 | 718 |
|
713 | | - RecordingSessions[sessionId].Client = new HttpClient(customizedClientHandler) |
| 719 | + if (RecordingSessions.TryGetValue(sessionId, out var recordingSession)) |
714 | 720 | { |
715 | | - Timeout = timeoutSpan |
716 | | - }; |
| 721 | + recordingSession.Client = new HttpClient(customizedClientHandler) |
| 722 | + { |
| 723 | + Timeout = timeoutSpan |
| 724 | + }; |
| 725 | + } |
| 726 | + else |
| 727 | + { |
| 728 | + throw new HttpException(HttpStatusCode.BadRequest, $"Unable to set a transport customization on a recording session that is not active. Id: \"{sessionId}\""); |
| 729 | + } |
| 730 | + |
| 731 | + if (customizations.PlaybackResponseTime > 0) |
| 732 | + { |
| 733 | + if (PlaybackSessions.TryGetValue(sessionId, out var playbackSession)) |
| 734 | + { |
| 735 | + playbackSession.PlaybackResponseTime = customizations.PlaybackResponseTime; |
| 736 | + } |
| 737 | + else |
| 738 | + { |
| 739 | + throw new HttpException(HttpStatusCode.BadRequest, $"Unable to set a transport customization on a recording session that is not active. Id: \"{sessionId}\""); |
| 740 | + } |
| 741 | + } |
717 | 742 | } |
718 | 743 | else |
719 | 744 | { |
|
0 commit comments