@e-mc/request 0.10.1 → 0.10.3

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.
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "@e-mc/request",
3
- "version": "0.10.1",
4
- "description": "Request constructor for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/request"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/module": "0.10.1",
24
- "@e-mc/types": "0.10.1",
25
- "combined-stream": "^1.0.8",
26
- "js-yaml": "^4.1.0",
27
- "picomatch": "^4.0.2",
28
- "which": "^2.0.2"
29
- }
30
- }
1
+ {
2
+ "name": "@e-mc/request",
3
+ "version": "0.10.3",
4
+ "description": "Request constructor for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/request"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "BSD-3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/module": "0.10.3",
24
+ "@e-mc/types": "0.10.3",
25
+ "combined-stream": "^1.0.8",
26
+ "js-yaml": "^4.1.0",
27
+ "picomatch": "^4.0.2",
28
+ "which": "^2.0.2"
29
+ }
30
+ }
package/util.d.ts CHANGED
@@ -1,28 +1,29 @@
1
- import type { AuthValue } from '../types/lib/http';
2
- import type { HttpProxySettings } from '../types/lib/settings';
3
-
4
- import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
5
- import type { Readable, Writable } from 'stream';
6
-
7
- declare namespace util {
8
- function parseHeader<T = unknown>(headers: IncomingHttpHeaders, name: string): T | undefined;
9
- function normalizeHeaders(headers: OutgoingHttpHeaders): OutgoingHttpHeaders;
10
- function getBasicAuth(auth: AuthValue): string;
11
- function getBasicAuth(username: unknown, password?: unknown): string;
12
- function hasBasicAuth(value: string): boolean;
13
- function checkRetryable(err: unknown): boolean;
14
- function isRetryable(value: number, timeout?: boolean): boolean;
15
- function parseHttpProxy(value?: string): HttpProxySettings | undefined;
16
- function trimPath(value: string): string;
17
- function asInt(value: unknown): number;
18
- function asFloat(value: unknown): number;
19
- function fromSeconds(value: unknown): number;
20
- function getTransferRate(length: number, timeMs: number, unitSeparator?: string): string;
21
- function hasSameStat(src: string, dest: string, keepEmpty?: boolean): boolean;
22
- function hasSize(value: string, keepEmpty?: boolean): boolean;
23
- function getSize(value: string, diskUsed?: boolean): number;
24
- function byteLength(value: Bufferable, encoding?: BufferEncoding): number;
25
- function cleanupStream(target: Readable | Writable, pathname?: string): void;
26
- }
27
-
1
+ import type { AuthValue } from '@e-mc/types/lib/http';
2
+ import type { HttpProxySettings } from '@e-mc/types/lib/settings';
3
+
4
+ import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
5
+ import type { Readable, Writable } from 'stream';
6
+
7
+ declare namespace util {
8
+ function parseHeader<T = unknown>(headers: IncomingHttpHeaders, name: string): T | undefined;
9
+ function parseOutgoingHeaders(headers: OutgoingHttpHeaders | Headers | undefined): OutgoingHttpHeaders | undefined;
10
+ function normalizeHeaders(headers: OutgoingHttpHeaders): OutgoingHttpHeaders;
11
+ function getBasicAuth(auth: AuthValue): string;
12
+ function getBasicAuth(username: unknown, password?: unknown): string;
13
+ function hasBasicAuth(value: string): boolean;
14
+ function checkRetryable(err: unknown): boolean;
15
+ function isRetryable(value: number, timeout?: boolean): boolean;
16
+ function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
17
+ function trimPath(value: string): string;
18
+ function asInt(value: unknown): number;
19
+ function asFloat(value: unknown): number;
20
+ function fromSeconds(value: unknown): number;
21
+ function getTransferRate(length: number, timeMs: number, unitSeparator?: string): string;
22
+ function hasSameStat(src: string, dest: string, keepEmpty?: boolean): boolean;
23
+ function hasSize(value: string, keepEmpty?: boolean): boolean;
24
+ function getSize(value: string, diskUsed?: boolean): number;
25
+ function byteLength(value: Bufferable, encoding?: BufferEncoding): number;
26
+ function cleanupStream(target: Readable | Writable, pathname?: string): void;
27
+ }
28
+
28
29
  export = util;
package/util.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  exports.parseHeader = parseHeader;
3
+ exports.parseOutgoingHeaders = parseOutgoingHeaders;
3
4
  exports.normalizeHeaders = normalizeHeaders;
4
5
  exports.getBasicAuth = getBasicAuth;
5
6
  exports.hasBasicAuth = hasBasicAuth;
@@ -19,8 +20,8 @@ exports.cleanupStream = cleanupStream;
19
20
  const path = require("path");
20
21
  const fs = require("fs");
21
22
  const util = require("util");
22
- const module_1 = require("@e-mc/module");
23
23
  const types_1 = require("@e-mc/types");
24
+ const module_1 = require("@e-mc/module");
24
25
  const SUPPORTED_USVSTRING = (0, types_1.supported)(16, 8);
25
26
  const safeInt = (value) => value >= 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : NaN;
26
27
  function parseHeader(headers, name) {
@@ -40,6 +41,23 @@ function parseHeader(headers, name) {
40
41
  }
41
42
  }
42
43
  }
44
+ function parseOutgoingHeaders(headers) {
45
+ if (headers) {
46
+ if (globalThis.Headers && headers instanceof Headers) {
47
+ const result = {};
48
+ headers.forEach((value, key) => {
49
+ if (key === 'set-cookie') {
50
+ (result[key] ||= []).push(value);
51
+ }
52
+ else {
53
+ result[key] = value;
54
+ }
55
+ });
56
+ return result;
57
+ }
58
+ return headers;
59
+ }
60
+ }
43
61
  function normalizeHeaders(headers) {
44
62
  const result = Object.create(null);
45
63
  for (const name in headers) {
@@ -52,11 +70,11 @@ function normalizeHeaders(headers) {
52
70
  value = value.trim();
53
71
  break;
54
72
  default:
55
- if (Array.isArray(value)) {
56
- value = value.map(out => module_1.asString(out).trim());
57
- break;
73
+ if (!(0, types_1.isArray)(value)) {
74
+ continue;
58
75
  }
59
- continue;
76
+ value = value.map(out => module_1.asString(out).trim());
77
+ break;
60
78
  }
61
79
  if (value) {
62
80
  result[trimPath(name.trim().toLowerCase())] = value;
@@ -113,28 +131,36 @@ function isRetryable(value, timeout) {
113
131
  case 502:
114
132
  case 503:
115
133
  case 521:
116
- if (!timeout) {
117
- return true;
118
- }
134
+ return !timeout;
119
135
  default:
120
136
  return false;
121
137
  }
122
138
  }
123
- function parseHttpProxy(value) {
124
- value || (value = process.env.HTTP_PROXY || process.env.HTTPS_PROXY);
139
+ function parseHttpProxy(value, ignoreEnv) {
140
+ if (!ignoreEnv) {
141
+ value ||= process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
142
+ }
125
143
  if (value) {
126
144
  try {
127
145
  const url = new URL(value);
128
146
  if (url.port) {
129
147
  let exclude;
130
- if (process.env.NO_PROXY) {
148
+ if (process.env.NO_PROXY && !ignoreEnv) {
131
149
  exclude = [];
132
- for (const item of process.env.NO_PROXY.trim().split(/\s*,\s*/)) {
150
+ for (let item of process.env.NO_PROXY.trim().split(/\s*,\s*/)) {
151
+ if (item === '*') {
152
+ exclude = ['**'];
153
+ break;
154
+ }
133
155
  if (module_1.isURL(item)) {
134
156
  exclude.push(item);
135
157
  }
136
158
  else {
137
- exclude.push(`https://${item}`, `http://${item}`);
159
+ const negate = item.startsWith('!') ? (item = item.substring(1), '!') : '';
160
+ if (!/^(?:[^.]+|(?:\d+\.){3}\d+)$/.test(item) && !item.includes('*')) {
161
+ item = '*' + item;
162
+ }
163
+ exclude.push(`${negate}http?(s)://${item}?(/)**`);
138
164
  }
139
165
  }
140
166
  }