urllib 3.0.1 → 3.0.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.
package/History.md CHANGED
@@ -1,31 +1,17 @@
1
1
 
2
+ 3.0.2 / 2022-07-17
3
+ ==================
4
+
5
+ **others**
6
+ * [[`3bc7461`](http://github.com/node-modules/urllib/commit/3bc74610eba9dfac4b5ab7b1c2e927cafacdaa9f)] - 📦 NEW: Enable Mocking request from undici (#386) (fengmk2 <<fengmk2@gmail.com>>)
7
+ * [[`2ef38b9`](http://github.com/node-modules/urllib/commit/2ef38b9a373428e109a2a813b11cdb5fd8e61446)] - 📖 DOC: Change History (fengmk2 <<fengmk2@gmail.com>>)
8
+
2
9
  3.0.1 / 2022-07-17
3
10
  ==================
4
11
 
5
12
  **others**
6
13
  * [[`a16deb5`](http://github.com/node-modules/urllib/commit/a16deb5923d55d145d29099073d9a3ccde07eeaf)] - 🐛 FIX: should export USER_AGENT (#385) (fengmk2 <<fengmk2@gmail.com>>)
7
14
  * [[`122d4a6`](http://github.com/node-modules/urllib/commit/122d4a6fc98ebe6b59b3c2cf386c180785fb4a5b)] - 📖 DOC: Add Benchmarks result (fengmk2 <<fengmk2@gmail.com>>)
8
- * [[`a8ef220`](http://github.com/node-modules/urllib/commit/a8ef220d2f56d451724cf00e7c105126a0580e61)] - 📦 NEW: Support request and response events (fengmk2 <<fengmk2@gmail.com>>)
9
- * [[`e39b033`](http://github.com/node-modules/urllib/commit/e39b03359bf8d4d582cdf2d042bc13bc4fe5a71a)] - 📦 NEW: Support HttpClient with rejectUnauthorized (fengmk2 <<fengmk2@gmail.com>>)
10
- * [[`885446c`](http://github.com/node-modules/urllib/commit/885446ca86c69cb221b35013062b524ab37e78ac)] - 📦 NEW: Support options.auth (fengmk2 <<fengmk2@gmail.com>>)
11
- * [[`8b9a6ee`](http://github.com/node-modules/urllib/commit/8b9a6ee07b61fba0fdf37bb64c60d3560df808d8)] - 📦 NEW: Support custom lookup and checkAddress (fengmk2 <<fengmk2@gmail.com>>)
12
- * [[`b6fc7e9`](http://github.com/node-modules/urllib/commit/b6fc7e940a50ebf8dec68507ae2487b6ab78be86)] - 📦 NEW: Support options.opaque = object (fengmk2 <<fengmk2@gmail.com>>)
13
- * [[`1485441`](http://github.com/node-modules/urllib/commit/148544132ff39dc15a77a3559da76aa6cb66835c)] - 📦 NEW: Support options.timing = true (fengmk2 <<fengmk2@gmail.com>>)
14
- * [[`3637ee1`](http://github.com/node-modules/urllib/commit/3637ee18bd5272a9ddc922b96104d767697aea55)] - 📦 NEW: Support options.compressed instead of gzip (fengmk2 <<fengmk2@gmail.com>>)
15
- * [[`1715e31`](http://github.com/node-modules/urllib/commit/1715e31ae031cab71f3d49cff687b8bcfce89928)] - 👌 IMPROVE: Support Node.js 14 (fengmk2 <<fengmk2@gmail.com>>)
16
- * [[`13ac861`](http://github.com/node-modules/urllib/commit/13ac8612aad7c8b4a0bde8a315dbdbac617b17e7)] - 📦 NEW: Support auto retry like HttpClient2 (fengmk2 <<fengmk2@gmail.com>>)
17
- * [[`ab4b630`](http://github.com/node-modules/urllib/commit/ab4b630e5c188924a2f5784e4abfc05a4be382ff)] - 👌 IMPROVE: Use brotli instead of deflate (fengmk2 <<fengmk2@gmail.com>>)
18
- * [[`0b55bbe`](http://github.com/node-modules/urllib/commit/0b55bbe339108ddefbb5213e335078ea000f5f52)] - 🤖 TEST: Big stream timeout (fengmk2 <<fengmk2@gmail.com>>)
19
- * [[`d4ac841`](http://github.com/node-modules/urllib/commit/d4ac84157c5b78590dacc4d28df60492a5ee2d7c)] - 📦 NEW: Use request instead of fetch (fengmk2 <<fengmk2@gmail.com>>)
20
- * [[`43eaaa1`](http://github.com/node-modules/urllib/commit/43eaaa187ebc8e1ee795bc26f1940553f40e6875)] - 🐛 FIX: Try to use Readable first (fengmk2 <<fengmk2@gmail.com>>)
21
- * [[`9c9df8d`](http://github.com/node-modules/urllib/commit/9c9df8dca57c2a3be8717d27cb7d6fff3bd71312)] - 🐛 FIX: Dont parse empty data to json (fengmk2 <<fengmk2@gmail.com>>)
22
- * [[`e6025df`](http://github.com/node-modules/urllib/commit/e6025df5aae8d237b0fb0d482f7a3d8ecb340d8b)] - 🤖 TEST: Error cases for stream and writeStream (fengmk2 <<fengmk2@gmail.com>>)
23
- * [[`0fbeffc`](http://github.com/node-modules/urllib/commit/0fbeffc9181ec8d8accc95672580f42b9bdfd9d4)] - 📦 NEW: Support options.streaming = true (fengmk2 <<fengmk2@gmail.com>>)
24
- * [[`7d8a700`](http://github.com/node-modules/urllib/commit/7d8a7007f7b64e47b4adc78a861dcff53fad6a10)] - 📦 NEW: Support fixJSONCtlChars (fengmk2 <<fengmk2@gmail.com>>)
25
- * [[`85f915a`](http://github.com/node-modules/urllib/commit/85f915a878388cba582bc9f7e0f2c51158b53fa3)] - 📦 NEW: TS compiler both Commonjs and ESM support (fengmk2 <<fengmk2@gmail.com>>)
26
- * [[`d18a3d4`](http://github.com/node-modules/urllib/commit/d18a3d492b3f7943a1f89449ebdeb46c52b83eaf)] - 📦 NEW: Support upload file by args.files (fengmk2 <<fengmk2@gmail.com>>)
27
- * [[`c5a284f`](http://github.com/node-modules/urllib/commit/c5a284fda3e88b309150f93aedae10bb12f61ab3)] - 🤖 TEST: Use jest and ts (fengmk2 <<fengmk2@gmail.com>>)
28
- * [[`8bbbb18`](http://github.com/node-modules/urllib/commit/8bbbb184dd26e123dcd67181385186e076c1f1b6)] - 📦 NEW: [BREAKING] Refactor impl base on undici (fengmk2 <<fengmk2@gmail.com>>)
29
15
 
30
16
  3.0.0 / 2022-07-16
31
17
  ==================
package/README.md CHANGED
@@ -253,6 +253,34 @@ Response is normal object, it contains:
253
253
  NODE_DEBUG=urllib npm test
254
254
  ```
255
255
 
256
+ ## Mocking Request
257
+
258
+ export from [undici](https://undici.nodejs.org/#/docs/best-practices/mocking-request)
259
+
260
+ ```ts
261
+ import { strict as assert } from 'assert';
262
+ import { MockAgent, setGlobalDispatcher, request } from 'urllib';
263
+
264
+ const mockAgent = new MockAgent();
265
+ setGlobalDispatcher(mockAgent);
266
+
267
+ const mockPool = mockAgent.get('http://localhost:7001');
268
+
269
+ mockPool.intercept({
270
+ path: '/foo',
271
+ method: 'POST',
272
+ }).reply(400, {
273
+ message: 'mock 400 bad request',
274
+ });
275
+
276
+ const response = await request('http://localhost:7001/foo', {
277
+ method: 'POST',
278
+ dataType: 'json',
279
+ });
280
+ assert.equal(response.status, 400);
281
+ assert.deepEqual(response.data, { message: 'mock 400 bad request' });
282
+ ```
283
+
256
284
  ## Benchmarks
257
285
 
258
286
  Fork [undici benchmarks script](https://github.com/fengmk2/undici/blob/urllib-benchmark/benchmarks/benchmark.js)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "urllib",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "publishConfig": {
5
5
  "tag": "latest"
6
6
  },
@@ -1,6 +1,7 @@
1
1
  import { RequestOptions, RequestURL } from './Request';
2
2
  export declare function request(url: RequestURL, options?: RequestOptions): Promise<import("./Response").HttpClientResponse>;
3
3
  export { HttpClient, HEADER_USER_AGENT as USER_AGENT } from './HttpClient';
4
+ export { MockAgent, setGlobalDispatcher } from 'undici';
4
5
  declare const _default: {
5
6
  request: typeof request;
6
7
  USER_AGENT: string;
package/src/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USER_AGENT = exports.HttpClient = exports.request = void 0;
3
+ exports.setGlobalDispatcher = exports.MockAgent = exports.USER_AGENT = exports.HttpClient = exports.request = void 0;
4
4
  const HttpClient_1 = require("./HttpClient");
5
5
  let httpclient;
6
6
  async function request(url, options) {
@@ -13,6 +13,9 @@ exports.request = request;
13
13
  var HttpClient_2 = require("./HttpClient");
14
14
  Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_2.HttpClient; } });
15
15
  Object.defineProperty(exports, "USER_AGENT", { enumerable: true, get: function () { return HttpClient_2.HEADER_USER_AGENT; } });
16
+ var undici_1 = require("undici");
17
+ Object.defineProperty(exports, "MockAgent", { enumerable: true, get: function () { return undici_1.MockAgent; } });
18
+ Object.defineProperty(exports, "setGlobalDispatcher", { enumerable: true, get: function () { return undici_1.setGlobalDispatcher; } });
16
19
  exports.default = {
17
20
  request,
18
21
  USER_AGENT: HttpClient_1.HEADER_USER_AGENT,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA6D;AAG7D,IAAI,UAAsB,CAAC;AACpB,KAAK,UAAU,OAAO,CAAC,GAAe,EAAE,OAAwB;IACrE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;KAC/B;IACD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AALD,0BAKC;AAED,2CAA2E;AAAlE,wGAAA,UAAU,OAAA;AAAE,wGAAA,iBAAiB,OAAc;AAEpD,kBAAe;IACb,OAAO;IACP,UAAU,EAAE,8BAAiB;CAC9B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA6D;AAG7D,IAAI,UAAsB,CAAC;AACpB,KAAK,UAAU,OAAO,CAAC,GAAe,EAAE,OAAwB;IACrE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;KAC/B;IACD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AALD,0BAKC;AAED,2CAA2E;AAAlE,wGAAA,UAAU,OAAA;AAAE,wGAAA,iBAAiB,OAAc;AACpD,iCAAwD;AAA/C,mGAAA,SAAS,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AAEvC,kBAAe;IACb,OAAO;IACP,UAAU,EAAE,8BAAiB;CAC9B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { RequestOptions, RequestURL } from './Request';
2
2
  export declare function request(url: RequestURL, options?: RequestOptions): Promise<import("./Response").HttpClientResponse>;
3
3
  export { HttpClient, HEADER_USER_AGENT as USER_AGENT } from './HttpClient';
4
+ export { MockAgent, setGlobalDispatcher } from 'undici';
4
5
  declare const _default: {
5
6
  request: typeof request;
6
7
  USER_AGENT: string;
package/src/esm/index.js CHANGED
@@ -7,6 +7,7 @@ export async function request(url, options) {
7
7
  return await httpclient.request(url, options);
8
8
  }
9
9
  export { HttpClient, HEADER_USER_AGENT as USER_AGENT } from './HttpClient.js';
10
+ export { MockAgent, setGlobalDispatcher } from 'undici';
10
11
  export default {
11
12
  request,
12
13
  USER_AGENT: HEADER_USER_AGENT,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG7D,IAAI,UAAsB,CAAC;AAC3B,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAe,EAAE,OAAwB;IACrE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;KAC/B;IACD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAe;IACb,OAAO;IACP,UAAU,EAAE,iBAAiB;CAC9B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG7D,IAAI,UAAsB,CAAC;AAC3B,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAe,EAAE,OAAwB;IACrE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;KAC/B;IACD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAExD,eAAe;IACb,OAAO;IACP,UAAU,EAAE,iBAAiB;CAC9B,CAAC"}
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export async function request(url: RequestURL, options?: RequestOptions) {
10
10
  }
11
11
 
12
12
  export { HttpClient, HEADER_USER_AGENT as USER_AGENT } from './HttpClient';
13
+ export { MockAgent, setGlobalDispatcher } from 'undici';
13
14
 
14
15
  export default {
15
16
  request,