Skip to content

Commit

Permalink
[frontend] fix imageSlowload headers not applied
Browse files Browse the repository at this point in the history
  • Loading branch information
klucsik committed Oct 1, 2024
1 parent 10048aa commit b1a436e
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 @@ -16,6 +16,9 @@ the release.
* [accountingservice] bump OpenTelemetry .NET Automatic Instrumentation
to 1.8.0 together with other dependencies
([#1727](https://github.com/open-telemetry/opentelemetry-demo/pull/1727))
* [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 b1a436e

Please sign in to comment.