@e-mc/request 0.12.11 → 0.12.13

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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.11/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.13/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -255,9 +255,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
255
255
 
256
256
  ## References
257
257
 
258
- - https://www.unpkg.com/@e-mc/types@0.12.11/lib/http.d.ts
259
- - https://www.unpkg.com/@e-mc/types@0.12.11/lib/request.d.ts
260
- - https://www.unpkg.com/@e-mc/types@0.12.11/lib/settings.d.ts
258
+ - https://www.unpkg.com/@e-mc/types@0.12.13/lib/http.d.ts
259
+ - https://www.unpkg.com/@e-mc/types@0.12.13/lib/request.d.ts
260
+ - https://www.unpkg.com/@e-mc/types@0.12.13/lib/settings.d.ts
261
261
 
262
262
  * https://www.npmjs.com/package/@types/node
263
263
 
@@ -73,13 +73,21 @@ class HttpAdapter {
73
73
  return;
74
74
  }
75
75
  const statusCode = headers[':status'];
76
- if (statusCode < 300) {
77
- this.acceptResponse(headers);
76
+ if (statusCode === 204 || statusCode === 304) {
77
+ this.acceptResponse(headers, true);
78
78
  }
79
- else if (statusCode < 400) {
79
+ else if (statusCode < 300) {
80
+ this.acceptResponse(headers, false);
81
+ }
82
+ else if (statusCode === 301 ||
83
+ statusCode === 302 ||
84
+ statusCode === 303 ||
85
+ statusCode === 307 ||
86
+ statusCode === 308) {
80
87
  this.redirectResponse(statusCode, headers.location);
81
88
  }
82
- else if (statusCode === 401 ||
89
+ else if (statusCode === 305 ||
90
+ statusCode === 401 ||
83
91
  statusCode === 402 ||
84
92
  statusCode === 403 ||
85
93
  statusCode === 404 ||
@@ -145,10 +153,17 @@ class HttpAdapter {
145
153
  return;
146
154
  }
147
155
  const statusCode = res.statusCode;
148
- if (statusCode < 300) {
149
- this.acceptResponse(res.headers);
156
+ if (statusCode === 204 || statusCode === 304) {
157
+ this.acceptResponse(res.headers, true);
158
+ }
159
+ else if (statusCode < 300) {
160
+ this.acceptResponse(res.headers, false);
150
161
  }
151
- else if (statusCode < 400) {
162
+ else if (statusCode === 301 ||
163
+ statusCode === 302 ||
164
+ statusCode === 303 ||
165
+ statusCode === 307 ||
166
+ statusCode === 308) {
152
167
  this.redirectResponse(statusCode, res.headers.location);
153
168
  }
154
169
  else if (this.isRetry(statusCode)) {
@@ -220,7 +235,7 @@ class HttpAdapter {
220
235
  this.opts.httpVersion = 1;
221
236
  this.init();
222
237
  }
223
- acceptResponse(headers) {
238
+ acceptResponse(headers, empty = false) {
224
239
  const opts = this.opts;
225
240
  if ('outHeaders' in opts) {
226
241
  opts.outHeaders = headers;
@@ -232,7 +247,7 @@ class HttpAdapter {
232
247
  const enabled = opts.connected?.call(this.client, headers) !== false && !pipeline;
233
248
  const maxBufferSize = opts.maxBufferSize ? (0, types_1.alignSize)(opts.maxBufferSize) : 0;
234
249
  this.contentLength = parseInt(headers['content-length'] || '0');
235
- const updating = opts.progressId !== undefined && !!this.instance.host && this.contentLength > 0;
250
+ const updating = opts.progressId !== undefined && !!this.instance.host && this.contentLength > 0 && !empty;
236
251
  const readTimeout = this.instance.readTimeout;
237
252
  let log = this.state.log, buffer = null, dataLength = 0;
238
253
  this.client.once('readable', () => {
@@ -261,7 +276,7 @@ class HttpAdapter {
261
276
  this.updateProgress(0, 0);
262
277
  }
263
278
  });
264
- if (enabled) {
279
+ if (enabled && !empty) {
265
280
  const encoding = opts.encoding;
266
281
  this.client.on('data', (chunk) => {
267
282
  if (buffer) {
@@ -360,7 +375,7 @@ class HttpAdapter {
360
375
  if (updating) {
361
376
  this.updateProgress(0, this.contentLength);
362
377
  }
363
- if (enabled && this.instance.readExpect === 'always') {
378
+ if (enabled && this.instance.readExpect === 'always' && !empty) {
364
379
  this.terminate("No data received");
365
380
  return;
366
381
  }
@@ -396,6 +411,9 @@ class HttpAdapter {
396
411
  }
397
412
  else if (++this.redirects <= this.redirectLimit) {
398
413
  this.abortResponse();
414
+ if (this.opts.method?.toUpperCase() === 'PUT' && statusCode !== 307 && statusCode !== 308) {
415
+ this.#options.method = 'GET';
416
+ }
399
417
  this.setOpts((0, util_1.fromURL)(this.opts.url, location));
400
418
  this.init();
401
419
  }
package/index.js CHANGED
@@ -301,6 +301,8 @@ function checkEncoding(request, response, statusCode, outStream, contentEncoding
301
301
  case 206:
302
302
  request.emit('error', (0, types_1.errorValue)("Aborted", 'Partial content'));
303
303
  case 204:
304
+ case 205:
305
+ case 304:
304
306
  return;
305
307
  }
306
308
  if (!contentEncoding) {
@@ -491,6 +493,7 @@ function addAria2Proxy(args, protocol, host) {
491
493
  }
492
494
  }
493
495
  const isConstructor = (value) => typeof value === 'function';
496
+ const hasResponse = (value) => value >= 200 && (value < 300 || value === 304);
494
497
  const isDirEnd = (value) => value.endsWith('/') || value.endsWith(path.sep);
495
498
  const trimCharEnd = (value) => value.substring(0, value.length - 1);
496
499
  const configureDns = (family, options) => family === 0 ? options : { family, hints: family === 6 ? dns.V4MAPPED : 0 };
@@ -1860,7 +1863,7 @@ class Request extends module_1 {
1860
1863
  return;
1861
1864
  }
1862
1865
  connected = true;
1863
- if (this.matchStatus(statusCode, url, response, request, options) && statusCode >= 200 && statusCode < 300) {
1866
+ if (this.matchStatus(statusCode, url, response, request, options) && hasResponse(statusCode)) {
1864
1867
  if (emitter = checkEncoding(request, request, statusCode, outStream, response['content-encoding'])) {
1865
1868
  for (const event in listenerMap) {
1866
1869
  const [name, type] = event.split('-');
@@ -1980,7 +1983,7 @@ class Request extends module_1 {
1980
1983
  }, response => {
1981
1984
  const statusCode = response.statusCode;
1982
1985
  const incoming = response.headers;
1983
- if (!expectContinue && this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && statusCode >= 200 && statusCode < 300) {
1986
+ if (!expectContinue && this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && hasResponse(statusCode)) {
1984
1987
  let source = checkEncoding(request, response, statusCode, outStream, incoming['content-encoding']);
1985
1988
  if (source) {
1986
1989
  source.once('finish', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.12.11",
3
+ "version": "0.12.13",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,10 +19,10 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/module": "0.12.11",
23
- "@e-mc/types": "0.12.11",
22
+ "@e-mc/module": "0.12.13",
23
+ "@e-mc/types": "0.12.13",
24
24
  "combined-stream": "^1.0.8",
25
- "js-yaml": "^4.1.0",
25
+ "js-yaml": "^4.1.1",
26
26
  "picomatch": "^4.0.3",
27
27
  "which": "^4.0.0"
28
28
  }