Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ export type RequestOptions = {
/** Default: `64 KiB` */
highWaterMark?: number;
signal?: AbortSignal | EventEmitter;
/**
* If `true`, the server certificate is verified against the list of supplied CAs.
* If verification fails, the request promise is rejected.
*
* This option is only effective when using the top-level request/curl wrapper with
* its default dispatcher. It may be ignored when using `HttpClient.request()`
* directly or when `dispatcher` is explicitly provided.
*
* Default: `true`
*/
rejectUnauthorized?: boolean;
Comment thread
fengmk2 marked this conversation as resolved.
Comment on lines +164 to +174
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestOptions is also the options type for HttpClient.request(), but HttpClient never reads options.rejectUnauthorized (it only comes from ClientOptions.connect.rejectUnauthorized or a provided dispatcher). With this change, TypeScript will now accept httpclient.request(url, { rejectUnauthorized: false }), but it will be a no-op at runtime. Consider scoping this to a wrapper-only options type (e.g. exporting a separate UrllibRequestOptions) or implementing per-request handling so the type matches behavior.

Copilot uses AI. Check for mistakes.
};

export type RequestMeta = {
Expand Down
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ export function getDefaultHttpClient(rejectUnauthorized?: boolean, allowH2?: boo
}

interface UrllibRequestOptions extends RequestOptions {
/**
* If `true`, the server certificate is verified against the list of supplied CAs.
* An 'error' event is emitted if verification fails.
* Default: `true`
*/
rejectUnauthorized?: boolean;
/** Allow to use HTTP2 first. Default is `false` */
allowH2?: boolean;
}
Expand Down
48 changes: 48 additions & 0 deletions test/options.rejectUnauthorized.typecheck.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { strict as assert } from 'node:assert';

import { describe, it, beforeAll, afterAll } from 'vite-plus/test';

import urllib from '../src/index.js';
import type { RequestOptions } from '../src/index.js';
import { startServer } from './fixtures/server.js';

describe('options.rejectUnauthorized.typecheck.test.ts', () => {
let close: any;
let _url: string;
beforeAll(async () => {
const { closeServer, url } = await startServer({ https: true });
close = closeServer;
_url = url;
});

afterAll(async () => {
await close();
});

it('should accept rejectUnauthorized on RequestOptions type', async () => {
// Type check: rejectUnauthorized should be assignable on RequestOptions
const options: RequestOptions = {
rejectUnauthorized: false,
dataType: 'json',
};
const response = await urllib.request(_url, options);
assert.equal(response.status, 200);
assert.equal(response.data.method, 'GET');
});

it('should accept rejectUnauthorized = true on RequestOptions type', async () => {
const options: RequestOptions = {
rejectUnauthorized: true,
dataType: 'json',
};
await assert.rejects(
async () => {
await urllib.request(_url, options);
},
(err: any) => {
assert.match(err.message, /signed certificate/);
return true;
},
);
});
});
Loading