@@ -1750,18 +1750,19 @@ pub async fn cache_chrome_response(
17501750 } ;
17511751
17521752 if let Ok ( u) = url:: Url :: parse ( target_url) {
1753+ let chromey_version = match chrome_http_req_res. protocol . as_str ( ) {
1754+ "http/0.9" => HttpVersion :: Http09 ,
1755+ "http/1" | "http/1.0" => HttpVersion :: Http10 ,
1756+ "http/1.1" => HttpVersion :: Http11 ,
1757+ "http/2.0" | "http/2" => HttpVersion :: H2 ,
1758+ "http/3.0" | "http/3" => HttpVersion :: H3 ,
1759+ _ => HttpVersion :: Http11 ,
1760+ } ;
17531761 let http_response = HttpResponse {
17541762 url : u,
17551763 body,
17561764 status : chrome_http_req_res. status_code . into ( ) ,
1757- version : match chrome_http_req_res. protocol . as_str ( ) {
1758- "http/0.9" => HttpVersion :: Http09 ,
1759- "http/1" | "http/1.0" => HttpVersion :: Http10 ,
1760- "http/1.1" => HttpVersion :: Http11 ,
1761- "http/2.0" | "http/2" => HttpVersion :: H2 ,
1762- "http/3.0" | "http/3" => HttpVersion :: H3 ,
1763- _ => HttpVersion :: Http11 ,
1764- } ,
1765+ version : chromey_version,
17651766 headers : chrome_http_req_res. response_headers ,
17661767 } ;
17671768 let auth_opt = match cache_options {
@@ -1776,13 +1777,64 @@ pub async fn cache_chrome_response(
17761777 auth_opt. map ( |token| token. as_ref ( ) ) ,
17771778 ) ;
17781779
1780+ // Clone data needed for remote cache dump before put_hybrid_cache consumes them.
1781+ #[ cfg( feature = "chrome_remote_cache" ) ]
1782+ let remote_dump_data = {
1783+ let cache_site =
1784+ chromiumoxide:: cache:: manager:: site_key_for_target_url ( target_url, None ) ;
1785+ Some ( (
1786+ cache_key. clone ( ) ,
1787+ cache_site,
1788+ http_response. body . clone ( ) ,
1789+ http_response. status ,
1790+ chrome_http_req_res. request_headers . clone ( ) ,
1791+ http_response. headers . clone ( ) ,
1792+ chromey_version,
1793+ chrome_http_req_res. method . clone ( ) ,
1794+ ) )
1795+ } ;
1796+
17791797 put_hybrid_cache (
17801798 & cache_key,
17811799 http_response,
17821800 & chrome_http_req_res. method ,
17831801 chrome_http_req_res. request_headers ,
17841802 )
17851803 . await ;
1804+
1805+ // Best-effort async dump to the shared remote cache server so other
1806+ // ECS tasks / processes can serve cache hits without re-rendering.
1807+ #[ cfg( feature = "chrome_remote_cache" ) ]
1808+ if let Some ( ( key, site, body, status, req_hdrs, resp_hdrs, version, method) ) =
1809+ remote_dump_data
1810+ {
1811+ let target = target_url. to_string ( ) ;
1812+ let remote_version = match version {
1813+ HttpVersion :: Http09 => chromiumoxide:: http:: HttpVersion :: Http09 ,
1814+ HttpVersion :: Http10 => chromiumoxide:: http:: HttpVersion :: Http10 ,
1815+ HttpVersion :: H2 => chromiumoxide:: http:: HttpVersion :: H2 ,
1816+ HttpVersion :: H3 => chromiumoxide:: http:: HttpVersion :: H3 ,
1817+ _ => chromiumoxide:: http:: HttpVersion :: Http11 ,
1818+ } ;
1819+ tokio:: spawn ( async move {
1820+ let _ = tokio:: time:: timeout (
1821+ Duration :: from_secs ( 5 ) ,
1822+ chromiumoxide:: cache:: remote:: dump_to_remote_cache_parts (
1823+ & key,
1824+ & site,
1825+ & target,
1826+ & body,
1827+ & method,
1828+ status,
1829+ & req_hdrs,
1830+ & resp_hdrs,
1831+ & remote_version,
1832+ Some ( "true" ) ,
1833+ ) ,
1834+ )
1835+ . await ;
1836+ } ) ;
1837+ }
17861838 }
17871839}
17881840
0 commit comments