Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test-Proxy] During recording, re-use existing request body #5304

Merged
merged 7 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public async Task CreateEntryUsesAbsoluteUri()
request.Path = uri.PathAndQuery;
request.Headers["x-recording-upstream-base-uri"] = uri.AbsoluteUri;

var entry = await RecordingHandler.CreateEntryAsync(request);
var entry = (await RecordingHandler.CreateEntryAsync(request)).Item1;
Assert.Equal(uri.AbsoluteUri, entry.RequestUri);
}

Expand Down
11 changes: 6 additions & 5 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incom
throw new HttpException(HttpStatusCode.BadRequest, $"There is no active recording session under id {recordingId}.");
}

var entry = await CreateEntryAsync(incomingRequest).ConfigureAwait(false);
var entryTuple = await CreateEntryAsync(incomingRequest).ConfigureAwait(false);
scbedd marked this conversation as resolved.
Show resolved Hide resolved
var entry = entryTuple.Item1;

var upstreamRequest = CreateUpstreamRequest(incomingRequest, CompressionUtilities.CompressBody(entry.Request.Body, entry.Request.Headers));
var upstreamRequest = CreateUpstreamRequest(incomingRequest, entryTuple.Item2);

HttpResponseMessage upstreamResponse = null;

Expand Down Expand Up @@ -432,7 +433,7 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming
throw new HttpException(HttpStatusCode.BadRequest, $"There is no active playback session under recording id {recordingId}.");
}

var entry = await CreateEntryAsync(incomingRequest).ConfigureAwait(false);
var entry = (await CreateEntryAsync(incomingRequest).ConfigureAwait(false)).Item1;

// If request contains "x-recording-remove: false", then request is not removed from session after playback.
// Used by perf tests to play back the same request multiple times.
Expand Down Expand Up @@ -470,7 +471,7 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming
}
}

public static async Task<RecordEntry> CreateEntryAsync(HttpRequest request)
public static async Task<Tuple<RecordEntry, byte[]>> CreateEntryAsync(HttpRequest request)
scbedd marked this conversation as resolved.
Show resolved Hide resolved
{
var entry = new RecordEntry();
entry.RequestUri = GetRequestUri(request).AbsoluteUri;
Expand All @@ -487,7 +488,7 @@ public static async Task<RecordEntry> CreateEntryAsync(HttpRequest request)
byte[] bytes = await ReadAllBytes(request.Body).ConfigureAwait(false);

entry.Request.Body = CompressionUtilities.DecompressBody(bytes, request.Headers);
scbedd marked this conversation as resolved.
Show resolved Hide resolved
return entry;
return new Tuple<RecordEntry, byte[]>(entry, bytes);
scbedd marked this conversation as resolved.
Show resolved Hide resolved
}

#endregion
Expand Down