Skip to content

Commit

Permalink
[frontend] fix imageSlowload headers not applied (open-telemetry#1733)
Browse files Browse the repository at this point in the history
Co-authored-by: Juliano Costa <[email protected]>
  • Loading branch information
klucsik and julianocosta89 authored Oct 14, 2024
1 parent 026e3ba commit 39f5e47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ the release.
([#1727](https://github.com/open-telemetry/opentelemetry-demo/pull/1727))
* [chore] Fix binding for host's volume mount
([#1728](https://github.com/open-telemetry/opentelemetry-demo/pull/1728))
* [frontend] fix imageSlowLoad headers not applied
to 1.8.0 together with other dependencies
([#1733](https://github.com/open-telemetry/opentelemetry-demo/pull/1733))

## 1.11.1

Expand Down
17 changes: 12 additions & 5 deletions src/frontend/components/ProductCard/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface IProps {
product: Product;
}

async function getImageWithHeaders(url: RequestInfo, headers: Record<string, string>) {
const res = await fetch(url, { headers });
async function getImageWithHeaders(requestInfo: Request) {
const res = await fetch(requestInfo);
return await res.blob();
}

Expand All @@ -33,9 +33,16 @@ const ProductCard = ({
const [imageSrc, setImageSrc] = useState<string>('');

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]);
Expand Down

0 comments on commit 39f5e47

Please sign in to comment.