From a033b0cb6154be2c852806348a1bb9edfd4511c0 Mon Sep 17 00:00:00 2001 From: "krisztian.klucsik" Date: Tue, 1 Oct 2024 16:18:00 +0200 Subject: [PATCH] [frontend] fix imageSlowload headers not applied --- .../components/ProductCard/ProductCard.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/frontend/components/ProductCard/ProductCard.tsx b/src/frontend/components/ProductCard/ProductCard.tsx index 1b051c7241..3205fb1872 100644 --- a/src/frontend/components/ProductCard/ProductCard.tsx +++ b/src/frontend/components/ProductCard/ProductCard.tsx @@ -12,8 +12,8 @@ interface IProps { product: Product; } -async function getImageWithHeaders(url: RequestInfo, headers: Record) { - const res = await fetch(url, { headers }); +async function getImageWithHeaders(requestInfo: Request) { + const res = await fetch(requestInfo); return await res.blob(); } @@ -33,9 +33,16 @@ const ProductCard = ({ const [imageSrc, setImageSrc] = useState(''); useEffect(() => { - const requestInfo = new Request('/images/products/' + picture); - const headers = { 'x-envoy-fault-delay-request': imageSlowLoad.toString(), 'Cache-Control': 'no-cache' }; - getImageWithHeaders(requestInfo, headers).then(blob => { + const headers = new Headers(); + headers.append('x-envoy-fault-delay-request', imageSlowLoad.toString()); + headers.append('Cache-Control', 'no-cache') + const requestInit = { + method: "GET", + headers: headers + }; + const image_url ='/images/products/' + picture + const requestInfo = new Request(image_url, requestInit); + getImageWithHeaders(requestInfo).then(blob => { setImageSrc(URL.createObjectURL(blob)); }); }, [imageSlowLoad, picture]);