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

Function test_streaming_cache_empty_response

http-cache-tower/src/test.rs:1740–1780  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1738 }
1739
1740 #[cfg(feature = "streaming")]
1741 #[tokio::test]
1742 async fn test_streaming_cache_empty_response() -> Result<()> {
1743 use http_cache::StreamingManager;
1744
1745 let cache_manager = StreamingManager::with_temp_dir(1000).await?;
1746 let streaming_layer = HttpCacheStreamingLayer::new(cache_manager);
1747
1748 let empty_service = TestService::new(
1749 StatusCode::NO_CONTENT,
1750 vec![("cache-control", CACHEABLE_PUBLIC)],
1751 b"", // Empty body
1752 );
1753
1754 let cached_service = streaming_layer.layer(empty_service);
1755
1756 // First request should be a cache miss
1757 let request1 = Request::builder()
1758 .uri("https://example.com/empty-streaming-test")
1759 .body(Full::new(Bytes::new()))?;
1760
1761 let response1 = cached_service.clone().oneshot(request1).await?;
1762 assert_eq!(response1.status(), StatusCode::NO_CONTENT);
1763
1764 // Check that empty body is handled correctly
1765 let body_bytes = response1.into_body().collect().await?.to_bytes();
1766 assert!(body_bytes.is_empty());
1767
1768 // Second request should be a cache hit
1769 let request2 = Request::builder()
1770 .uri("https://example.com/empty-streaming-test")
1771 .body(Full::new(Bytes::new()))
1772 .unwrap();
1773
1774 let response2 = cached_service.clone().oneshot(request2).await?;
1775 assert_eq!(response2.status(), StatusCode::NO_CONTENT);
1776
1777 // Check that cached empty body is correct
1778 let body_bytes2 = response2.into_body().collect().await?.to_bytes();
1779 assert!(body_bytes2.is_empty());
1780
1781 Ok(())
1782 }
1783

Callers

nothing calls this directly

Calls 3

bodyMethod · 0.80
cloneMethod · 0.80
layerMethod · 0.45

Tested by

no test coverage detected