Skip to content

Commit

Permalink
Update for code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSuplizio committed Sep 19, 2024
1 parent 344a945 commit 7ab4c24
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public async Task CustomMatcherMatchesDifferentUriOrder()
};
foreach (var kvp in requestHeaders)
{
playbackContext.Request.Headers.Add(kvp.Key, kvp.Value);
playbackContext.Request.Headers.Append(kvp.Key, kvp.Value);
}
playbackContext.Request.Method = "POST";

Expand Down Expand Up @@ -332,7 +332,7 @@ public async Task EncodedUriAmpersandWorksCrossplat()
};
foreach (var kvp in requestHeaders)
{
playbackContext.Request.Headers.Add(kvp.Key, kvp.Value);
playbackContext.Request.Headers.Append(kvp.Key, kvp.Value);
}
var queryString = "?api-version=1.0&year=2023&basinId=AL&govId=5";
var path = "/weather/tropical/storms/json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task TestPlaybackThrowsOnDifferentUriOrder()
};
foreach (var kvp in requestHeaders)
{
playbackContext.Request.Headers.Add(kvp.Key, kvp.Value);
playbackContext.Request.Headers.Append(kvp.Key, kvp.Value);
}
playbackContext.Request.Method = "POST";

Expand Down
2 changes: 1 addition & 1 deletion tools/test-proxy/Azure.Sdk.Tools.TestProxy/Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public async Task AddSanitizers()

if (recordingId != null)
{
Response.Headers.Add("x-recording-id", recordingId);
Response.Headers.Append("x-recording-id", recordingId);
}

var json = JsonSerializer.Serialize(new { Sanitizers = registeredSanitizers });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -36,11 +36,5 @@ public HttpException(HttpStatusCode statusCode, string message, Exception innerE
{
StatusCode = statusCode;
}

protected HttpException(HttpStatusCode statusCode, SerializationInfo info, StreamingContext context) : base(info, context)
{
StatusCode = statusCode;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public async Task Invoke(HttpContext context)

if (e is TestRecordingMismatchException)
{
response.Headers.Add("x-request-mismatch", "true");
response.Headers.Add("x-request-mismatch-error", encodedException);
response.Headers.Append("x-request-mismatch", "true");
response.Headers.Append("x-request-mismatch-error", encodedException);
}
else
{
response.Headers.Add("x-request-known-exception", "true");
response.Headers.Add("x-request-known-exception-error", encodedException);
response.Headers.Append("x-request-known-exception", "true");
response.Headers.Append("x-request-known-exception-error", encodedException);
}

var bodyObj = new
Expand All @@ -77,8 +77,8 @@ public async Task Invoke(HttpContext context)
response.StatusCode = unexpectedStatusCode;
response.ContentType = "application/json";

response.Headers.Add("x-request-exception", "true");
response.Headers.Add("x-request-exception-error", Convert.ToBase64String(Encoding.UTF8.GetBytes(e.Message)));
response.Headers.Append("x-request-exception", "true");
response.Headers.Append("x-request-exception-error", Convert.ToBase64String(Encoding.UTF8.GetBytes(e.Message)));

DebugLogger.LogError(unexpectedStatusCode, e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,5 @@ public TestRecordingMismatchException(string message) : base(HttpStatusCode.NotF
public TestRecordingMismatchException(string message, Exception innerException) : base(HttpStatusCode.NotFound, message, innerException)
{
}

protected TestRecordingMismatchException(SerializationInfo info, StreamingContext context) : base(HttpStatusCode.NotFound, info, context)
{
}
}
}
12 changes: 6 additions & 6 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public async Task StartRecordingAsync(string sessionId, HttpResponse outgoingRes


DebugLogger.LogTrace($"RECORD START END {id}.");
outgoingResponse.Headers.Add("x-recording-id", id);
outgoingResponse.Headers.Append("x-recording-id", id);
}

public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incomingRequest, HttpResponse outgoingResponse)
Expand Down Expand Up @@ -328,7 +328,7 @@ public async Task HandleRecordRequestAsync(string recordingId, HttpRequest incom
foreach (var header in upstreamResponse.Headers.Concat(upstreamResponse.Content.Headers))
{
var values = new StringValues(header.Value.ToArray());
outgoingResponse.Headers.Add(header.Key, values);
outgoingResponse.Headers.Append(header.Key, values);
entry.Response.Headers.Add(header.Key, values);
}

Expand Down Expand Up @@ -445,7 +445,7 @@ public async Task StartPlaybackAsync(string sessionId, HttpResponse outgoingResp
await RestoreAssetsJson(assetsPath, true);
var path = await GetRecordingPath(sessionId, assetsPath);
var base64path = Convert.ToBase64String(Encoding.UTF8.GetBytes(path));
outgoingResponse.Headers.Add("x-base64-recording-file-location", base64path);
outgoingResponse.Headers.Append("x-base64-recording-file-location", base64path);
if (!File.Exists(path))
{
throw new TestRecordingMismatchException($"Recording file path {path} does not exist.");
Expand All @@ -465,11 +465,11 @@ public async Task StartPlaybackAsync(string sessionId, HttpResponse outgoingResp
throw new HttpException(HttpStatusCode.InternalServerError, $"Unexpectedly failed to add new playback session under id {id}.");
}

outgoingResponse.Headers.Add("x-recording-id", id);
outgoingResponse.Headers.Append("x-recording-id", id);


var json = JsonSerializer.Serialize(session.Session.Variables);
outgoingResponse.Headers.Add("Content-Type", "application/json");
outgoingResponse.Headers.Append("Content-Type", "application/json");

// Write to the response
await outgoingResponse.WriteAsync(json);
Expand Down Expand Up @@ -577,7 +577,7 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming

foreach (var header in match.Response.Headers)
{
outgoingResponse.Headers.Add(header.Key, header.Value.ToArray());
outgoingResponse.Headers.Append(header.Key, header.Value.ToArray());
}

outgoingResponse.Headers.Remove("Transfer-Encoding");
Expand Down

0 comments on commit 7ab4c24

Please sign in to comment.