Skip to content

Commit

Permalink
fix(fetch): preserve properties of Request by default (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrickyPi authored Jul 21, 2022
1 parent 34dddd5 commit 2d0d14e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/patch/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ const Xhook = function(url, options) {
if (options == null) {
options = { headers: {} };
}
options.url = url;

let request = null;

if (url instanceof Request) {
request = url
} else {
options.url = url;
}

const beforeHooks = hooks.listeners("before");
const afterHooks = hooks.listeners("after");

Expand Down
22 changes: 22 additions & 0 deletions tests/fetch/fetch-header.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from "@playwright/test";
import { createWaitting } from '../test.util';

test("Should preserve headers of Request", async ({ page }) => {
const url = "http://127.0.0.1:8080/example/common.html"
await page.goto(url);
const { waitting, $resolve } = createWaitting()
page.on('requestfinished', (req) => {
$resolve(req.headers())
})
await page.evaluate((url) => {
const req = new Request(url, {
headers: {
"custom-xhook-header": "1"
}
})
fetch(req)
}, url)
const headers = await waitting;
expect(headers).toMatchObject({ 'custom-xhook-header': '1' })
});

0 comments on commit 2d0d14e

Please sign in to comment.