reqwest-cache 0.1.1

reqwest-middleware based in-memory HTTP caching middleware
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use reqwest::Client;
use reqwest_middleware::ClientBuilder;

#[tokio::test]
async fn cache() -> reqwest_middleware::Result<()> {
	let mock =
		mockito::mock("GET", "/").with_header("cache-control", "public,max-age=100").create();
	let client = Client::new();
	let client = ClientBuilder::new(client).with(reqwest_cache::CacheMiddleware::new()).build();
	// GET twice
	for _ in 0..2 {
		client.get(mockito::server_url()).send().await?;
	}
	// Assert that the mocking server only received one request
	mock.assert();
	Ok(())
}