urllib 3.27.1 → 3.27.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,8 +26,9 @@ export type ClientOptions = {
26
26
  */
27
27
  cert?: string | Buffer;
28
28
  /**
29
- * If true, the server certificate is verified against the list of supplied CAs.
30
- * An 'error' event is emitted if verification fails.Default: true.
29
+ * If `true`, the server certificate is verified against the list of supplied CAs.
30
+ * An 'error' event is emitted if verification fails.
31
+ * Default: `true`
31
32
  */
32
33
  rejectUnauthorized?: boolean;
33
34
  /**
@@ -68,7 +68,7 @@ class BlobFromStream {
68
68
  return 'Blob';
69
69
  }
70
70
  }
71
- exports.HEADER_USER_AGENT = (0, default_user_agent_1.default)('node-urllib', '3.27.1');
71
+ exports.HEADER_USER_AGENT = (0, default_user_agent_1.default)('node-urllib', '3.27.2');
72
72
  function getFileName(stream) {
73
73
  const filePath = stream.path;
74
74
  if (filePath) {
@@ -1,8 +1,18 @@
1
1
  import { HttpClient } from './HttpClient.js';
2
2
  import { RequestOptions, RequestURL } from './Request.js';
3
- export declare function getDefaultHttpClient(): HttpClient;
4
- export declare function request<T = any>(url: RequestURL, options?: RequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
5
- export declare function curl<T = any>(url: RequestURL, options?: RequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
3
+ export declare function getDefaultHttpClient(rejectUnauthorized?: boolean, allowH2?: boolean): HttpClient;
4
+ export interface UrllibRequestOptions extends RequestOptions {
5
+ /**
6
+ * If `true`, the server certificate is verified against the list of supplied CAs.
7
+ * An 'error' event is emitted if verification fails.
8
+ * Default: `true`
9
+ */
10
+ rejectUnauthorized?: boolean;
11
+ /** Allow to use HTTP2 first. Default is `false` */
12
+ allowH2?: boolean;
13
+ }
14
+ export declare function request<T = any>(url: RequestURL, options?: UrllibRequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
15
+ export declare function curl<T = any>(url: RequestURL, options?: UrllibRequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
6
16
  export { MockAgent, ProxyAgent, Agent, Dispatcher, setGlobalDispatcher, getGlobalDispatcher, } from 'undici';
7
17
  export { HttpClient, HttpClient as HttpClient2, HEADER_USER_AGENT as USER_AGENT, RequestDiagnosticsMessage, ResponseDiagnosticsMessage, } from './HttpClient.js';
8
18
  export { RequestOptions, RequestOptions as RequestOptions2, RequestURL, HttpMethod, FixJSONCtlCharsHandler, FixJSONCtlChars, } from './Request.js';
@@ -24,8 +24,40 @@ exports.curl = curl;
24
24
  const ylru_1 = __importDefault(require("ylru"));
25
25
  const HttpClient_js_1 = require("./HttpClient.js");
26
26
  let httpClient;
27
+ let allowH2HttpClient;
28
+ let allowUnauthorizedHttpClient;
29
+ let allowH2AndUnauthorizedHttpClient;
27
30
  const domainSocketHttpClients = new ylru_1.default(50);
28
- function getDefaultHttpClient() {
31
+ function getDefaultHttpClient(rejectUnauthorized, allowH2) {
32
+ if (rejectUnauthorized === false) {
33
+ if (allowH2) {
34
+ if (!allowH2AndUnauthorizedHttpClient) {
35
+ allowH2AndUnauthorizedHttpClient = new HttpClient_js_1.HttpClient({
36
+ allowH2,
37
+ connect: {
38
+ rejectUnauthorized,
39
+ },
40
+ });
41
+ }
42
+ return allowH2AndUnauthorizedHttpClient;
43
+ }
44
+ if (!allowUnauthorizedHttpClient) {
45
+ allowUnauthorizedHttpClient = new HttpClient_js_1.HttpClient({
46
+ connect: {
47
+ rejectUnauthorized,
48
+ },
49
+ });
50
+ }
51
+ return allowUnauthorizedHttpClient;
52
+ }
53
+ if (allowH2) {
54
+ if (!allowH2HttpClient) {
55
+ allowH2HttpClient = new HttpClient_js_1.HttpClient({
56
+ allowH2,
57
+ });
58
+ }
59
+ return allowH2HttpClient;
60
+ }
29
61
  if (!httpClient) {
30
62
  httpClient = new HttpClient_js_1.HttpClient();
31
63
  }
@@ -42,7 +74,7 @@ async function request(url, options) {
42
74
  }
43
75
  return await domainSocketHttpclient.request(url, options);
44
76
  }
45
- return await getDefaultHttpClient().request(url, options);
77
+ return await getDefaultHttpClient(options?.rejectUnauthorized, options?.allowH2).request(url, options);
46
78
  }
47
79
  // export curl method is keep compatible with urllib.curl()
48
80
  // ```ts
@@ -26,8 +26,9 @@ export type ClientOptions = {
26
26
  */
27
27
  cert?: string | Buffer;
28
28
  /**
29
- * If true, the server certificate is verified against the list of supplied CAs.
30
- * An 'error' event is emitted if verification fails.Default: true.
29
+ * If `true`, the server certificate is verified against the list of supplied CAs.
30
+ * An 'error' event is emitted if verification fails.
31
+ * Default: `true`
31
32
  */
32
33
  rejectUnauthorized?: boolean;
33
34
  /**
@@ -62,7 +62,7 @@ class BlobFromStream {
62
62
  return 'Blob';
63
63
  }
64
64
  }
65
- export const HEADER_USER_AGENT = createUserAgent('node-urllib', '3.27.1');
65
+ export const HEADER_USER_AGENT = createUserAgent('node-urllib', '3.27.2');
66
66
  function getFileName(stream) {
67
67
  const filePath = stream.path;
68
68
  if (filePath) {
@@ -1,8 +1,18 @@
1
1
  import { HttpClient } from './HttpClient.js';
2
2
  import { RequestOptions, RequestURL } from './Request.js';
3
- export declare function getDefaultHttpClient(): HttpClient;
4
- export declare function request<T = any>(url: RequestURL, options?: RequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
5
- export declare function curl<T = any>(url: RequestURL, options?: RequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
3
+ export declare function getDefaultHttpClient(rejectUnauthorized?: boolean, allowH2?: boolean): HttpClient;
4
+ export interface UrllibRequestOptions extends RequestOptions {
5
+ /**
6
+ * If `true`, the server certificate is verified against the list of supplied CAs.
7
+ * An 'error' event is emitted if verification fails.
8
+ * Default: `true`
9
+ */
10
+ rejectUnauthorized?: boolean;
11
+ /** Allow to use HTTP2 first. Default is `false` */
12
+ allowH2?: boolean;
13
+ }
14
+ export declare function request<T = any>(url: RequestURL, options?: UrllibRequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
15
+ export declare function curl<T = any>(url: RequestURL, options?: UrllibRequestOptions): Promise<import("./Response.js").HttpClientResponse<T>>;
6
16
  export { MockAgent, ProxyAgent, Agent, Dispatcher, setGlobalDispatcher, getGlobalDispatcher, } from 'undici';
7
17
  export { HttpClient, HttpClient as HttpClient2, HEADER_USER_AGENT as USER_AGENT, RequestDiagnosticsMessage, ResponseDiagnosticsMessage, } from './HttpClient.js';
8
18
  export { RequestOptions, RequestOptions as RequestOptions2, RequestURL, HttpMethod, FixJSONCtlCharsHandler, FixJSONCtlChars, } from './Request.js';
package/dist/esm/index.js CHANGED
@@ -1,8 +1,40 @@
1
1
  import LRU from 'ylru';
2
2
  import { HttpClient, HEADER_USER_AGENT } from './HttpClient.js';
3
3
  let httpClient;
4
+ let allowH2HttpClient;
5
+ let allowUnauthorizedHttpClient;
6
+ let allowH2AndUnauthorizedHttpClient;
4
7
  const domainSocketHttpClients = new LRU(50);
5
- export function getDefaultHttpClient() {
8
+ export function getDefaultHttpClient(rejectUnauthorized, allowH2) {
9
+ if (rejectUnauthorized === false) {
10
+ if (allowH2) {
11
+ if (!allowH2AndUnauthorizedHttpClient) {
12
+ allowH2AndUnauthorizedHttpClient = new HttpClient({
13
+ allowH2,
14
+ connect: {
15
+ rejectUnauthorized,
16
+ },
17
+ });
18
+ }
19
+ return allowH2AndUnauthorizedHttpClient;
20
+ }
21
+ if (!allowUnauthorizedHttpClient) {
22
+ allowUnauthorizedHttpClient = new HttpClient({
23
+ connect: {
24
+ rejectUnauthorized,
25
+ },
26
+ });
27
+ }
28
+ return allowUnauthorizedHttpClient;
29
+ }
30
+ if (allowH2) {
31
+ if (!allowH2HttpClient) {
32
+ allowH2HttpClient = new HttpClient({
33
+ allowH2,
34
+ });
35
+ }
36
+ return allowH2HttpClient;
37
+ }
6
38
  if (!httpClient) {
7
39
  httpClient = new HttpClient();
8
40
  }
@@ -19,7 +51,7 @@ export async function request(url, options) {
19
51
  }
20
52
  return await domainSocketHttpclient.request(url, options);
21
53
  }
22
- return await getDefaultHttpClient().request(url, options);
54
+ return await getDefaultHttpClient(options?.rejectUnauthorized, options?.allowH2).request(url, options);
23
55
  }
24
56
  // export curl method is keep compatible with urllib.curl()
25
57
  // ```ts
package/dist/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "urllib",
3
- "version": "3.27.1"
3
+ "version": "3.27.2"
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "urllib",
3
- "version": "3.27.1",
3
+ "version": "3.27.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -78,7 +78,7 @@
78
78
  "git-contributor": "^2.0.0",
79
79
  "iconv-lite": "^0.6.3",
80
80
  "proxy": "^1.0.2",
81
- "selfsigned": "^2.0.1",
81
+ "selfsigned": "^2.4.1",
82
82
  "tar-stream": "^2.2.0",
83
83
  "tshy": "^1.0.0",
84
84
  "tshy-after": "^1.0.0",
package/src/HttpClient.ts CHANGED
@@ -90,8 +90,9 @@ export type ClientOptions = {
90
90
  */
91
91
  cert?: string | Buffer;
92
92
  /**
93
- * If true, the server certificate is verified against the list of supplied CAs.
94
- * An 'error' event is emitted if verification fails.Default: true.
93
+ * If `true`, the server certificate is verified against the list of supplied CAs.
94
+ * An 'error' event is emitted if verification fails.
95
+ * Default: `true`
95
96
  */
96
97
  rejectUnauthorized?: boolean;
97
98
  /**
package/src/index.ts CHANGED
@@ -3,16 +3,62 @@ import { HttpClient, HEADER_USER_AGENT } from './HttpClient.js';
3
3
  import { RequestOptions, RequestURL } from './Request.js';
4
4
 
5
5
  let httpClient: HttpClient;
6
+ let allowH2HttpClient: HttpClient;
7
+ let allowUnauthorizedHttpClient: HttpClient;
8
+ let allowH2AndUnauthorizedHttpClient: HttpClient;
6
9
  const domainSocketHttpClients = new LRU(50);
7
10
 
8
- export function getDefaultHttpClient(): HttpClient {
11
+ export function getDefaultHttpClient(rejectUnauthorized?: boolean, allowH2?: boolean): HttpClient {
12
+ if (rejectUnauthorized === false) {
13
+ if (allowH2) {
14
+ if (!allowH2AndUnauthorizedHttpClient) {
15
+ allowH2AndUnauthorizedHttpClient = new HttpClient({
16
+ allowH2,
17
+ connect: {
18
+ rejectUnauthorized,
19
+ },
20
+ });
21
+ }
22
+ return allowH2AndUnauthorizedHttpClient;
23
+ }
24
+
25
+ if (!allowUnauthorizedHttpClient) {
26
+ allowUnauthorizedHttpClient = new HttpClient({
27
+ connect: {
28
+ rejectUnauthorized,
29
+ },
30
+ });
31
+ }
32
+ return allowUnauthorizedHttpClient;
33
+ }
34
+
35
+ if (allowH2) {
36
+ if (!allowH2HttpClient) {
37
+ allowH2HttpClient = new HttpClient({
38
+ allowH2,
39
+ });
40
+ }
41
+ return allowH2HttpClient;
42
+ }
43
+
9
44
  if (!httpClient) {
10
45
  httpClient = new HttpClient();
11
46
  }
12
47
  return httpClient;
13
48
  }
14
49
 
15
- export async function request<T = any>(url: RequestURL, options?: RequestOptions) {
50
+ export interface UrllibRequestOptions extends RequestOptions {
51
+ /**
52
+ * If `true`, the server certificate is verified against the list of supplied CAs.
53
+ * An 'error' event is emitted if verification fails.
54
+ * Default: `true`
55
+ */
56
+ rejectUnauthorized?: boolean;
57
+ /** Allow to use HTTP2 first. Default is `false` */
58
+ allowH2?: boolean;
59
+ }
60
+
61
+ export async function request<T = any>(url: RequestURL, options?: UrllibRequestOptions) {
16
62
  if (options?.socketPath) {
17
63
  let domainSocketHttpclient = domainSocketHttpClients.get<HttpClient>(options.socketPath);
18
64
  if (!domainSocketHttpclient) {
@@ -24,7 +70,7 @@ export async function request<T = any>(url: RequestURL, options?: RequestOptions
24
70
  return await domainSocketHttpclient.request<T>(url, options);
25
71
  }
26
72
 
27
- return await getDefaultHttpClient().request<T>(url, options);
73
+ return await getDefaultHttpClient(options?.rejectUnauthorized, options?.allowH2).request<T>(url, options);
28
74
  }
29
75
 
30
76
  // export curl method is keep compatible with urllib.curl()
@@ -32,7 +78,7 @@ export async function request<T = any>(url: RequestURL, options?: RequestOptions
32
78
  // import * as urllib from 'urllib';
33
79
  // urllib.curl(url);
34
80
  // ```
35
- export async function curl<T = any>(url: RequestURL, options?: RequestOptions) {
81
+ export async function curl<T = any>(url: RequestURL, options?: UrllibRequestOptions) {
36
82
  return await request<T>(url, options);
37
83
  }
38
84