Ejemplo n.º 1
0
        public async Task Private_caching_a_POST_response()
        {
            // Cache-Control: max-age=5

            var client = CreateCachingEnabledClient();

            var response = await client.PostAsync("/CacheablePostResponse", new StringContent("Here is a message"));  // Server round trip

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            HttpAssert.FromServer(response);

            var response2 = await client.GetAsync("/CacheablePostResponse");  // No round trip

            Assert.Equal(HttpStatusCode.OK, response2.StatusCode);
            HttpAssert.FromCache(response2);

            Thread.Sleep(7000);                                              // Pause for resource to expire

            var response3 = await client.GetAsync("/CacheablePostResponse"); // Server round trip

            Assert.Equal(HttpStatusCode.OK, response3.StatusCode);
            HttpAssert.FromServer(response3);
        }
Ejemplo n.º 2
0
        public async Task Refuse_cached()
        {
            var client = CreateClientWithMessageHandlerCache();

            var response = await client.GetAsync("/CacheableResource"); // Round trip to server

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            HttpAssert.FromServer(response);

            var request = new HttpRequestMessage()
            {
                RequestUri = new Uri("/CacheableResource", UriKind.Relative)
            };

            request.Headers.CacheControl = new CacheControlHeaderValue()
            {
                NoCache = true
            };

            var response2 = await client.SendAsync(request);

            Assert.Equal(HttpStatusCode.OK, response2.StatusCode);
            HttpAssert.FromServer(response2);
        }