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 5fdb9f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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

* [otel-col] Add docker stats receiver
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 5fdb9f2

Please sign in to comment.