Skip to content

Commit 24c3a2c

Browse files
committed
1 parent 12ac77b commit 24c3a2c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

examples/e2e/app-router/e2e/middleware.redirect.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import { expect, test } from "@playwright/test";
2+
import { validateMd5 } from "../../utils";
3+
4+
/*
5+
* `curl -s https://opennext.js.org/share.png | md5sum`
6+
* This is the MD5 hash of the image. It is used to validate the image content.
7+
*/
8+
const OPENNEXT_PNG_MD5 = "405f45cc3397b09717a13ebd6f1e027b";
29

310
test("Middleware Redirect", async ({ page, context }) => {
411
await page.goto("/");
@@ -18,3 +25,14 @@ test("Middleware Redirect", async ({ page, context }) => {
1825
el = page.getByText("Redirect Destination", { exact: true });
1926
await expect(el).toBeVisible();
2027
});
28+
29+
test("Middleware Rewrite External Image", async ({ page }) => {
30+
await page.goto("/rewrite-external");
31+
page.on("response", async (response) => {
32+
expect(response.status()).toBe(200);
33+
expect(response.headers()["content-type"]).toBe("image/png");
34+
expect(response.headers()["cache-control"]).toBe("max-age=600");
35+
const bodyBuffer = await response.body();
36+
expect(validateMd5(bodyBuffer, OPENNEXT_PNG_MD5)).toBe(true);
37+
});
38+
});

examples/e2e/app-router/middleware.ts

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export function middleware(request: NextRequest) {
2424
},
2525
});
2626
}
27+
if (path === "/rewrite-external") {
28+
const u = new URL("https://opennext.js.org/share.png");
29+
return NextResponse.rewrite(u);
30+
}
2731
const requestHeaders = new Headers();
2832
// Setting the Request Headers, this should be available in RSC
2933
requestHeaders.set("request-header", "request-header");

0 commit comments

Comments
 (0)