/// <inheritdoc /> protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var retrieveBody = _retrieveBody; if (retrieveBody == null && NetCache.RequestCache != null) { retrieveBody = NetCache.RequestCache.Fetch; } if (retrieveBody == null) { throw new Exception("Configure NetCache.RequestCache before calling this!"); } var body = await retrieveBody(request, RateLimitedHttpMessageHandler.UniqueKeyForRequest(request), cancellationToken).ConfigureAwait(false); if (body == null) { return(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)); } var byteContent = new ByteArrayContent(body); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = byteContent }); }
static NetCache() { var innerHandler = Locator.Current.GetService <HttpMessageHandler>() ?? new HttpClientHandler(); // NB: In vNext this value will be adjusted based on the user's // network connection, but that requires us to go fully platformy // like Splat. speculative = new RateLimitedHttpMessageHandler(innerHandler, Priority.Speculative, 0, 1048576 * 5); userInitiated = new RateLimitedHttpMessageHandler(innerHandler, Priority.UserInitiated, 0); background = new RateLimitedHttpMessageHandler(innerHandler, Priority.Background, 0); offline = new OfflineHttpMessageHandler(null); }