MCPcopy Create free account
hub / github.com/06chaynes/http-cache / head_request_caching

Function head_request_caching

http-cache-quickcache/src/test.rs:182–222  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

180
181#[tokio::test]
182async fn head_request_caching() -> Result<()> {
183 let mock_server = MockServer::start().await;
184 let m = Mock::given(method("HEAD"))
185 .respond_with(
186 ResponseTemplate::new(200)
187 .insert_header("cache-control", CACHEABLE_PUBLIC)
188 .insert_header("content-type", "text/plain")
189 .insert_header("content-length", "4"), // HEAD responses should not have a body
190 )
191 .expect(1);
192 let _mock_guard = mock_server.register_as_scoped(m).await;
193 let url = format!("{}/", mock_server.uri());
194 let manager = QuickManager::default();
195
196 // Construct reqwest client with cache defaults
197 let client = ClientBuilder::new(Client::new())
198 .with(Cache(HttpCache {
199 mode: CacheMode::Default,
200 manager: manager.clone(),
201 options: HttpCacheOptions::default(),
202 }))
203 .build();
204
205 // HEAD request should be cached
206 let res = client.head(url.clone()).send().await?;
207 assert_eq!(res.status(), 200);
208 assert_eq!(res.headers().get("content-type").unwrap(), "text/plain");
209
210 // Try to load cached object - should use HEAD method in cache key
211 let data = http_cache::CacheManager::get(
212 &manager,
213 &format!("HEAD:{}", url_parse(&url)?),
214 )
215 .await?;
216 assert!(data.is_some());
217
218 let cached_response = data.unwrap().0;
219 assert_eq!(cached_response.status, 200);
220
221 Ok(())
222}
223
224#[tokio::test]
225async fn put_request_invalidates_cache() -> Result<()> {

Callers

nothing calls this directly

Calls 4

buildMethod · 0.80
cloneMethod · 0.80
headMethod · 0.80
CacheClass · 0.50

Tested by

no test coverage detected