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: keep IncomingHttpHeaders the same type as undici #473

Closed
wants to merge 2 commits into from
Closed
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: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"mime-types": "^2.1.35",
"pump": "^3.0.0",
"qs": "^6.11.2",
"type-fest": "^4.3.1",
"undici": "^5.22.1",
"ylru": "^1.3.2"
},
Expand Down
4 changes: 1 addition & 3 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

type Exists<T> = T extends undefined ? never : T;
type UndiciRequestOption = Exists<Parameters<typeof undiciRequest>[1]>;
type PropertyShouldBe<T, K extends keyof T, V> = Omit<T, K> & { [P in K]: V };
type IUndiciRequestOption = PropertyShouldBe<UndiciRequestOption, 'headers', IncomingHttpHeaders>;

const PROTO_RE = /^https?:\/\//i;
const FormData = FormDataNative ?? FormDataNode;
Expand Down Expand Up @@ -347,7 +345,7 @@
}

try {
const requestOptions: IUndiciRequestOption = {
const requestOptions: UndiciRequestOption = {
method,
maxRedirections: args.maxRedirects ?? 10,
headersTimeout,
Expand Down Expand Up @@ -474,7 +472,7 @@
} else {
if (args.contentType === 'json'
|| args.contentType === 'application/json'
|| headers['content-type']?.startsWith('application/json')) {

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.

Check failure on line 475 in src/HttpClient.ts

View workflow job for this annotation

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

Property 'startsWith' does not exist on type 'string | string[]'.
requestOptions.body = JSON.stringify(args.data);
if (!headers['content-type']) {
headers['content-type'] = 'application/json';
Expand Down Expand Up @@ -544,7 +542,7 @@
res.status = res.statusCode = response.statusCode;
res.statusText = STATUS_CODES[res.status] || '';
if (res.headers['content-length']) {
res.size = parseInt(res.headers['content-length']);

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.

Check failure on line 545 in src/HttpClient.ts

View workflow job for this annotation

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

Argument of type 'string | string[]' is not assignable to parameter of type 'string'.
}

let data: any = null;
Expand Down
8 changes: 2 additions & 6 deletions src/IncomingHttpHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import type { Except } from 'type-fest';
import type { IncomingHttpHeaders as HTTPIncomingHttpHeaders } from 'node:http';

// fix set-cookie type define https://github.com/nodejs/undici/pull/1893
export interface IncomingHttpHeaders extends Except<HTTPIncomingHttpHeaders, 'set-cookie'> {
'set-cookie'?: string | string[];
}
// keep the same type as undici IncomingHttpHeaders
export type IncomingHttpHeaders = Record<string, string | string[] | undefined>;
Loading