-
Notifications
You must be signed in to change notification settings - Fork 124
feat: add rejectUnauthorized to RequestOptions #741
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
base: master
Are you sure you want to change the base?
Changes from all commits
718083a
28ffbcd
701a8e0
bca3315
87fe4b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 on lines
+164
to
+174
|
||
| }; | ||
|
|
||
| export type RequestMeta = { | ||
|
|
||
| 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; | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.