Initial commit
This commit is contained in:
+203
@@ -0,0 +1,203 @@
|
||||
# Changelog
|
||||
|
||||
### [7.1.3](https://www.github.com/googleapis/teeny-request/compare/v7.1.2...v7.1.3) (2021-09-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency http-proxy-agent to v5 ([#253](https://www.github.com/googleapis/teeny-request/issues/253)) ([c84dff4](https://www.github.com/googleapis/teeny-request/commit/c84dff45e4a0e71fc5205838dae51f57f3139c06))
|
||||
|
||||
### [7.1.2](https://www.github.com/googleapis/teeny-request/compare/v7.1.1...v7.1.2) (2021-09-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **build:** set default branch to main ([#247](https://www.github.com/googleapis/teeny-request/issues/247)) ([db3126d](https://www.github.com/googleapis/teeny-request/commit/db3126df77bc7e6cebb7d092001bbd3a444207d6))
|
||||
|
||||
### [7.1.1](https://www.github.com/googleapis/teeny-request/compare/v7.1.0...v7.1.1) (2021-06-30)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* throw error if missing uri or url ([#239](https://www.github.com/googleapis/teeny-request/issues/239)) ([4d770e3](https://www.github.com/googleapis/teeny-request/commit/4d770e3b89254c4cec30c422cdcdad257500c9cc))
|
||||
|
||||
## [7.1.0](https://www.github.com/googleapis/teeny-request/compare/v7.0.1...v7.1.0) (2021-05-19)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add `gcf-owl-bot[bot]` to `ignoreAuthors` ([#224](https://www.github.com/googleapis/teeny-request/issues/224)) ([3e7424f](https://www.github.com/googleapis/teeny-request/commit/3e7424fb63f0c0dca3606d6e1fc2f294f9d86ba5))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Buffer is allow as body without encoding to string ([#223](https://www.github.com/googleapis/teeny-request/issues/223)) ([d9bcdc3](https://www.github.com/googleapis/teeny-request/commit/d9bcdc36a60074fd78718ea8f7c4745d640e3b4f))
|
||||
|
||||
### [7.0.1](https://www.github.com/googleapis/teeny-request/compare/v7.0.0...v7.0.1) (2020-09-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update node-fetch to 2.6.1 ([#200](https://www.github.com/googleapis/teeny-request/issues/200)) ([8958a78](https://www.github.com/googleapis/teeny-request/commit/8958a78b117e5610f3ccf121ba1d650dbe9739f8))
|
||||
|
||||
## [7.0.0](https://www.github.com/googleapis/teeny-request/compare/v6.0.3...v7.0.0) (2020-06-01)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* dropping support for Node.js 8.x
|
||||
|
||||
### Features
|
||||
|
||||
* pass agent options when using agent pool config ([#149](https://www.github.com/googleapis/teeny-request/issues/149)) ([38ece79](https://www.github.com/googleapis/teeny-request/commit/38ece79151b667ec1a72ec50b1c7a58258924794))
|
||||
* warn on too many concurrent requests ([#165](https://www.github.com/googleapis/teeny-request/issues/165)) ([88ff2d0](https://www.github.com/googleapis/teeny-request/commit/88ff2d0d8e0fc25a4219ef5625b8de353ed4aa29))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* apache license URL ([#468](https://www.github.com/googleapis/teeny-request/issues/468)) ([#156](https://www.github.com/googleapis/teeny-request/issues/156)) ([01ac7bd](https://www.github.com/googleapis/teeny-request/commit/01ac7bd01e870796fd15355e079649633d5d5983))
|
||||
* update template files for Node.js libraries ([#152](https://www.github.com/googleapis/teeny-request/issues/152)) ([89833c3](https://www.github.com/googleapis/teeny-request/commit/89833c3c3e8afea04c85a60811f122c5a6d37e48))
|
||||
* **deps:** update dependency uuid to v8 ([#164](https://www.github.com/googleapis/teeny-request/issues/164)) ([2ab8155](https://www.github.com/googleapis/teeny-request/commit/2ab81550aeb8ca914516ff4ac20ebbb7b3d73fa5))
|
||||
|
||||
|
||||
### Build System
|
||||
|
||||
* drop support for node.js 8.x ([#159](https://www.github.com/googleapis/teeny-request/issues/159)) ([d87aa73](https://www.github.com/googleapis/teeny-request/commit/d87aa73d3fafbdc013b03b7629a41decda6da98a))
|
||||
|
||||
### [6.0.3](https://www.github.com/googleapis/teeny-request/compare/v6.0.2...v6.0.3) (2020-03-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency uuid to v7 ([#134](https://www.github.com/googleapis/teeny-request/issues/134)) ([97817bf](https://www.github.com/googleapis/teeny-request/commit/97817bfb12396f620b2e280dcdc8965c4815abb5))
|
||||
|
||||
### [6.0.2](https://www.github.com/googleapis/teeny-request/compare/v6.0.1...v6.0.2) (2020-02-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency https-proxy-agent to v5 ([#128](https://www.github.com/googleapis/teeny-request/issues/128)) ([5dcef3f](https://www.github.com/googleapis/teeny-request/commit/5dcef3f5883b24a1092def38004074d04e37e241))
|
||||
|
||||
### [6.0.1](https://www.github.com/googleapis/teeny-request/compare/v6.0.0...v6.0.1) (2020-01-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency http-proxy-agent to v4 ([#121](https://www.github.com/googleapis/teeny-request/issues/121)) ([7caabcf](https://www.github.com/googleapis/teeny-request/commit/7caabcf154d8cf0848e443ce2cd4fbfae913ca41))
|
||||
|
||||
## [6.0.0](https://www.github.com/googleapis/teeny-request/compare/v5.3.3...v6.0.0) (2020-01-11)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* remove console log and throw instead (#107)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove console log and throw instead ([#107](https://www.github.com/googleapis/teeny-request/issues/107)) ([965beaa](https://www.github.com/googleapis/teeny-request/commit/965beaae17f0273992c9856ebf79b6f1befc59fe))
|
||||
|
||||
### [5.3.3](https://www.github.com/googleapis/teeny-request/compare/v5.3.2...v5.3.3) (2019-12-15)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency http-proxy-agent to v3 ([#104](https://www.github.com/googleapis/teeny-request/issues/104)) ([35a47d8](https://www.github.com/googleapis/teeny-request/commit/35a47d83adf92b16eab3fce52deae0e3c1353aa6))
|
||||
* **deps:** update dependency https-proxy-agent to v4 ([#105](https://www.github.com/googleapis/teeny-request/issues/105)) ([26b67af](https://www.github.com/googleapis/teeny-request/commit/26b67afcb084ce1b99a62ecc55050d6f8f8aaee4))
|
||||
* **docs:** add jsdoc-region-tag plugin ([#98](https://www.github.com/googleapis/teeny-request/issues/98)) ([8f3c35a](https://www.github.com/googleapis/teeny-request/commit/8f3c35aee711a1262ffa7c058eb1b9f18204b80e))
|
||||
|
||||
### [5.3.2](https://www.github.com/googleapis/teeny-request/compare/v5.3.1...v5.3.2) (2019-12-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** pin TypeScript below 3.7.0 ([#102](https://www.github.com/googleapis/teeny-request/issues/102)) ([c0b81e6](https://www.github.com/googleapis/teeny-request/commit/c0b81e6e7c1bb7e4a3e823c2e41692bc8ede0218))
|
||||
|
||||
### [5.3.1](https://www.github.com/googleapis/teeny-request/compare/v5.3.0...v5.3.1) (2019-10-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* correctly set compress/gzip option when false ([#95](https://www.github.com/googleapis/teeny-request/issues/95)) ([72ef307](https://www.github.com/googleapis/teeny-request/commit/72ef307364de542af3ef8581572b1897fca2bcf4))
|
||||
|
||||
## [5.3.0](https://www.github.com/googleapis/teeny-request/compare/v5.2.1...v5.3.0) (2019-10-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** update dependency https-proxy-agent to v3 ([#89](https://www.github.com/googleapis/teeny-request/issues/89)) ([dfd52cc](https://www.github.com/googleapis/teeny-request/commit/dfd52cc))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* agent pooling ([#86](https://www.github.com/googleapis/teeny-request/issues/86)) ([b182f51](https://www.github.com/googleapis/teeny-request/commit/b182f51))
|
||||
|
||||
### [5.2.1](https://www.github.com/googleapis/teeny-request/compare/v5.2.0...v5.2.1) (2019-08-14)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **types:** make types less strict for method ([#76](https://www.github.com/googleapis/teeny-request/issues/76)) ([9f07e98](https://www.github.com/googleapis/teeny-request/commit/9f07e98))
|
||||
|
||||
## [5.2.0](https://www.github.com/googleapis/teeny-request/compare/v5.1.3...v5.2.0) (2019-08-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* if scheme is http:// use an HTTP agent ([#75](https://www.github.com/googleapis/teeny-request/issues/75)) ([abdf846](https://www.github.com/googleapis/teeny-request/commit/abdf846))
|
||||
* remove unused logging ([#71](https://www.github.com/googleapis/teeny-request/issues/71)) ([4cb4967](https://www.github.com/googleapis/teeny-request/commit/4cb4967))
|
||||
* undefined headers breaks compatibility with auth ([#66](https://www.github.com/googleapis/teeny-request/issues/66)) ([12901a0](https://www.github.com/googleapis/teeny-request/commit/12901a0))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support lazy-reading from response stream ([#74](https://www.github.com/googleapis/teeny-request/issues/74)) ([f6db420](https://www.github.com/googleapis/teeny-request/commit/f6db420))
|
||||
* support reading from the request stream ([#67](https://www.github.com/googleapis/teeny-request/issues/67)) ([ae23054](https://www.github.com/googleapis/teeny-request/commit/ae23054))
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* do not pipe fetch response into user stream ([#72](https://www.github.com/googleapis/teeny-request/issues/72)) ([6ec812e](https://www.github.com/googleapis/teeny-request/commit/6ec812e))
|
||||
|
||||
### [5.1.3](https://www.github.com/googleapis/teeny-request/compare/v5.1.2...v5.1.3) (2019-08-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* duplex stream does not implement methods like _read ([#64](https://www.github.com/googleapis/teeny-request/issues/64)) ([22ee26c](https://www.github.com/googleapis/teeny-request/commit/22ee26c))
|
||||
|
||||
### [5.1.2](https://www.github.com/googleapis/teeny-request/compare/v5.1.1...v5.1.2) (2019-08-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **types:** expand method and header types ([#61](https://www.github.com/googleapis/teeny-request/issues/61)) ([c04d2f1](https://www.github.com/googleapis/teeny-request/commit/c04d2f1))
|
||||
|
||||
### [5.1.1](https://www.github.com/googleapis/teeny-request/compare/v5.1.0...v5.1.1) (2019-07-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* support lowercase proxy env vars ([#56](https://www.github.com/googleapis/teeny-request/issues/56)) ([0b3e433](https://www.github.com/googleapis/teeny-request/commit/0b3e433))
|
||||
|
||||
## [5.1.0](https://www.github.com/googleapis/teeny-request/compare/v5.0.0...v5.1.0) (2019-07-19)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support forever option ([#54](https://www.github.com/googleapis/teeny-request/issues/54)) ([746d70e](https://www.github.com/googleapis/teeny-request/commit/746d70e))
|
||||
|
||||
## [5.0.0](https://www.github.com/googleapis/teeny-request/compare/v4.0.0...v5.0.0) (2019-07-15)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* this is our first release since moving into googleapis org; in the theme of "better safe than sorry" we're releasing as 5.0.0.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* export types independent of @types/request ([#44](https://www.github.com/googleapis/teeny-request/issues/44)) ([fbe2b77](https://www.github.com/googleapis/teeny-request/commit/fbe2b77))
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* revert 4.0.0 release in favor of 5.0.0 release ([#52](https://www.github.com/googleapis/teeny-request/issues/52)) ([f24499e](https://www.github.com/googleapis/teeny-request/commit/f24499e))
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
[](https://travis-ci.org/googleapis/teeny-request)
|
||||
|
||||
# teeny-request
|
||||
|
||||
Like `request`, but much smaller - and with less options. Uses `node-fetch` under the hood.
|
||||
Pop it in where you would use `request`. Improves load and parse time of modules.
|
||||
|
||||
```js
|
||||
const request = require('teeny-request').teenyRequest;
|
||||
|
||||
request({uri: 'http://ip.jsontest.com/'}, function (error, response, body) {
|
||||
console.log('error:', error); // Print the error if one occurred
|
||||
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
|
||||
console.log('body:', body); // Print the JSON.
|
||||
});
|
||||
```
|
||||
|
||||
For TypeScript, you can use `@types/request`.
|
||||
|
||||
```ts
|
||||
import {teenyRequest as request} from 'teeny-request';
|
||||
import r as * from 'request'; // Only for type declarations
|
||||
|
||||
request({uri: 'http://ip.jsontest.com/'}, (error: any, response: r.Response, body: any) => {
|
||||
console.log('error:', error); // Print the error if one occurred
|
||||
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
|
||||
console.log('body:', body); // Print the JSON.
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
|
||||
## teenyRequest(options, callback)
|
||||
|
||||
Options are limited to the following
|
||||
|
||||
* uri
|
||||
* method, default GET
|
||||
* headers
|
||||
* json
|
||||
* qs
|
||||
* useQuerystring
|
||||
* timeout in ms
|
||||
* gzip
|
||||
* proxy
|
||||
|
||||
```ts
|
||||
request({uri:'http://service.com/upload', method:'POST', json: {key:'value'}}, function(err,httpResponse,body){ /* ... */ })
|
||||
```
|
||||
|
||||
The callback argument gets 3 arguments:
|
||||
|
||||
* An error when applicable (usually from http.ClientRequest object)
|
||||
* An response object with statusCode, a statusMessage, and a body
|
||||
* The third is the response body (JSON object)
|
||||
|
||||
## defaults(options)
|
||||
|
||||
Set default options for every `teenyRequest` call.
|
||||
|
||||
```ts
|
||||
let defaultRequest = teenyRequest.defaults({timeout: 60000});
|
||||
defaultRequest({uri: 'http://ip.jsontest.com/'}, function (error, response, body) {
|
||||
assert.ifError(error);
|
||||
assert.strictEqual(response.statusCode, 200);
|
||||
console.log(body.ip);
|
||||
assert.notEqual(body.ip, null);
|
||||
|
||||
done();
|
||||
});
|
||||
```
|
||||
|
||||
## Proxy environment variables
|
||||
If environment variables `HTTP_PROXY` or `HTTPS_PROXY` are set, they are respected. `NO_PROXY` is currently not implemented.
|
||||
|
||||
## Building with Webpack 4+
|
||||
Since 4.0.0, Webpack uses `javascript/esm` for `.mjs` files which handles ESM more strictly compared to `javascript/auto`. If you get the error `Can't import the named export 'PassThrough' from non EcmaScript module`, please add the following to your Webpack config:
|
||||
|
||||
```js
|
||||
{
|
||||
test: /\.mjs$/,
|
||||
type: 'javascript/auto',
|
||||
},
|
||||
```
|
||||
|
||||
## Motivation
|
||||
`request` has a ton of options and features and is accordingly large. Requiering a module incurs load and parse time. For
|
||||
`request`, that is around 600ms.
|
||||
|
||||

|
||||
|
||||
`teeny-request` doesn't have any of the bells and whistles that `request` has, but is so much faster to load. If startup time is an issue and you don't need much beyong a basic GET and POST, you can use `teeny-request`.
|
||||
|
||||
## Thanks
|
||||
Special thanks to [billyjacobson](https://github.com/billyjacobson) for suggesting the name. Please report all bugs to them. Just kidding. Please open issues.
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export interface TeenyStatisticsOptions {
|
||||
/**
|
||||
* A positive number representing when to issue a warning about the number
|
||||
* of concurrent requests using teeny-request.
|
||||
* Set to 0 to disable this warning.
|
||||
* Corresponds to the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment
|
||||
* variable.
|
||||
*/
|
||||
concurrentRequests?: number;
|
||||
}
|
||||
declare type TeenyStatisticsConfig = Required<TeenyStatisticsOptions>;
|
||||
/**
|
||||
* TeenyStatisticsCounters is distinct from TeenyStatisticsOptions:
|
||||
* Used when dumping current counters and other internal metrics.
|
||||
*/
|
||||
export interface TeenyStatisticsCounters {
|
||||
concurrentRequests: number;
|
||||
}
|
||||
/**
|
||||
* @class TeenyStatisticsWarning
|
||||
* @extends Error
|
||||
* @description While an error, is used for emitting warnings when
|
||||
* meeting certain configured thresholds.
|
||||
* @see process.emitWarning
|
||||
*/
|
||||
export declare class TeenyStatisticsWarning extends Error {
|
||||
static readonly CONCURRENT_REQUESTS = "ConcurrentRequestsExceededWarning";
|
||||
threshold: number;
|
||||
type: string;
|
||||
value: number;
|
||||
/**
|
||||
* @param {string} message
|
||||
*/
|
||||
constructor(message: string);
|
||||
}
|
||||
/**
|
||||
* @class TeenyStatistics
|
||||
* @description Maintain various statistics internal to teeny-request. Tracking
|
||||
* is not automatic and must be instrumented within teeny-request.
|
||||
*/
|
||||
export declare class TeenyStatistics {
|
||||
/**
|
||||
* @description A default threshold representing when to warn about excessive
|
||||
* in-flight/concurrent requests.
|
||||
* @type {number}
|
||||
* @static
|
||||
* @readonly
|
||||
* @default 5000
|
||||
*/
|
||||
static readonly DEFAULT_WARN_CONCURRENT_REQUESTS = 5000;
|
||||
/**
|
||||
* @type {TeenyStatisticsConfig}
|
||||
* @private
|
||||
*/
|
||||
private _options;
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
* @default 0
|
||||
*/
|
||||
private _concurrentRequests;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
* @default false
|
||||
*/
|
||||
private _didConcurrentRequestWarn;
|
||||
/**
|
||||
* @param {TeenyStatisticsOptions} [opts]
|
||||
*/
|
||||
constructor(opts?: TeenyStatisticsOptions);
|
||||
/**
|
||||
* Returns a copy of the current options.
|
||||
* @return {TeenyStatisticsOptions}
|
||||
*/
|
||||
getOptions(): TeenyStatisticsOptions;
|
||||
/**
|
||||
* Change configured statistics options. This will not preserve unspecified
|
||||
* options that were previously specified, i.e. this is a reset of options.
|
||||
* @param {TeenyStatisticsOptions} [opts]
|
||||
* @returns {TeenyStatisticsConfig} The previous options.
|
||||
* @see _prepareOptions
|
||||
*/
|
||||
setOptions(opts?: TeenyStatisticsOptions): TeenyStatisticsConfig;
|
||||
/**
|
||||
* @readonly
|
||||
* @return {TeenyStatisticsCounters}
|
||||
*/
|
||||
get counters(): TeenyStatisticsCounters;
|
||||
/**
|
||||
* @description Should call this right before making a request.
|
||||
*/
|
||||
requestStarting(): void;
|
||||
/**
|
||||
* @description When using `requestStarting`, call this after the request
|
||||
* has finished.
|
||||
*/
|
||||
requestFinished(): void;
|
||||
/**
|
||||
* Configuration Precedence:
|
||||
* 1. Dependency inversion via defined option.
|
||||
* 2. Global numeric environment variable.
|
||||
* 3. Built-in default.
|
||||
* This will not preserve unspecified options previously specified.
|
||||
* @param {TeenyStatisticsOptions} [opts]
|
||||
* @returns {TeenyStatisticsOptions}
|
||||
* @private
|
||||
*/
|
||||
private static _prepareOptions;
|
||||
}
|
||||
export {};
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TeenyStatistics = exports.TeenyStatisticsWarning = void 0;
|
||||
/**
|
||||
* @class TeenyStatisticsWarning
|
||||
* @extends Error
|
||||
* @description While an error, is used for emitting warnings when
|
||||
* meeting certain configured thresholds.
|
||||
* @see process.emitWarning
|
||||
*/
|
||||
class TeenyStatisticsWarning extends Error {
|
||||
/**
|
||||
* @param {string} message
|
||||
*/
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.threshold = 0;
|
||||
this.type = '';
|
||||
this.value = 0;
|
||||
this.name = this.constructor.name;
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
exports.TeenyStatisticsWarning = TeenyStatisticsWarning;
|
||||
TeenyStatisticsWarning.CONCURRENT_REQUESTS = 'ConcurrentRequestsExceededWarning';
|
||||
/**
|
||||
* @class TeenyStatistics
|
||||
* @description Maintain various statistics internal to teeny-request. Tracking
|
||||
* is not automatic and must be instrumented within teeny-request.
|
||||
*/
|
||||
class TeenyStatistics {
|
||||
/**
|
||||
* @param {TeenyStatisticsOptions} [opts]
|
||||
*/
|
||||
constructor(opts) {
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
* @default 0
|
||||
*/
|
||||
this._concurrentRequests = 0;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
* @default false
|
||||
*/
|
||||
this._didConcurrentRequestWarn = false;
|
||||
this._options = TeenyStatistics._prepareOptions(opts);
|
||||
}
|
||||
/**
|
||||
* Returns a copy of the current options.
|
||||
* @return {TeenyStatisticsOptions}
|
||||
*/
|
||||
getOptions() {
|
||||
return Object.assign({}, this._options);
|
||||
}
|
||||
/**
|
||||
* Change configured statistics options. This will not preserve unspecified
|
||||
* options that were previously specified, i.e. this is a reset of options.
|
||||
* @param {TeenyStatisticsOptions} [opts]
|
||||
* @returns {TeenyStatisticsConfig} The previous options.
|
||||
* @see _prepareOptions
|
||||
*/
|
||||
setOptions(opts) {
|
||||
const oldOpts = this._options;
|
||||
this._options = TeenyStatistics._prepareOptions(opts);
|
||||
return oldOpts;
|
||||
}
|
||||
/**
|
||||
* @readonly
|
||||
* @return {TeenyStatisticsCounters}
|
||||
*/
|
||||
get counters() {
|
||||
return {
|
||||
concurrentRequests: this._concurrentRequests,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @description Should call this right before making a request.
|
||||
*/
|
||||
requestStarting() {
|
||||
this._concurrentRequests++;
|
||||
if (this._options.concurrentRequests > 0 &&
|
||||
this._concurrentRequests >= this._options.concurrentRequests &&
|
||||
!this._didConcurrentRequestWarn) {
|
||||
this._didConcurrentRequestWarn = true;
|
||||
const warning = new TeenyStatisticsWarning('Possible excessive concurrent requests detected. ' +
|
||||
this._concurrentRequests +
|
||||
' requests in-flight, which exceeds the configured threshold of ' +
|
||||
this._options.concurrentRequests +
|
||||
'. Use the TEENY_REQUEST_WARN_CONCURRENT_REQUESTS environment ' +
|
||||
'variable or the concurrentRequests option of teeny-request to ' +
|
||||
'increase or disable (0) this warning.');
|
||||
warning.type = TeenyStatisticsWarning.CONCURRENT_REQUESTS;
|
||||
warning.value = this._concurrentRequests;
|
||||
warning.threshold = this._options.concurrentRequests;
|
||||
process.emitWarning(warning);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description When using `requestStarting`, call this after the request
|
||||
* has finished.
|
||||
*/
|
||||
requestFinished() {
|
||||
// TODO negative?
|
||||
this._concurrentRequests--;
|
||||
}
|
||||
/**
|
||||
* Configuration Precedence:
|
||||
* 1. Dependency inversion via defined option.
|
||||
* 2. Global numeric environment variable.
|
||||
* 3. Built-in default.
|
||||
* This will not preserve unspecified options previously specified.
|
||||
* @param {TeenyStatisticsOptions} [opts]
|
||||
* @returns {TeenyStatisticsOptions}
|
||||
* @private
|
||||
*/
|
||||
static _prepareOptions({ concurrentRequests: diConcurrentRequests, } = {}) {
|
||||
let concurrentRequests = this.DEFAULT_WARN_CONCURRENT_REQUESTS;
|
||||
const envConcurrentRequests = Number(process.env.TEENY_REQUEST_WARN_CONCURRENT_REQUESTS);
|
||||
if (diConcurrentRequests !== undefined) {
|
||||
concurrentRequests = diConcurrentRequests;
|
||||
}
|
||||
else if (!Number.isNaN(envConcurrentRequests)) {
|
||||
concurrentRequests = envConcurrentRequests;
|
||||
}
|
||||
return { concurrentRequests };
|
||||
}
|
||||
}
|
||||
exports.TeenyStatistics = TeenyStatistics;
|
||||
/**
|
||||
* @description A default threshold representing when to warn about excessive
|
||||
* in-flight/concurrent requests.
|
||||
* @type {number}
|
||||
* @static
|
||||
* @readonly
|
||||
* @default 5000
|
||||
*/
|
||||
TeenyStatistics.DEFAULT_WARN_CONCURRENT_REQUESTS = 5000;
|
||||
//# sourceMappingURL=TeenyStatistics.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"TeenyStatistics.js","sourceRoot":"","sources":["../../src/TeenyStatistics.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAuBH;;;;;;GAMG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAO/C;;OAEG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QARV,cAAS,GAAG,CAAC,CAAC;QACd,SAAI,GAAG,EAAE,CAAC;QACV,UAAK,GAAG,CAAC,CAAC;QAOf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;;AAdH,wDAeC;AAdiB,0CAAmB,GAAG,mCAAmC,CAAC;AAgB5E;;;;GAIG;AACH,MAAa,eAAe;IA+B1B;;OAEG;IACH,YAAY,IAA6B;QAjBzC;;;;WAIG;QACK,wBAAmB,GAAG,CAAC,CAAC;QAEhC;;;;WAIG;QACK,8BAAyB,GAAG,KAAK,CAAC;QAMxC,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,IAA6B;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO;YACL,kBAAkB,EAAE,IAAI,CAAC,mBAAmB;SAC7C,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAE3B,IACE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,CAAC;YACpC,IAAI,CAAC,mBAAmB,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB;YAC5D,CAAC,IAAI,CAAC,yBAAyB,EAC/B;YACA,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;YACtC,MAAM,OAAO,GAAG,IAAI,sBAAsB,CACxC,mDAAmD;gBACjD,IAAI,CAAC,mBAAmB;gBACxB,iEAAiE;gBACjE,IAAI,CAAC,QAAQ,CAAC,kBAAkB;gBAChC,+DAA+D;gBAC/D,gEAAgE;gBAChE,uCAAuC,CAC1C,CAAC;YACF,OAAO,CAAC,IAAI,GAAG,sBAAsB,CAAC,mBAAmB,CAAC;YAC1D,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC;YACzC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YACrD,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;SAC9B;IACH,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,iBAAiB;QACjB,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;;OASG;IACK,MAAM,CAAC,eAAe,CAAC,EAC7B,kBAAkB,EAAE,oBAAoB,MACd,EAAE;QAC5B,IAAI,kBAAkB,GAAG,IAAI,CAAC,gCAAgC,CAAC;QAE/D,MAAM,qBAAqB,GAAG,MAAM,CAClC,OAAO,CAAC,GAAG,CAAC,sCAAsC,CACnD,CAAC;QACF,IAAI,oBAAoB,KAAK,SAAS,EAAE;YACtC,kBAAkB,GAAG,oBAAoB,CAAC;SAC3C;aAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE;YAC/C,kBAAkB,GAAG,qBAAqB,CAAC;SAC5C;QAED,OAAO,EAAC,kBAAkB,EAAC,CAAC;IAC9B,CAAC;;AAnIH,0CAoIC;AAnIC;;;;;;;GAOG;AACa,gDAAgC,GAAG,IAAI,CAAC"}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import { Agent as HTTPAgent } from 'http';
|
||||
import { Agent as HTTPSAgent } from 'https';
|
||||
import { Options } from './';
|
||||
export declare const pool: Map<string, HTTPAgent>;
|
||||
export declare type HttpAnyAgent = HTTPAgent | HTTPSAgent;
|
||||
/**
|
||||
* Returns a custom request Agent if one is found, otherwise returns undefined
|
||||
* which will result in the global http(s) Agent being used.
|
||||
* @private
|
||||
* @param {string} uri The request uri
|
||||
* @param {Options} reqOpts The request options
|
||||
* @returns {HttpAnyAgent|undefined}
|
||||
*/
|
||||
export declare function getAgent(uri: string, reqOpts: Options): HttpAnyAgent | undefined;
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getAgent = exports.pool = void 0;
|
||||
const http_1 = require("http");
|
||||
const https_1 = require("https");
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
const url_1 = require("url");
|
||||
exports.pool = new Map();
|
||||
/**
|
||||
* Returns a custom request Agent if one is found, otherwise returns undefined
|
||||
* which will result in the global http(s) Agent being used.
|
||||
* @private
|
||||
* @param {string} uri The request uri
|
||||
* @param {Options} reqOpts The request options
|
||||
* @returns {HttpAnyAgent|undefined}
|
||||
*/
|
||||
function getAgent(uri, reqOpts) {
|
||||
const isHttp = uri.startsWith('http://');
|
||||
const proxy = reqOpts.proxy ||
|
||||
process.env.HTTP_PROXY ||
|
||||
process.env.http_proxy ||
|
||||
process.env.HTTPS_PROXY ||
|
||||
process.env.https_proxy;
|
||||
const poolOptions = Object.assign({}, reqOpts.pool);
|
||||
if (proxy) {
|
||||
// tslint:disable-next-line variable-name
|
||||
const Agent = isHttp
|
||||
? require('http-proxy-agent')
|
||||
: require('https-proxy-agent');
|
||||
const proxyOpts = { ...url_1.parse(proxy), ...poolOptions };
|
||||
return new Agent(proxyOpts);
|
||||
}
|
||||
let key = isHttp ? 'http' : 'https';
|
||||
if (reqOpts.forever) {
|
||||
key += ':forever';
|
||||
if (!exports.pool.has(key)) {
|
||||
// tslint:disable-next-line variable-name
|
||||
const Agent = isHttp ? http_1.Agent : https_1.Agent;
|
||||
exports.pool.set(key, new Agent({ ...poolOptions, keepAlive: true }));
|
||||
}
|
||||
}
|
||||
return exports.pool.get(key);
|
||||
}
|
||||
exports.getAgent = getAgent;
|
||||
//# sourceMappingURL=agents.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/agents.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,+BAAwC;AACxC,iCAA0C;AAC1C,kDAAkD;AAClD,6BAA0B;AAGb,QAAA,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;AAIjD;;;;;;;GAOG;AACH,SAAgB,QAAQ,CACtB,GAAW,EACX,OAAgB;IAEhB,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzC,MAAM,KAAK,GACT,OAAO,CAAC,KAAK;QACb,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,OAAO,CAAC,GAAG,CAAC,WAAW;QACvB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAE1B,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD,IAAI,KAAK,EAAE;QACT,yCAAyC;QACzC,MAAM,KAAK,GAAG,MAAM;YAClB,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC;YAC7B,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAEjC,MAAM,SAAS,GAAG,EAAC,GAAG,WAAK,CAAC,KAAK,CAAC,EAAE,GAAG,WAAW,EAAC,CAAC;QACpD,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;KAC7B;IAED,IAAI,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAEpC,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,GAAG,IAAI,UAAU,CAAC;QAElB,IAAI,CAAC,YAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,yCAAyC;YACzC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,YAAS,CAAC,CAAC,CAAC,aAAU,CAAC;YAC9C,YAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,EAAC,GAAG,WAAW,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC;SAC7D;KACF;IAED,OAAO,YAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AArCD,4BAqCC"}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import { Agent, AgentOptions as HttpsAgentOptions } from 'https';
|
||||
import { AgentOptions as HttpAgentOptions } from 'http';
|
||||
import { PassThrough, Readable } from 'stream';
|
||||
import { TeenyStatistics } from './TeenyStatistics';
|
||||
export interface CoreOptions {
|
||||
method?: string;
|
||||
timeout?: number;
|
||||
gzip?: boolean;
|
||||
json?: any;
|
||||
headers?: Headers;
|
||||
body?: string | {};
|
||||
useQuerystring?: boolean;
|
||||
qs?: any;
|
||||
proxy?: string;
|
||||
multipart?: RequestPart[];
|
||||
forever?: boolean;
|
||||
pool?: HttpsAgentOptions | HttpAgentOptions;
|
||||
}
|
||||
export interface OptionsWithUri extends CoreOptions {
|
||||
uri: string;
|
||||
}
|
||||
export interface OptionsWithUrl extends CoreOptions {
|
||||
url: string;
|
||||
}
|
||||
export declare type Options = OptionsWithUri | OptionsWithUrl;
|
||||
export interface Request extends PassThrough {
|
||||
agent: Agent | false;
|
||||
headers: Headers;
|
||||
href?: string;
|
||||
}
|
||||
export interface Response<T = any> {
|
||||
statusCode: number;
|
||||
headers: Headers;
|
||||
body: T;
|
||||
request: Request;
|
||||
statusMessage?: string;
|
||||
}
|
||||
export interface RequestPart {
|
||||
body: string | Readable;
|
||||
}
|
||||
export interface RequestCallback<T = any> {
|
||||
(err: Error | null, response: Response, body?: T): void;
|
||||
}
|
||||
export declare class RequestError extends Error {
|
||||
code?: number;
|
||||
}
|
||||
interface Headers {
|
||||
[index: string]: any;
|
||||
}
|
||||
declare function teenyRequest(reqOpts: Options): Request;
|
||||
declare namespace teenyRequest {
|
||||
var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
|
||||
var stats: TeenyStatistics;
|
||||
var resetStats: () => void;
|
||||
}
|
||||
declare function teenyRequest(reqOpts: Options, callback: RequestCallback): void;
|
||||
declare namespace teenyRequest {
|
||||
var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
|
||||
var stats: TeenyStatistics;
|
||||
var resetStats: () => void;
|
||||
}
|
||||
export { teenyRequest };
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.teenyRequest = exports.RequestError = void 0;
|
||||
const node_fetch_1 = require("node-fetch");
|
||||
const stream_1 = require("stream");
|
||||
const uuid = require("uuid");
|
||||
const agents_1 = require("./agents");
|
||||
const TeenyStatistics_1 = require("./TeenyStatistics");
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const streamEvents = require('stream-events');
|
||||
class RequestError extends Error {
|
||||
}
|
||||
exports.RequestError = RequestError;
|
||||
/**
|
||||
* Convert options from Request to Fetch format
|
||||
* @private
|
||||
* @param reqOpts Request options
|
||||
*/
|
||||
function requestToFetchOptions(reqOpts) {
|
||||
const options = {
|
||||
method: reqOpts.method || 'GET',
|
||||
...(reqOpts.timeout && { timeout: reqOpts.timeout }),
|
||||
...(typeof reqOpts.gzip === 'boolean' && { compress: reqOpts.gzip }),
|
||||
};
|
||||
if (typeof reqOpts.json === 'object') {
|
||||
// Add Content-type: application/json header
|
||||
reqOpts.headers = reqOpts.headers || {};
|
||||
reqOpts.headers['Content-Type'] = 'application/json';
|
||||
// Set body to JSON representation of value
|
||||
options.body = JSON.stringify(reqOpts.json);
|
||||
}
|
||||
else {
|
||||
if (Buffer.isBuffer(reqOpts.body)) {
|
||||
options.body = reqOpts.body;
|
||||
}
|
||||
else if (typeof reqOpts.body !== 'string') {
|
||||
options.body = JSON.stringify(reqOpts.body);
|
||||
}
|
||||
else {
|
||||
options.body = reqOpts.body;
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
options.headers = reqOpts.headers;
|
||||
let uri = (reqOpts.uri ||
|
||||
reqOpts.url);
|
||||
if (!uri) {
|
||||
throw new Error('Missing uri or url in reqOpts.');
|
||||
}
|
||||
if (reqOpts.useQuerystring === true || typeof reqOpts.qs === 'object') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const qs = require('querystring');
|
||||
const params = qs.stringify(reqOpts.qs);
|
||||
uri = uri + '?' + params;
|
||||
}
|
||||
options.agent = agents_1.getAgent(uri, reqOpts);
|
||||
return { uri, options };
|
||||
}
|
||||
/**
|
||||
* Convert a response from `fetch` to `request` format.
|
||||
* @private
|
||||
* @param opts The `request` options used to create the request.
|
||||
* @param res The Fetch response
|
||||
* @returns A `request` response object
|
||||
*/
|
||||
function fetchToRequestResponse(opts, res) {
|
||||
const request = {};
|
||||
request.agent = opts.agent || false;
|
||||
request.headers = (opts.headers || {});
|
||||
request.href = res.url;
|
||||
// headers need to be converted from a map to an obj
|
||||
const resHeaders = {};
|
||||
res.headers.forEach((value, key) => (resHeaders[key] = value));
|
||||
const response = Object.assign(res.body, {
|
||||
statusCode: res.status,
|
||||
statusMessage: res.statusText,
|
||||
request,
|
||||
body: res.body,
|
||||
headers: resHeaders,
|
||||
toJSON: () => ({ headers: resHeaders }),
|
||||
});
|
||||
return response;
|
||||
}
|
||||
/**
|
||||
* Create POST body from two parts as multipart/related content-type
|
||||
* @private
|
||||
* @param boundary
|
||||
* @param multipart
|
||||
*/
|
||||
function createMultipartStream(boundary, multipart) {
|
||||
const finale = `--${boundary}--`;
|
||||
const stream = new stream_1.PassThrough();
|
||||
for (const part of multipart) {
|
||||
const preamble = `--${boundary}\r\nContent-Type: ${part['Content-Type']}\r\n\r\n`;
|
||||
stream.write(preamble);
|
||||
if (typeof part.body === 'string') {
|
||||
stream.write(part.body);
|
||||
stream.write('\r\n');
|
||||
}
|
||||
else {
|
||||
part.body.pipe(stream, { end: false });
|
||||
part.body.on('end', () => {
|
||||
stream.write('\r\n');
|
||||
stream.write(finale);
|
||||
stream.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
function teenyRequest(reqOpts, callback) {
|
||||
const { uri, options } = requestToFetchOptions(reqOpts);
|
||||
const multipart = reqOpts.multipart;
|
||||
if (reqOpts.multipart && multipart.length === 2) {
|
||||
if (!callback) {
|
||||
// TODO: add support for multipart uploads through streaming
|
||||
throw new Error('Multipart without callback is not implemented.');
|
||||
}
|
||||
const boundary = uuid.v4();
|
||||
options.headers['Content-Type'] = `multipart/related; boundary=${boundary}`;
|
||||
options.body = createMultipartStream(boundary, multipart);
|
||||
// Multipart upload
|
||||
teenyRequest.stats.requestStarting();
|
||||
node_fetch_1.default(uri, options).then(res => {
|
||||
teenyRequest.stats.requestFinished();
|
||||
const header = res.headers.get('content-type');
|
||||
const response = fetchToRequestResponse(options, res);
|
||||
const body = response.body;
|
||||
if (header === 'application/json' ||
|
||||
header === 'application/json; charset=utf-8') {
|
||||
res.json().then(json => {
|
||||
response.body = json;
|
||||
callback(null, response, json);
|
||||
}, (err) => {
|
||||
callback(err, response, body);
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.text().then(text => {
|
||||
response.body = text;
|
||||
callback(null, response, text);
|
||||
}, err => {
|
||||
callback(err, response, body);
|
||||
});
|
||||
}, err => {
|
||||
teenyRequest.stats.requestFinished();
|
||||
callback(err, null, null);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (callback === undefined) {
|
||||
// Stream mode
|
||||
const requestStream = streamEvents(new stream_1.PassThrough());
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let responseStream;
|
||||
requestStream.once('reading', () => {
|
||||
if (responseStream) {
|
||||
responseStream.pipe(requestStream);
|
||||
}
|
||||
else {
|
||||
requestStream.once('response', () => {
|
||||
responseStream.pipe(requestStream);
|
||||
});
|
||||
}
|
||||
});
|
||||
options.compress = false;
|
||||
teenyRequest.stats.requestStarting();
|
||||
node_fetch_1.default(uri, options).then(res => {
|
||||
teenyRequest.stats.requestFinished();
|
||||
responseStream = res.body;
|
||||
responseStream.on('error', (err) => {
|
||||
requestStream.emit('error', err);
|
||||
});
|
||||
const response = fetchToRequestResponse(options, res);
|
||||
requestStream.emit('response', response);
|
||||
}, err => {
|
||||
teenyRequest.stats.requestFinished();
|
||||
requestStream.emit('error', err);
|
||||
});
|
||||
// fetch doesn't supply the raw HTTP stream, instead it
|
||||
// returns a PassThrough piped from the HTTP response
|
||||
// stream.
|
||||
return requestStream;
|
||||
}
|
||||
// GET or POST with callback
|
||||
teenyRequest.stats.requestStarting();
|
||||
node_fetch_1.default(uri, options).then(res => {
|
||||
teenyRequest.stats.requestFinished();
|
||||
const header = res.headers.get('content-type');
|
||||
const response = fetchToRequestResponse(options, res);
|
||||
const body = response.body;
|
||||
if (header === 'application/json' ||
|
||||
header === 'application/json; charset=utf-8') {
|
||||
if (response.statusCode === 204) {
|
||||
// Probably a DELETE
|
||||
callback(null, response, body);
|
||||
return;
|
||||
}
|
||||
res.json().then(json => {
|
||||
response.body = json;
|
||||
callback(null, response, json);
|
||||
}, err => {
|
||||
callback(err, response, body);
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.text().then(text => {
|
||||
const response = fetchToRequestResponse(options, res);
|
||||
response.body = text;
|
||||
callback(null, response, text);
|
||||
}, err => {
|
||||
callback(err, response, body);
|
||||
});
|
||||
}, err => {
|
||||
teenyRequest.stats.requestFinished();
|
||||
callback(err, null, null);
|
||||
});
|
||||
return;
|
||||
}
|
||||
exports.teenyRequest = teenyRequest;
|
||||
teenyRequest.defaults = (defaults) => {
|
||||
return (reqOpts, callback) => {
|
||||
const opts = { ...defaults, ...reqOpts };
|
||||
if (callback === undefined) {
|
||||
return teenyRequest(opts);
|
||||
}
|
||||
teenyRequest(opts, callback);
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Single instance of an interface for keeping track of things.
|
||||
*/
|
||||
teenyRequest.stats = new TeenyStatistics_1.TeenyStatistics();
|
||||
teenyRequest.resetStats = () => {
|
||||
teenyRequest.stats = new TeenyStatistics_1.TeenyStatistics(teenyRequest.stats.getOptions());
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+97
@@ -0,0 +1,97 @@
|
||||
{
|
||||
"_from": "teeny-request@^7.0.0",
|
||||
"_id": "[email protected]",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-Ew3aoFzgQEatLA5OBIjdr1DWJUaC1xardG+qbPPo5k/y/3fMwXLxpjh5UB5dVfElktLaQbbMs80chkz53ByvSg==",
|
||||
"_location": "/teeny-request",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "teeny-request@^7.0.0",
|
||||
"name": "teeny-request",
|
||||
"escapedName": "teeny-request",
|
||||
"rawSpec": "^7.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^7.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@google-cloud/common"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-7.1.3.tgz",
|
||||
"_shasum": "5a3d90c559a6c664a993477b138e331a518765ba",
|
||||
"_spec": "teeny-request@^7.0.0",
|
||||
"_where": "/Users/talksik/Development/nirvana-server/node_modules/@google-cloud/common",
|
||||
"author": {
|
||||
"name": "fhinkel"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/googleapis/teeny-request/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"http-proxy-agent": "^5.0.0",
|
||||
"https-proxy-agent": "^5.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"stream-events": "^1.0.5",
|
||||
"uuid": "^8.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Like request, but smaller.",
|
||||
"devDependencies": {
|
||||
"@compodoc/compodoc": "^1.1.9",
|
||||
"@types/mocha": "^8.0.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/sinon": "^10.0.0",
|
||||
"@types/uuid": "^8.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"codecov": "^3.1.0",
|
||||
"gts": "^3.0.0",
|
||||
"linkinator": "^2.0.0",
|
||||
"mocha": "^8.0.0",
|
||||
"nock": "^13.0.0",
|
||||
"sinon": "^10.0.0",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"files": [
|
||||
"build/src"
|
||||
],
|
||||
"homepage": "https://github.com/googleapis/teeny-request#readme",
|
||||
"keywords": [
|
||||
"request",
|
||||
"node-fetch",
|
||||
"fetch"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"main": "./build/src/index.js",
|
||||
"name": "teeny-request",
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"build/test"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/googleapis/teeny-request.git"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "gts clean",
|
||||
"compile": "tsc -p .",
|
||||
"docs": "compodoc src/",
|
||||
"docs-test": "linkinator docs",
|
||||
"fix": "gts fix",
|
||||
"lint": "gts check",
|
||||
"precompile": "gts clean",
|
||||
"predocs-test": "npm run docs",
|
||||
"prepare": "npm run compile",
|
||||
"pretest": "npm run compile",
|
||||
"samples-test": "echo no sample tests!",
|
||||
"system-test": "echo no system tests!",
|
||||
"test": "c8 mocha build/test"
|
||||
},
|
||||
"types": "./build/src/index.d.ts",
|
||||
"version": "7.1.3"
|
||||
}
|
||||
Reference in New Issue
Block a user