public void AddTransformToRecording(string recordingId, ResponseTransform transform) { if (!PlaybackSessions.TryGetValue(recordingId, out var session)) { throw new HttpException(HttpStatusCode.BadRequest, $"{recordingId} is not an active playback session. Check the value being passed and try again."); } session.AdditionalTransforms.Add(transform); }
public void TakeHeader_ResponseNull_ReturnsNothing() { var httpContext = new DefaultHttpContext(); var result = ResponseTransform.TakeHeader(new ResponseTransformContext() { HttpContext = httpContext, ProxyResponse = null, HeadersCopied = false, }, "name"); Assert.Equal(StringValues.Empty, result); }
public void TakeHeader_HeadersNotCopied_ReturnsHttpContentHeader() { var httpContext = new DefaultHttpContext(); var proxyResponse = new HttpResponseMessage(); proxyResponse.Content = new StringContent("hello world"); proxyResponse.Content.Headers.Add("Name", "value2"); var result = ResponseTransform.TakeHeader(new ResponseTransformContext() { HttpContext = httpContext, ProxyResponse = proxyResponse, HeadersCopied = false, }, "name"); Assert.Equal("value2", result); }
public async Task AddTransform() { await DebugLogger.LogRequestDetailsAsync(_logger, Request); var tName = RecordingHandler.GetHeader(Request, "x-abstraction-identifier"); var recordingId = RecordingHandler.GetHeader(Request, "x-recording-id", allowNulls: true); ResponseTransform t = (ResponseTransform)GetTransform(tName, await HttpRequestInteractions.GetBody(Request)); if (recordingId != null) { _recordingHandler.AddTransformToRecording(recordingId, t); } else { _recordingHandler.Transforms.Add(t); } }
public void TakeHeader_RemovesAndReturnsHttpResponseHeader(bool copiedHeaders) { var httpContext = new DefaultHttpContext(); httpContext.Response.Headers.Add("name", "value0"); var proxyResponse = new HttpResponseMessage(); proxyResponse.Headers.Add("Name", "value1"); proxyResponse.Content = new StringContent("hello world"); proxyResponse.Content.Headers.Add("Name", "value2"); var result = ResponseTransform.TakeHeader(new ResponseTransformContext() { HttpContext = httpContext, ProxyResponse = proxyResponse, HeadersCopied = copiedHeaders, }, "name"); Assert.Equal("value0", result); Assert.False(httpContext.Response.Headers.TryGetValue("name", out var _)); Assert.Equal(new[] { "value1" }, proxyResponse.Headers.GetValues("name")); Assert.Equal(new[] { "value2" }, proxyResponse.Content.Headers.GetValues("name")); }