I am experimenting with caching in HttpClient in order to understand the topic better.
I have written a command line dot net tool that uses a single HttpClient and can send GET requests to a server, displaying the response headers. I also have a Python web server (based on BaseHTTPServer) that returns 304 whenever it sees an if-modified-since header in the request.
When I use my tool to hit the server the first time, this is what I see:
HTTP:>GET http://localhost:7777
Status 200 OK (OK in 00:00:01.7794986):
Cache-Control = must-revalidate, no-cache
Date = Sat, 08 Jul 2017 16:41:28 GMT
Server = BaseHTTP/0.3, Python/2.7.13
Content-Type = text/html
Last-Modified = Sat, 08 Jul 2017 16:41:24 GMT
When I repeat the request a few seconds later (same instance of the sending tool and therefore same singleton instance of HttpClient), the request is visibly much faster and I see:
HTTP:>GET http://localhost:7777
Status 200 OK (OK in 00:00:00.1773793):
Cache-Control = must-revalidate, no-cache
Date = Sat, 08 Jul 2017 16:42:40 GMT
Server = BaseHTTP/0.3, Python/2.7.13
Age = 0
Content-Length = 24000000
Content-Type = text/html
Last-Modified = 2017-07-08 12:41:24.187000
Looking at the output of BaseHTTPServer, I can see that the first time my server did the "work" of generating the request and returned 200 and the request body. The second time, it simply returned a header with 304.
But HttpClient did not tell me about the 304, instead it reported 200. It showed an age of 0 when I waited at least ten seconds between requests. And it introduced the Content-Length header, which was not in the original response.
Can anyone tell me, is the correct and expected status code from HttpClient on that second response 200 instead of 304? Why is the Age header never more than 0? And, other than the apparent speed of the response, how can I determine on the client what actually happened during this transaction?