public TapedResponse Get(RequestKey key) { TapedResponse tapedResponse; _tapes.TryGetValue(key, out tapedResponse); return(tapedResponse); }
// ReSharper disable once UnusedMember.Global public async Task Invoke(HttpContext context) { var incomingRequest = context.Request; var requestKey = new RequestKey(incomingRequest); var tapedResponse = _tapeRepository.Get(requestKey); if (tapedResponse != null) { _logger.LogInformation("request was previously recorded, playing back tape"); tapedResponse.WriteTo(context.Response); } else { _logger.LogInformation("could not find recorded tape for request, passing through, and recording it"); var incomingResponse = await ProxyRequestAsync(incomingRequest, context.RequestAborted); tapedResponse = await requestKey.CreateTapeFromAsync(incomingResponse); tapedResponse.WriteTo(context.Response); _tapeRepository.Store(tapedResponse); } }
protected TapedResponse(RequestKey requestKey) { RequestKey = requestKey; }
public HttpClientTapedResponse(RequestKey requestKey, HttpResponseMessage responseMessage, byte[] body) : base(requestKey) { _responseMessage = responseMessage; _body = body; }