Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should not throw when fetch a Request with post #563

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ test/fixtures/ts-cjs-es2021/*.js
test/fixtures/ts-esm/*.js
.eslintcache
.tshy*
.idea/
2 changes: 1 addition & 1 deletion src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
const requestStartTime = performance.now();
init = init ?? {};
init.dispatcher = init.dispatcher ?? FetchFactory.#dispatcher;
const request = new Request(input, init);

Check failure on line 136 in src/fetch.ts

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 16)

test/fetch.test.ts > fetch.test.ts > fetch request with post should work

ReferenceError: TransformStream is not defined ❯ new Request node_modules/undici/lib/web/fetch/request.js:568:33 ❯ Module.fetch src/fetch.ts:136:21 ❯ test/fetch.test.ts:120:13 ❯ test/fetch.test.ts:115:18

Check failure on line 136 in src/fetch.ts

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

test/fetch.test.ts > fetch.test.ts > fetch request with post should work

ReferenceError: TransformStream is not defined ❯ new Request node_modules/undici/lib/web/fetch/request.js:568:33 ❯ Module.fetch src/fetch.ts:136:21 ❯ test/fetch.test.ts:120:13 ❯ test/fetch.test.ts:115:18

Check failure on line 136 in src/fetch.ts

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 16)

test/fetch.test.ts > fetch.test.ts > fetch request with post should work

ReferenceError: TransformStream is not defined ❯ new Request node_modules/undici/lib/web/fetch/request.js:568:33 ❯ Module.fetch src/fetch.ts:136:21 ❯ test/fetch.test.ts:120:13 ❯ test/fetch.test.ts:115:18
const requestId = globalId('HttpClientRequest');
// https://developer.chrome.com/docs/devtools/network/reference/?utm_source=devtools#timing-explanation
const timing = {
Expand Down Expand Up @@ -218,7 +218,7 @@
} as any as RawResponseWithMeta;
try {
await FetchFactory.#opaqueLocalStorage.run(internalOpaque, async () => {
res = await UndiciFetch(input, init);
res = await UndiciFetch(request);
});
} catch (e: any) {
updateSocketInfo(socketInfo, internalOpaque, e);
Expand Down
11 changes: 11 additions & 0 deletions test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
fetch, FetchDiagnosticsMessage, FetchFactory, FetchResponseDiagnosticsMessage,
} from '../src/fetch.js';
import { RequestDiagnosticsMessage, ResponseDiagnosticsMessage } from '../src/HttpClient.js';
import { Request } from 'undici';

describe('fetch.test.ts', () => {
let close: any;
Expand Down Expand Up @@ -109,4 +110,14 @@ describe('fetch.test.ts', () => {
assert(stats);
assert(Object.keys(stats).length > 0);
});

it('fetch request with post should work', async () => {
await assert.doesNotReject(async () => {
const request = new Request(_url, {
method: 'POST',
body: 'test-body',
});
await fetch(request);
}, /Cannot construct a Request with a Request object that has already been used/);
});
});
Loading