| 396 | |
| 397 | #[tokio::test] |
| 398 | async fn options_request_not_cached() -> Result<()> { |
| 399 | let mock_server = MockServer::start().await; |
| 400 | let m = Mock::given(method("OPTIONS")) |
| 401 | .respond_with( |
| 402 | ResponseTemplate::new(200) |
| 403 | .insert_header("allow", "GET, POST, PUT, DELETE") |
| 404 | .insert_header("cache-control", CACHEABLE_PUBLIC), // Even with cache headers |
| 405 | ) |
| 406 | .expect(2); // Should be called twice since not cached |
| 407 | let _mock_guard = mock_server.register_as_scoped(m).await; |
| 408 | let url = format!("{}/", mock_server.uri()); |
| 409 | let manager = QuickManager::default(); |
| 410 | |
| 411 | let client = ClientBuilder::new(Client::new()) |
| 412 | .with(Cache(HttpCache { |
| 413 | mode: CacheMode::Default, |
| 414 | manager: manager.clone(), |
| 415 | options: HttpCacheOptions::default(), |
| 416 | })) |
| 417 | .build(); |
| 418 | |
| 419 | // First OPTIONS request |
| 420 | let res1 = |
| 421 | client.request(reqwest::Method::OPTIONS, url.clone()).send().await?; |
| 422 | assert_eq!(res1.status(), 200); |
| 423 | |
| 424 | // Verify it's not cached |
| 425 | let data = http_cache::CacheManager::get( |
| 426 | &manager, |
| 427 | &format!("OPTIONS:{}", url_parse(&url)?), |
| 428 | ) |
| 429 | .await?; |
| 430 | assert!(data.is_none()); |
| 431 | |
| 432 | // Second OPTIONS request should hit the server again |
| 433 | let res2 = |
| 434 | client.request(reqwest::Method::OPTIONS, url.clone()).send().await?; |
| 435 | assert_eq!(res2.status(), 200); |
| 436 | |
| 437 | Ok(()) |
| 438 | } |