-
-
Save aarondandy/ee11865494c4b1ea5004 to your computer and use it in GitHub Desktop.
Cache loses content type.
This file contains 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
using System; | |
using System.Net; | |
using System.Net.Cache; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
namespace HttpCacheTest | |
{ | |
class Program | |
{ | |
const string url = "http://<redacted>/octopus/api/projects/projects-<redacted>"; | |
const string apiKey = "<redacted>"; | |
static void Main(string[] args) | |
{ | |
DefaultTest().Wait(); | |
Task.Delay(1000).Wait(); | |
CachingTest().Wait(); | |
} | |
static async Task DefaultTest() | |
{ | |
Console.WriteLine("Default:"); | |
using (var httpClient = new HttpClient() | |
{ | |
DefaultRequestHeaders = { | |
{ "X-Octopus-ApiKey", apiKey} | |
} | |
}) | |
{ | |
using (var response = await httpClient.GetAsync(url)) | |
{ | |
Console.WriteLine($"{response.Content.Headers.ContentType}"); | |
} | |
await Task.Delay(1000); | |
using (var response = await httpClient.GetAsync(url)) | |
{ | |
Console.WriteLine($"{response.Content.Headers.ContentType}"); | |
} | |
} | |
} | |
static async Task CachingTest() | |
{ | |
Console.WriteLine("With Cache:"); | |
using (var httpClient = new HttpClient(new WebRequestHandler() | |
{ | |
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default) | |
}) | |
{ | |
DefaultRequestHeaders = { | |
{ "X-Octopus-ApiKey", apiKey} | |
} | |
}) | |
{ | |
using (var response = await httpClient.GetAsync(url)) | |
{ | |
Console.WriteLine($"{response.Content.Headers.ContentType}"); | |
} | |
await Task.Delay(1000); | |
using (var response = await httpClient.GetAsync(url)) | |
{ | |
Console.WriteLine($"{response.Content.Headers.ContentType}"); | |
} | |
} | |
} | |
} | |
} |
This file contains 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
Default: | |
application/json; charset=utf-8 | |
application/json; charset=utf-8 | |
With Cache: | |
application/json; charset=utf-8 | |
text/plain | |
Press any key to continue . . . |
This file contains 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
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom | |
1 200 HTTP <redacted> /octopus/api/projects/<redacted> 1,379 must-revalidate; Expires: Tue, 05 May 2015 03:18:10 GMT application/json; charset=utf-8 httpcachetest.vshost:3228 | |
2 200 HTTP <redacted> /octopus/api/projects/<redacted> 1,379 must-revalidate; Expires: Tue, 05 May 2015 03:18:11 GMT application/json; charset=utf-8 httpcachetest.vshost:3228 | |
3 200 HTTP <redacted> /octopus/api/projects/<redacted> 1,379 must-revalidate; Expires: Tue, 05 May 2015 03:18:13 GMT application/json; charset=utf-8 httpcachetest.vshost:3228 | |
4 304 HTTP <redacted> /octopus/api/projects/<redacted> 0 no-cache; Expires: Tue, 05 May 2015 03:18:14 GMT text/plain httpcachetest.vshost:3228 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment