Skip to content
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
26 changes: 11 additions & 15 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,32 @@ export type ClientOptions = {
defaultArgs?: RequestOptions;
/** Allow to use HTTP2 first. Default is `false` */
allowH2?: boolean;
/**
* Custom DNS lookup function, default is `dns.lookup`.
*/
/** Custom DNS lookup function, default is `dns.lookup`. */
lookup?: LookupFunction;
/**
* check request address to protect from SSRF and similar attacks.
* It receive two arguments(ip and family) and should return true or false to identified the address is legal or not.
* It rely on lookup and have the same version requirement.
* Check request address to protect from SSRF and similar attacks. It receive two arguments(ip and family) and should
* return true or false to identified the address is legal or not. It rely on lookup and have the same version
* requirement.
Comment on lines +82 to +84
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

In this public API doc comment, "It receive" / "to identified" are grammatically incorrect. Since this block was reformatted, please update the wording (e.g., "It receives..." / "to identify...") to keep generated docs professional and clear.

Suggested change
* Check request address to protect from SSRF and similar attacks. It receive two arguments(ip and family) and should
* return true or false to identified the address is legal or not. It rely on lookup and have the same version
* requirement.
* Check request addresses to protect from SSRF and similar attacks. It receives two arguments (ip and family) and
* should return true or false to identify whether the address is legal. It relies on lookup and has the same
* version requirement.

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +84
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The re-wrapped JSDoc contains several grammatical errors that affect clarity: "It receive" should be "It receives", "identified" should be "identify", and "It rely" should be "It relies". Additionally, adding a space between "arguments" and the parenthesis improves readability.

Suggested change
* Check request address to protect from SSRF and similar attacks. It receive two arguments(ip and family) and should
* return true or false to identified the address is legal or not. It rely on lookup and have the same version
* requirement.
* Check request address to protect from SSRF and similar attacks. It receives two arguments (ip and family) and
* should return true or false to identify whether the address is legal or not. It relies on lookup and has the same
* version requirement.

*/
checkAddress?: CheckAddressFunction;
connect?: {
key?: string | Buffer;
/**
* A string or Buffer containing the certificate key of the client in PEM format.
* Notes: This is necessary only if using the client certificate authentication
* A string or Buffer containing the certificate key of the client in PEM format. Notes: This is necessary only if
* using the client certificate authentication
*/
cert?: string | Buffer;
/**
* If `true`, the server certificate is verified against the list of supplied CAs.
* An 'error' event is emitted if verification fails.
* Default: `true`
* 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;
/**
* socketPath string | null (optional) - Default: null - An IPC endpoint, either Unix domain socket or Windows named pipe
* SocketPath string | null (optional) - Default: null - An IPC endpoint, either Unix domain socket or Windows named
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The JSDoc refers to "SocketPath" (capital S), but the actual option is socketPath. Using the exact property name in the comment will avoid confusion when users search docs for this option.

Suggested change
* SocketPath string | null (optional) - Default: null - An IPC endpoint, either Unix domain socket or Windows named
* socketPath string | null (optional) - Default: null - An IPC endpoint, either Unix domain socket or Windows named

Copilot uses AI. Check for mistakes.
* pipe
Comment on lines +100 to +101
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The formatter capitalized socketPath to SocketPath. Since this refers to a specific property name, it should remain lowercase. Wrapping it in backticks will prevent the formatter from capitalizing it and clearly identify it as a technical term.

Suggested change
* SocketPath string | null (optional) - Default: null - An IPC endpoint, either Unix domain socket or Windows named
* pipe
* `socketPath` string | null (optional) - Default: null - An IPC endpoint, either Unix domain socket or Windows
* named pipe

*/
socketPath?: string | null;
/**
* connect timeout, default is 10000ms
*/
/** Connect timeout, default is 10000ms */
timeout?: number;
};
};
Expand Down
69 changes: 28 additions & 41 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ export type RequestOptions = {
*/
stream?: Readable;
/**
* A writable stream to be piped by the response stream.
* Responding data will be write to this stream and callback
* A writable stream to be piped by the response stream. Responding data will be write to this stream and callback
* will be called with data set null after finished writing.
Comment on lines +35 to 36
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The JSDoc sentence reads ungrammatically: "Responding data will be write". Since this block was reformatted, consider fixing it to "will be written" (and adjust wording as needed) to keep the public API docs clear.

Suggested change
* A writable stream to be piped by the response stream. Responding data will be write to this stream and callback
* will be called with data set null after finished writing.
* A writable stream to which the response stream will be piped. Response data will be written to this stream, and the
* callback will be called with `data` set to `null` after writing finishes.

Copilot uses AI. Check for mistakes.
*/
writeStream?: Writable;
/**
* The files will send with multipart/form-data format, base on formstream.
* If method not set, will use POST method by default.
* The files will send with multipart/form-data format, base on formstream. If method not set, will use POST method by
* default.
*/
files?:
| Array<Readable | Buffer | string>
Expand All @@ -51,16 +50,14 @@ export type RequestOptions = {
/** Type of request data, could be 'json'. If it's 'json', will auto set Content-Type: 'application/json' header. */
contentType?: string;
/**
* Type of response data. Could be text or json.
* If it's text or html, the callbacked data would be a String.
* If it's json, the data of callback would be a parsed JSON Object
* and will auto set Accept: 'application/json' header.
* Type of response data. Could be text or json. If it's text or html, the callbacked data would be a String. If it's
* json, the data of callback would be a parsed JSON Object and will auto set Accept: 'application/json' header.
* Default is 'buffer'.
Comment on lines +53 to 55
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

In this JSDoc, "callbacked" is not correct English (should be something like "callback" / "returned" / "passed to the callback"). Since this comment was reformatted, please correct the wording for clarity.

Suggested change
* Type of response data. Could be text or json. If it's text or html, the callbacked data would be a String. If it's
* json, the data of callback would be a parsed JSON Object and will auto set Accept: 'application/json' header.
* Default is 'buffer'.
* Type of response data. Could be text or json. If it's text or html, the data passed to the callback will be a
* string. If it's json, the data passed to the callback will be a parsed JSON object and will auto set Accept:
* 'application/json' header. Default is 'buffer'.

Copilot uses AI. Check for mistakes.
*/
dataType?: 'text' | 'html' | 'json' | 'buffer' | 'stream';
/**
* urllib default use URLSearchParams to stringify form data which don't support nested object,
* will use qs instead of URLSearchParams to support nested object by set this option to true.
* Urllib default use URLSearchParams to stringify form data which don't support nested object, will use qs instead of
* URLSearchParams to support nested object by set this option to true.
Comment on lines +59 to +60
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This sentence is a run-on and contains grammatical errors ("default use", "don't support nested object"). Improving the structure makes the documentation much clearer.

Suggested change
* Urllib default use URLSearchParams to stringify form data which don't support nested object, will use qs instead of
* URLSearchParams to support nested object by set this option to true.
* Urllib by default uses URLSearchParams to stringify form data, which doesn't support nested objects. Set this
* option to true to use `qs` instead of URLSearchParams to support nested objects.

*/
nestedQuerystring?: boolean;
/**
Expand All @@ -85,27 +82,23 @@ export type RequestOptions = {
/** Request headers. */
headers?: IncomingHttpHeaders;
/**
* Request timeout in milliseconds for connecting phase and response receiving phase.
* Defaults is `5000`, both are 5 seconds. You can use timeout: 5000 to tell urllib use same timeout on two phase or set them separately such as
* Request timeout in milliseconds for connecting phase and response receiving phase. Defaults is `5000`, both are 5
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Minor grammar fix: "Defaults is" should be "Default is".

Suggested change
* Request timeout in milliseconds for connecting phase and response receiving phase. Defaults is `5000`, both are 5
* Request timeout in milliseconds for connecting phase and response receiving phase. Default is `5000`, both are 5

* seconds. You can use timeout: 5000 to tell urllib use same timeout on two phase or set them separately such as
* timeout: [3000, 5000], which will set connecting timeout to 3s and response 5s.
*/
timeout?: number | number[];
/**
* Default is `4000`, 4 seconds - The timeout after which a socket without active requests will time out.
* Monitors time between activity on a connected socket.
* This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
* Default is `4000`, 4 seconds - The timeout after which a socket without active requests will time out. Monitors
* time between activity on a connected socket. This value may be overridden by _keep-alive_ hints from the server.
* See [MDN: HTTP - Headers - Keep-Alive
* directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
Comment on lines +93 to +94
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The markdown link text is split across lines inside the [...] label. Some JSDoc/Markdown renderers don’t handle newlines in link labels well, which can break the rendered link text. Consider rewrapping so the line break happens outside the link label (or shorten the label) while keeping the URL intact.

Suggested change
* See [MDN: HTTP - Headers - Keep-Alive
* directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
* See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives)
* for more details.

Copilot uses AI. Check for mistakes.
*/
keepAliveTimeout?: number;
/**
* username:password used in HTTP Basic Authorization.
* Alias to `headers.authorization = xxx`
**/
/** Username:password used in HTTP Basic Authorization. Alias to `headers.authorization = xxx` */
auth?: string;
/**
* username:password used in HTTP Digest Authorization.
* */
/** Username:password used in HTTP Digest Authorization. */
digestAuth?: string;
/** follow HTTP 3xx responses as redirects. defaults to true. */
/** Follow HTTP 3xx responses as redirects. defaults to true. */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Capitalize "Defaults" for consistency with the start of the sentence.

Suggested change
/** Follow HTTP 3xx responses as redirects. defaults to true. */
/** Follow HTTP 3xx responses as redirects. Defaults to true. */

followRedirect?: boolean;
/** The maximum number of redirects to follow, defaults to 10. */
maxRedirects?: number;
Expand All @@ -118,28 +111,26 @@ export type RequestOptions = {
/**
* @deprecated
* Alias to compressed
* */
*/
gzip?: boolean;
/**
* Enable timing or not, default is `true`.
* */
/** Enable timing or not, default is `true`. */
timing?: boolean;
/**
* Auto retry times on 5xx response, default is `0`. Don't work on streaming request
* It's not supported by using retry and writeStream, because the retry request can't stop the stream which is consuming.
**/
* Auto retry times on 5xx response, default is `0`. Don't work on streaming request It's not supported by using retry
* and writeStream, because the retry request can't stop the stream which is consuming.
Comment on lines +119 to +120
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This JSDoc became a run-on sentence after reflow: "Don't work on streaming request It's not supported...". Add punctuation (e.g., a period after "request") so the two sentences are properly separated.

Copilot uses AI. Check for mistakes.
Comment on lines +119 to +120
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The formatter merged two sentences without punctuation, creating a run-on sentence. Adding a period and fixing the grammar ("Don't" to "Doesn't", "request" to "requests") improves readability.

Suggested change
* Auto retry times on 5xx response, default is `0`. Don't work on streaming request It's not supported by using retry
* and writeStream, because the retry request can't stop the stream which is consuming.
* Auto retry times on 5xx response, default is `0`. Doesn't work on streaming requests. It's not supported when
* using retry and writeStream, because the retry request can't stop the stream which is consuming.

*/
retry?: number;
/** Wait a delay(ms) between retries */
retryDelay?: number;
/**
* Determine whether retry, a response object as the first argument.
* It will retry when status >= 500 by default. Request error is not included.
* Determine whether retry, a response object as the first argument. It will retry when status >= 500 by default.
* Request error is not included.
*/
isRetry?: (response: HttpClientResponse) => boolean;
/**
* Auto retry times on socket error, default is `1`. Don't work on streaming request
* It's not supported by using retry and writeStream, because the retry request can't stop the stream which is consuming.
**/
* Auto retry times on socket error, default is `1`. Don't work on streaming request It's not supported by using retry
* and writeStream, because the retry request can't stop the stream which is consuming.
Comment on lines +131 to +132
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This JSDoc also reads as a run-on sentence after reflow: "Don't work on streaming request It's not supported...". Add punctuation between these sentences for readability.

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +132
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The formatter merged two sentences without punctuation, creating a run-on sentence. Adding a period and fixing the grammar ("Don't" to "Doesn't", "request" to "requests") improves readability.

Suggested change
* Auto retry times on socket error, default is `1`. Don't work on streaming request It's not supported by using retry
* and writeStream, because the retry request can't stop the stream which is consuming.
* Auto retry times on socket error, default is `1`. Doesn't work on streaming requests. It's not supported when
* using retry and writeStream, because the retry request can't stop the stream which is consuming.

*/
socketErrorRetry?: number;
/** Default: `null` */
opaque?: unknown;
Expand All @@ -148,13 +139,9 @@ export type RequestOptions = {
* Maybe you should use opaque instead
*/
ctx?: unknown;
/**
* request dispatcher, default is getGlobalDispatcher()
*/
/** Request dispatcher, default is getGlobalDispatcher() */
dispatcher?: Dispatcher;
/**
* unix domain socket file path
*/
/** Unix domain socket file path */
socketPath?: string | null;
/** Whether the request should stablish a keep-alive or not. Default `false`, try to keep alive by default */
reset?: boolean;
Expand Down
8 changes: 3 additions & 5 deletions src/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export type SocketInfo = {
connectPort?: string;
};

/**
* https://eggjs.org/en/core/httpclient.html#timing-boolean
*/
/** https://eggjs.org/en/core/httpclient.html#timing-boolean */
export type Timing = {
// socket assigned
queuing: number;
Expand All @@ -47,9 +45,9 @@ export type RawResponseWithMeta = Readable & {
statusCode: number;
statusText: string;
/**
* @alias statusText
* @deprecated use `statusText` instead
**/
* @alias statusText
*/
statusMessage: string;
headers: IncomingHttpHeaders;
timing: Timing;
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ 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`
* 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` */
Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default defineConfig({
newlinesBetween: true,
order: 'asc',
},
jsdoc: {
preferCodeFences: true,
},
},
lint: {
options: {
Expand Down
Loading