Created
January 8, 2014 15:45
-
-
Save darrelmiller/8318796 to your computer and use it in GitHub Desktop.
Wininet seems to ignore no-cache request header.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static async Task TestNoCache(string host) | |
{ | |
var clientHandler = new WebRequestHandler(); | |
clientHandler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default); | |
var client = new HttpClient(clientHandler) { BaseAddress = new Uri(host) }; | |
var response = await client.GetAsync("/CacheableResource"); | |
var request = new HttpRequestMessage() | |
{ | |
RequestUri = new Uri("/CacheableResource", UriKind.Relative) | |
}; | |
request.Headers.CacheControl = new CacheControlHeaderValue() { NoCache = true }; | |
var response2 = await client.SendAsync(request); // This should make a round-trip, but it doesn't | |
} | |
[Route("CacheableResource")] | |
public class CacheableResourceController : ApiController | |
{ | |
public HttpResponseMessage Get() | |
{ | |
var response = new HttpResponseMessage() | |
{ | |
Content = new StringContent("This is cached content") | |
}; | |
response.Headers.CacheControl = new CacheControlHeaderValue() { MaxAge = new TimeSpan(0, 0, 0, 5) }; | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment