Commit Graph

218 Commits

Author SHA1 Message Date
Richie Bendall 94e5b92de1
Remove `timeout` option (#831) 2020-05-25 13:30:05 +02:00
Antoni Kepinski a3cee3f6e7
Merge branch 'master' of https://github.com/node-fetch/node-fetch 2020-05-24 12:17:13 +02:00
Antoni Kepinski 498710d555
make sure the default `highWaterMark` equals 16384 2020-05-24 12:16:34 +02:00
Richie Bendall 26966e561d
Simplify test delaying
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
2020-05-24 17:36:22 +12:00
Jonathan Stewmon bea4a7cb73
fix: Settle `consumeBody` promise when the response closes prematurely (#768)
The stream.finished function is used consolidate the terminal cases.
The writable option must be set to false, since the body stream is
a Duplex stream, but our terminal cases only apply to the Readable side.
2020-05-23 08:28:38 -04:00
Jonathan Stewmon 63d3663466
fix: disambiguate timeout behavior for response headers and body (#770)
There is a single timeout option which applies to both the receiving of
response headers and the receiving of the entire response body. Once
the response is received, the socket timeout must be cleared to allow
the timeout to apply to the receiving of the entire response body.

Without clearing the socket timeout, if the nearing the idle timeout
when the Promise for the body is created, then the request's timeout
handler will abort the request, emitting ERR_STREAM_PREMATURE_CLOSE in
the body Promise.

By clearing the socket timeout once the response headers are received,
the timeout for the entire body can be started when the body is awaited.
Since the request will no longer be aborted by the socket timeout,
destroy is called on the body to prevent it continuing to emit data
events.
2020-05-22 15:19:05 -04:00
Konstantin Vyatkin 0f97d62844
drop Babel (while keeping ESM) (#805)
* drop Babel

* fix lint

* just to trigger CI

* Update package.json

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>

* fix all imports

* coverage only from Node 14.x

* remove esm

* restore travis

* fix lint

Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
2020-05-21 02:50:31 -04:00
Antoni Kepinski 7d36f3b247
Improve coverage (#779) 2020-05-17 15:28:26 +02:00
Antoni Kepinski 631a4b2437
fix question mark stripped from url when no params are given (#7… (#782)
* fix question mark stripped from url when no params are given (#776)

* add more tests

* whitespace

* modify the server to handle the new tests

Co-authored-by: dzek69 <git-public@dzek.eu>
2020-04-20 21:42:51 +02:00
Antoni Kepinski 55b6004581
lint 2020-04-13 13:42:35 +02:00
David Frank 0959ca9739
merge 3.x into master branch (#745)
* feat: Migrate TypeScript types (#669)

* style: Introduce linting via XO

* fix: Fix tests

* chore!: Drop support for nodejs 4 and 6

* chore: Fix Travis CI yml

* Use old Babel (needs migration)

* chore: lint everything

* chore: Migrate to microbundle

* Default response.statusText should be blank (#578)

* fix: Use correct AbortionError message

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Use modern @babel/register

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Remove redundant packages

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Readd form-data

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* fix: Fix tests and force utf8-encoded urls

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* lint index.js

* Update devDependencies & ignore `test` directory in linter options

* Remove unnecessary eslint-ignore comment

* Update the `lint` script to run linter on every file

* Remove unused const & unnecessary import

* TypeScript: Fix Body.blob() wrong type (DefinitelyTyped/DefinitelyTyped#33721)

* chore: Lint as part of the build process

* fix: Convert Content-Encoding to lowercase (#672)

* fix: Better object checks (#673)

* Fix stream piping (#670)

* chore: Remove useless check

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* style: Fix lint

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* style: Fix lint

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* refactor: Modernise code

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Ensure all files are properly included

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Update deps and utf8 should be in dependencies

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* test: Drop Node v4 from tests

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* test: Modernise code

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Move errors to seperate directory

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* refactor: Add fetch-blob (#678)

* feat: Migrate data uri integration

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* Allow setting custom highWaterMark via node-fetch options (#386) (#671)

* Expose highWaterMark option to body clone function

* Add highWaterMark to responseOptions

* Add highWaterMark as node-fetch-only option

* a way to silently pass highWaterMark to clone

* Chai helper

* Server helper

* Tests

* Remove debug comments

* Document highWaterMark option

* Add TypeScript types for the new highWaterMark option

* feat: Include system error in FetchError if one occurs (#654)

* style: Add editorconfig

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore!: Drop NodeJS v8

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Remove legacy code for node < 8

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Use proper checks for ArrayBuffer and AbortError

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Use explicitly set error name in checks

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* Propagate size and timeout to cloned response (#664)

* Remove --save option as it isn't required anymore (#581)

* Propagate size and timeout to cloned response


Co-authored-by: Steve Moser <contact@stevemoser.org>
Co-authored-by: Antoni Kepinski <xxczaki@pm.me>

* Update Response types

* Update devDependencies

* feat: Fallback to blob type (Closes: #607)

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* style: Update formatting

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* style: Fix linting issues

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: Add info on patching the global object

* docs: Added non-globalThis polyfill

* Replace deprecated `url.resolve` with the new WHATWG URL

* Update devDependencies

* Format code in examples to use `xo` style

* Verify examples with RunKit and edit them if necessary

* Add information about TypeScript support

* Document the new `highWaterMark` option

* Add Discord badge & information about Open Collective

* Style change

* Edit acknowledgement & add "Team" section

* fix table

* Format example code to use xo style

* chore: v3 release changelog

* Add the recommended way to fix `highWaterMark` issues

* docs: Add simple Runkit example

* fix: Properly set the name of the errors.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: Add AbortError to documented types

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: AbortError proper typing parameters

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: Add example code for Runkit

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* Replace microbundle with @pika/pack (#689)

* gitignore the pkg/ directory

* Move TypeScript types to the root of the project

* Replace microbundle with @pika/pack

* chore: Remove @pika/plugin-build-web and revert ./dist output directory

Signed-off-by: Richie Bendall <richiebendall@gmail.com>


Co-authored-by: Richie Bendall <richiebendall@gmail.com>

* fix incorrect statement in changelog

* chore: v3.x upgrade guide

* Change the Open Collective button

* docs: Encode support button as Markdown instead of HTML

* chore: Ignore proper directory in xo

* Add an "Upgrading" section to readme

* Split the upgrade guide into 2 files & add the missing changes about v3.x

* style: Lint test and example files

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* Move *.md files to the `docs` folder (except README.md)

* Update references to files

* Split LIMITS.md into 2 files (as of v2.x and v3.x)

* chore: Remove logging statement

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* style: Fix lint

* docs: Correct typings for systemError in FetchError (Fixes #697)

* refactor: Replace `encoding` with `fetch-charset-detection`. (#694)

* refactor: Replace `encoding` with `fetch-charset-detection`.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* refactor: Move writing to stream back to body.js

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* refactor: Only put convertBody in fetch-charset-detection and refactor others.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* test: Readd tests for getTotalBytes and extractContentType

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Revert package.json indention

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Remove optional dependency

* docs: Replace code for fetch-charset-detection with documentation.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Remove iconv-lite

* fix: Use default export instead of named export for convertBody

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Remove unneeded installation of fetch-charset-detection in the build

* docs: Fix typo

* fix: Throw SyntaxError instead of FetchError in case of invalid… (#700)

* fix: Throw SyntaxError instead of FetchError in case of invalid JSON

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: Add to upgrade guide

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* Remove deprecated url.parse from test

* Remove deprecated url.parse from server

* fix: Proper data uri to buffer conversion (#703)

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Add funding info

* fix: Flawed property existence test (#706)

Fix a problem where not all prototype methods are copied from the Body via the mixin method due to a failure to properly detect properties in the target. The current code uses the `in` operator, which may return properties lower down the inheritance chain, thus causing them to fail the copy. The new code properly calls the `.hasOwnProperty()` method to make the determination.

* fix: Properly handle stream pipeline double-fire

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: Fix spelling

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Add `funding` field to package.json (#708)

* Fix: Do not set ContentLength to NaN (#709)

* do not set ContentLength to NaN

* lint

* docs: Add logo

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Update repository name from bitinn/node-fetch to node-fetch/node-fetch.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Fix unit tests

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore(deps): Bump @pika/plugin-copy-assets from 0.7.1 to 0.8.1 (#713)

Bumps [@pika/plugin-copy-assets](https://github.com/pikapkg/builders) from 0.7.1 to 0.8.1.
- [Release notes](https://github.com/pikapkg/builders/releases)
- [Commits](https://github.com/pikapkg/builders/compare/v0.7.1...v0.8.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* chore(deps): Bump @pika/plugin-build-types from 0.7.1 to 0.8.1 (#710)

Bumps [@pika/plugin-build-types](https://github.com/pikapkg/builders) from 0.7.1 to 0.8.1.
- [Release notes](https://github.com/pikapkg/builders/releases)
- [Commits](https://github.com/pikapkg/builders/compare/v0.7.1...v0.8.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Bump nyc from 14.1.1 to 15.0.0 (#714)

Bumps [nyc](https://github.com/istanbuljs/nyc) from 14.1.1 to 15.0.0.
- [Release notes](https://github.com/istanbuljs/nyc/releases)
- [Changelog](https://github.com/istanbuljs/nyc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/istanbuljs/nyc/compare/v14.1.1...v15.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* chore: Update travis ci url

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore(deps): Bump mocha from 6.2.2 to 7.0.0 (#711)

Bumps [mocha](https://github.com/mochajs/mocha) from 6.2.2 to 7.0.0.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v6.2.2...v7.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* feat: Allow excluding a user agent in a fetch request by setting… (#715)

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* Bump @pika/plugin-build-node from 0.7.1 to 0.8.1 (#717)

Bumps [@pika/plugin-build-node](https://github.com/pikapkg/builders) from 0.7.1 to 0.8.1.
- [Release notes](https://github.com/pikapkg/builders/releases)
- [Commits](https://github.com/pikapkg/builders/compare/v0.7.1...v0.8.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Bump @pika/plugin-standard-pkg from 0.7.1 to 0.8.1 (#716)

Bumps [@pika/plugin-standard-pkg](https://github.com/pikapkg/builders) from 0.7.1 to 0.8.1.
- [Release notes](https://github.com/pikapkg/builders/releases)
- [Commits](https://github.com/pikapkg/builders/compare/v0.7.1...v0.8.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Bump form-data from 2.5.1 to 3.0.0 (#712)

Bumps [form-data](https://github.com/form-data/form-data) from 2.5.1 to 3.0.0.
- [Release notes](https://github.com/form-data/form-data/releases)
- [Commits](https://github.com/form-data/form-data/compare/v2.5.1...v3.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* fix: typo

* update suggestion

* feat: Added missing redirect function (#718)

* added missing redirect function
* chore: Add types

Co-authored-by: Richie Bendall <richiebendall@gmail.com>

* fix: Use req.setTimeout for timeout (#719)

* chore: Update typings comment

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* chore: Update deps

Signed-off-by: Richie Bendall <richiebendall@gmail.com>

* docs: center badges & Open Collective button

* docs: add missing comma

* Remove current stable & LTS node version numbers from the comments

I don't think we really want to update them

* Bump xo from 0.25.4 to 0.26.1 (#730)

Bumps [xo](https://github.com/xojs/xo) from 0.25.4 to 0.26.1.
- [Release notes](https://github.com/xojs/xo/releases)
- [Commits](https://github.com/xojs/xo/compare/v0.25.4...v0.26.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Bump @pika/plugin-build-types from 0.8.3 to 0.9.2 (#729)

Bumps [@pika/plugin-build-types](https://github.com/pikapkg/builders) from 0.8.3 to 0.9.2.
- [Release notes](https://github.com/pikapkg/builders/releases)
- [Commits](https://github.com/pikapkg/builders/compare/v0.8.3...v0.9.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Bump @pika/plugin-standard-pkg from 0.8.3 to 0.9.2 (#726)

Bumps [@pika/plugin-standard-pkg](https://github.com/pikapkg/builders) from 0.8.3 to 0.9.2.
- [Release notes](https://github.com/pikapkg/builders/releases)
- [Commits](https://github.com/pikapkg/builders/compare/v0.8.3...v0.9.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* docs: Update information about `req.body` type in v3.x release

* Add information about removed body type to the v3 upgrade guide

* add awesome badge

* Show 2 ways of importing node-fetch (CommonJS & ES module)

* update dependencies

* lint

* refactor: Replace `url.parse` with `new URL()` (#701)

* chore: replace `url.parse` with `new URL()`

* lint

* handle relative URLs

* Change error message

* detect whether the url is absolute or not

* update tests

* drop relative url support

* lint

* fix tests

* typo

* Add information about dropped arbitrary URL support in v3.x upgrade guide

* set xo linting rule (node/no-deprecated-api) to on

* remove the `utf8` dependency

* fix

* refactor: split tests into several files, create the `utils` directory

* Update package.json scripts & remove unnecessary xo linting rules

* refactor: turn on some xo linting rules to improve code quality

* fix tests

* Remove invalid urls

* fix merge conflict

* update the upgrade guide

* test if URLs are encoded as UTF-8

* update xo to 0.28.0

* chore: Build before publishing

* v3.0.0-beta.1

* fix lint on test/main.js

Co-authored-by: Richie Bendall <richiebendall@gmail.com>
Co-authored-by: Antoni Kepinski <xxczaki@pm.me>
Co-authored-by: aeb-sia <50743092+aeb-sia@users.noreply.github.com>
Co-authored-by: Nazar Mokrynskyi <nazar@mokrynskyi.com>
Co-authored-by: Steve Moser <contact@stevemoser.org>
Co-authored-by: Erick Calder <e@arix.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Jimmy Wärting <jimmy@warting.se>
2020-03-13 23:06:25 +08:00
dsuket 6a5d192034 fix: Properly parse meta tag when parameters are reversed (#682) 2019-10-07 19:58:27 +13:00
Richie Bendall eb3a57255b
feat: Data URI support (#659)
Adds support for Data URIs using native methods in Node 5.10.0+
2019-09-08 09:44:40 +12:00
David Frank 95286f52bb
v2.6.0 (#638)
* Update readme and changelog for `options.agent`
- Fix content-length issue introduced in v2.5.0
* More test coverage for `extractContentType`
* Slightly improve test performance
* `Response.url` should not return null
* Document `Headers.raw()` usage better
* 2.6.0
2019-05-16 14:38:28 +08:00
edgraaff bf8b4e8db3 Allow agent option to be a function (#632)
Enable users to return HTTP/HTTPS-specific agent based on request url
2019-05-05 20:12:33 +08:00
David Frank 0c2294ec48
2.5.0 release (#630)
* redirected property
* changelog update
* readme update
* 2.5.0
2019-05-01 13:05:32 +08:00
Justin Beckwith a35dcd14a3 chore(deps): address deprecated url-search-params package (#622) 2019-05-01 11:14:11 +08:00
David Frank 49d77600a7
Pass custom timeout to subsequent requests on redirect (#615) 2019-04-27 00:46:53 +08:00
Muhammet Öztürk 2a2d4384af Adding Brotli Support (#598)
* adding brotli support
* support old node versions
* better test
2019-04-27 00:20:15 +08:00
David Frank 05f5ac12a2
Node 12 compatibility (#614)
* dev package bump
* test invalid header differently as node 12 no longer accepts invalid headers in response
* add node v10 in travis test list as node 12 has been released
2019-04-27 00:11:52 +08:00
Jimmy Wärting 432c9b01ea support reading blob with stream (#608) 2019-04-16 18:29:17 +08:00
Jimmy Wärting 0ad136d49f Added new reading method to blob 2019-04-15 22:46:11 +02:00
Kevin (Kun) "Kassimo" Qian 1c2f07ffb8 Headers should not accept empty field name (#562) 2018-12-29 17:04:44 +08:00
Jimmy Wärting 2d0fc689c6 Clone URLSearchParams to avoid mutation (#547)
* And make sure Request/Response set Content-Type per Fetch Spec
* And make sure users can read the body as string via text()
2018-11-14 00:36:44 +08:00
Joseph Nields ecd3d52c55 Add support for AbortSignal to cancel requests (#539)
Thx @jnields @FrogTheFrog @TimothyGu for their work!
2018-11-13 12:40:11 +08:00
David Frank 1daae67e9e
Fix import style to workaround node < 10 and webpack issues. (#544)
* fix import rule for stream PassThrough

* avoid named export for compatibility below node 10

* compress flag should not overwrite accept encoding header

* doc update

* 2.2.1
2018-11-05 17:42:51 +08:00
Timothy Gu b091ab5917
Fix up ArrayBufferView support (#464)
Also add more test coverage.

Fixes: #482
Closes: #484
2018-07-21 22:13:01 -07:00
Bernhard K. Weisshuhn 287bc3bdcf test agent option `family` being passed to `lookup` 2018-06-19 12:52:13 -07:00
Bernhard K. Weisshuhn b2c5f543ce test supplying a lookup function through an agent 2018-06-19 12:52:13 -07:00
Nazar Mokrynskyi 5bc23d81cf Added support for `ArrayBufferView` (#457) 2018-05-28 11:18:17 +08:00
Timothy Gu f6683aa49c Add a test case for invalid headers
See feae6d6ec8.
2018-03-25 13:45:26 -07:00
Timothy Gu 13b230b30b Add a test for redirect with stream body
See 35722f19e5.
2018-03-25 13:45:26 -07:00
Timothy Gu 8aac53679d
Fix custom Host header with arbitrary case (#430)
Regression since 1592ca1148.

Fixes: #416
Fixes: #425
2018-03-22 22:01:45 -07:00
Jason Rogers c012c4116b Reject when stream accumulation fails (#415)
Fixes: #414
2018-03-22 18:38:03 -07:00
William MacDonald 4c4f2f29e5 Wrap ArrayBuffer with Buffer internally to fix Body methods (#426) 2018-03-20 09:57:03 -07:00
Timothy Gu 780598ad72
Harmonize style (#413) 2018-03-04 20:29:12 -08:00
Timothy Gu 35722f19e5 Significant rework of redirection
- Handle Location-less redirect like non-redirect response.
- Include bodies when redirecting to non-POST 301/302 and all 307/308
  response.

Co-authored-by: Gregor Martynus <gregor@martynus.net>
2018-03-04 20:25:16 -08:00
Gregor Martynus fc539951ca Support ArrayBuffer as body (#408) 2018-03-04 16:40:39 -08:00
Timothy Gu b1cd2dd438
Better compliance with Web IDL
- Make read-only attributes actually read-only
- Set @@toStringTag on the prototype only
- Make prototype methods/getters enumerable

Based on #354.

Co-authored-by: Benjamin Seber <seber@synyx.de>
2018-02-03 12:12:14 -08:00
Timothy Gu dccef32e81
Refactor tests 2018-02-03 12:11:50 -08:00
Timothy Gu bc6f0da3ac
Remove Blob#close per spec change
See https://github.com/w3c/FileAPI/pull/68.
2018-02-03 11:19:32 -08:00
Moritz 19b115f9dc Add error event hander for the body stream even if the body isn't accessed (#379)
Fixes #378
2018-01-27 11:20:05 -08:00
David Frank 3345b652e4
fix a small oversight in request class
lowercase method name does not trigger type error properly (#362)
2017-11-19 12:44:02 +08:00
Timothy Gu e7c1ef88ed Update deps (#320) 2017-07-28 12:12:54 +08:00
David Frank 9bd099a779 workaround slow nodejs 8 spawn on travis ci by increasing timeout for test cases 2017-07-22 21:11:25 +08:00
David Frank 70cd403914 do not make request to example.com, use local server instead, avoid UnhandledPromiseRejectionWarning altogether 2017-07-22 21:04:59 +08:00
Jared Kantrowitz 432cd8a31e remove `encoding` as a dependency, throw detailed Error if not installed (#302)
* remove `encoding` as a dependency, throw descriptive Error if textConverted() is used without it in env

* remove rollup ext dep resolution since we don't need it

* switch to programmer error, rm unneeded test conditions, bump timeout for slow CI

* more kill `encoding` dep PR changes

keep blank "dependencies" prop in package.json so rollup's external config func doesn't seize
add ext dep checks back to the rollup config
no implicit var
clarify test comment

* [squash] alter travis cfg to test with and without `encoding`, various

fix devDeps
separate `encoding` tests to their own block

* [squash] fixing nits

* [squash] ci: full matrix of form-data versions and encoding existence

and nits
2017-07-02 12:32:48 -04:00
Jared Kantrowitz 76e8ad8b24 refactor deprecated `new Buffer` with Buffer.from and Buffer.alloc (#299)
* refactor deprecated `new Buffer` with Buffer.from and Buffer.alloc

* don't need new ArrayBuffer instance when already an ArrayBuffer
2017-06-19 20:41:05 -04:00
jared kantrowitz 1804041726 wrap JSON.parse's SynaxError with FetchError 2017-06-19 20:31:15 -04:00
Jared Kantrowitz 553d50e804 Accept URLSearchParams as body (#297)
Fixes: #296
2017-06-12 13:29:50 +08:00
David Frank c24d591794 fix test server for node 8, which changes keepalive connection handling 2017-06-03 18:01:13 +08:00
Kat Marchán e5ff203ef4 Revert "Allow passing agent option as an object (#236)" (#263)
This reverts commit ec29e3d264.

This patch prevents any agent being passed in which is not explicitly
an instance of `http.Agent`. This makes `node-fetch` no longer
compatible with https://npm.im/proxy-agent, which is one example of a
library that does not directly inherit from `http.Agent` directly.

Sorry for the revert -- I don't have an alternative patch because I
don't believe this is something node-fetch should be doing
automatically, because of how much of a limitation this could impose.

The original PR stated that this was to prevent requiring http/https,
and the effect would effectively be to force creation of an Agent on
every call. Note that this is already the behavior specified for
http.Agent when http.request received `false`. (See the bottom of the
[section on http.Agent in the Node
docs](https://nodejs.org/dist/latest-v7.x/docs/api/http.html#http_class_http_agent).

Cheers, and with apologies to @ahmadnassri for reverting their PR.
2017-04-08 18:33:46 -07:00
Ahmad Nassri ec29e3d264 Allow passing agent option as an object (#236) 2017-04-03 02:54:31 -07:00
Kat Marchán 09f2e30557 headers.get: add space to join (#257)
The behavior was changed in whatwg/fetch#504.
2017-04-02 08:43:46 -07:00
Gajus Kuizinas 4804a40c17 Add a special case for constructing Headers with Headers (#253)
Fixes: #251.
2017-03-20 09:22:49 -07:00
Grzegorz Graczyk a1e76b97e1 More lenient gzip decompression (#239)
Ref: https://github.com/nodejs/node/issues/8701#issuecomment-268224481
Ref: https://github.com/request/request/issues/2482
Ref: https://github.com/request/request/pull/2492
Fixes: http://www.mantovanispa.it
Fixes: #139
2017-02-27 10:02:45 -08:00
Timothy Gu e284841db9 test: use fetch.Promise consistently
On Node.js v4, Babel polyfills `Promise`.
2017-02-26 17:00:01 -08:00
Timothy Gu 25e43a8f3e Export FetchError and update ERROR-HANDLING.md 2017-02-26 16:46:34 -08:00
Timothy Gu 55e573b741 Back to 100% coverage 2017-02-26 15:30:43 -08:00
Timothy Gu b899649c32 Remove bluebird 2017-02-26 14:42:46 -08:00
Timothy Gu 56f786f896 Update deps and remove 0.12 compat 2017-02-26 14:12:45 -08:00
Timothy Gu 11a9481405 request: overwrite Content-Length if possible
Also reorganize header normalization
2017-01-29 10:06:54 -08:00
Timothy Gu ac8ddaccb8 Improve Headers constructor argument processing 2017-01-29 08:58:16 -08:00
Timothy Gu e9db869523 Remove FOLLOW_SPEC option; make it the default behavior (#225)
* Remove !FOLLOW_SPEC mode

* Update UPGRADE-GUIDE

* Add CHANGELOG entry
2017-01-23 07:54:28 -08:00
Timothy Gu 502b604208 Fix Headers iterable initializer handling 2017-01-14 21:22:23 -08:00
Timothy Gu f198f93767 test: remove fallbacks for Node.js 0.10 2017-01-14 20:56:26 -08:00
Timothy Gu 151de2bdfb Use ES2015 export syntax (#212)
* Implement Rollup's external module check

* Use ES2015 export syntax

More friendly to ES2015 environments.
2017-01-14 20:50:10 -08:00
Nathan Rajlich fa22529128 proper stack first line for FetchError instances (#215)
The `.stack` property gets cached in the `captureStackTrace()` call, so
whatever is set as the `name` and `message` at that time will be used
for the first line of the stack trace.

Before this patch, FetchError's stack would just say "Error" as the
first line. Now they correctly display the "${name}: ${message}" of the
error instances.

Test case included.

Signed-off-by: Timothy Gu <timothygu99@gmail.com>
2016-12-14 15:41:35 -08:00
Timothy Gu 0f7e6c15d3 Back to 100% 2016-12-05 21:20:00 -08:00
Timothy Gu 90d3bc4436 Set content-length for buffer bodies 2016-12-05 20:30:00 -08:00
Timothy Gu a604069860 More exact content-type and content-length
Set content-type of requests with body being objects to text/plain
2016-12-05 20:27:08 -08:00
Timothy Gu 385ca6b2b0 To 100% branches coverage 2016-12-05 19:48:59 -08:00
Timothy Gu 4d944365df Fix tests added in the last commit 2016-12-05 15:21:19 -08:00
Timothy Gu e7a13a5314 Add support for blobs 2016-12-05 15:06:22 -08:00
Timothy Gu cc4ace1778 Make body default to null in Request
Fixes #208.
2016-12-04 13:16:03 -08:00
Timothy Gu 3d676235a8 Throw when a GET/HEAD Request is created with body
As mandated by the spec
2016-12-04 13:15:03 -08:00
Timothy Gu d3071fa46a Revert "Return empty .json() object on 204. Fix #165. (#166)" (#201)
This reverts commit 95b58936b8.

Fixes #165.
2016-11-26 09:07:12 -08:00
Timothy Gu 25ff99677d Improve Headers' iteration support
Class strings, spec-compliant forEach, etc.
2016-11-23 15:06:30 -08:00
Timothy Gu a355664e64 Update packages 2016-11-23 11:30:01 -08:00
Timothy Gu 5fe80dba06 Remove dependency on babel-polyfill
This way the tests can better emulate the real Node.js environment.
2016-11-05 10:26:30 -07:00
Timothy Gu 72d34af6e2 Start test server when executed directly 2016-11-05 09:39:01 -07:00
Timothy Gu 76cb57cace Support WHATWG URL objects
Fixes #175.
2016-10-15 10:19:52 -07:00
Timothy Gu b092a8ed12 Add test for constructing Request with parsed URL object 2016-10-15 10:19:52 -07:00
Timothy Gu d3b4161d7c Add a new res.textConverted() and always use UTF-8 for res.text()
Also uses iconv-lite directly instead of using the "encoding" package.

Fixes #184.
2016-10-15 09:41:52 -07:00
Timothy Gu 2a7ef63bc4 Add FOLLOW_SPEC mode 2016-10-15 08:21:51 -07:00
Timothy Gu 2cafdcb5e4 Validate headers 2016-10-15 08:21:51 -07:00
Timothy Gu fba873d3fe Make sure to coerce header values to string 2016-10-15 08:21:51 -07:00
Timothy Gu 82c1e78184 Allow constructing Headers with an Array 2016-10-15 08:21:51 -07:00
Timothy Gu 67326e3873 Condense class toString tests 2016-10-12 20:51:19 -07:00
Timothy Gu 4d81cb4877 Test @@toStringTag getter of all classes 2016-10-12 17:29:33 -07:00
Timothy Gu 0f65af3fd8 Split Headers iterable test into four 2016-10-12 17:29:33 -07:00
Timothy Gu c3a121a360 Add support for Body#arrayBuffer 2016-10-12 17:29:33 -07:00
Timothy Gu 64e239b092 Improve Body spec compliance when body is null 2016-10-12 17:29:33 -07:00
Timothy Gu a0be6aa34a Simplify Request constructor
Also make Request more standard compliant:

> The `url` attribute's getter must return request's url, **serialized.**
2016-10-12 17:29:33 -07:00
Timothy Gu 838071247d Convert all files to ES2015 (#182)
Elements of this commit come from #140 by @gwicke.
2016-10-10 11:50:04 -07:00
Timothy Gu 993d4cdea1 Convert Headers to ES2015 and implement Iterable interface (#180)
Closes #127, #174.
2016-10-08 20:51:01 -07:00
Timothy Gu 7c26fa9479 Add Babel infrastructure
No actual code has been changed yet.
2016-10-04 02:59:46 -07:00
David Frank e926483448 minor format fix and comments 2016-09-24 17:12:18 +08:00
Dan Dascalescu 95b58936b8 Return empty .json() object on 204. Fix #165. (#166)
Handle an edge case where 204 No Content response body is empty, but node-fetch trying to parse the empty body as-is.
2016-09-24 17:06:18 +08:00
David Frank ffddec0ad2 fix test: buffer.alloc is not available for older node.js release 2016-09-11 23:34:50 +08:00