/// <summary> /// Override the base class to capture and store the response message /// if it doesn't already exist in storage /// </summary> /// <param name="request">The <see cref="HttpRequestMessage"/> to find or retreive from the endpoint</param> /// <param name="cancellationToken"></param> /// <returns>The response message</returns> protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // if the response exists in the store go get it from there if (_store.ResponseExists(request)) { return(_store.FindResponse(request)); } // otherwise get it from the actual endpoint, store it and return it var response = await base.SendAsync(request, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await _store.StoreResponse(response); return(_store.FindResponse(request)); }
/// <summary> /// Override the base class to capture and store the response message /// </summary> /// <param name="request">The <see cref="HttpRequestMessage"/> to capture and store</param> /// <param name="cancellationToken"></param> /// <returns>The stored response message</returns> protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var response = await base.SendAsync(request, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await _store.StoreResponse(response); return(_store.FindResponse(request)); }