2.5.0 release (#630)
* redirected property * changelog update * readme update * 2.5.0
This commit is contained in:
parent
0fc414c2a8
commit
0c2294ec48
|
@ -5,6 +5,14 @@ Changelog
|
|||
|
||||
# 2.x release
|
||||
|
||||
## v2.5.0
|
||||
|
||||
- Enhance: `Response` object now includes `redirected` property.
|
||||
- Enhance: `fetch()` now accepts third-party `Blob` implementation as body.
|
||||
- Other: disable `package-lock.json` generation as we never commit them.
|
||||
- Other: dev dependency update.
|
||||
- Other: readme update.
|
||||
|
||||
## v2.4.1
|
||||
|
||||
- Fix: `Blob` import rule for node < 10, as `Readable` isn't a named export.
|
||||
|
|
15
README.md
15
README.md
|
@ -381,7 +381,6 @@ The following properties are not implemented in node-fetch at this moment:
|
|||
- `Response.error()`
|
||||
- `Response.redirect()`
|
||||
- `type`
|
||||
- `redirected`
|
||||
- `trailer`
|
||||
|
||||
#### new Response([body[, options]])
|
||||
|
@ -401,6 +400,12 @@ Because Node.js does not implement service workers (for which this class was des
|
|||
|
||||
Convenience property representing if the request ended normally. Will evaluate to true if the response status was greater than or equal to 200 but smaller than 300.
|
||||
|
||||
#### response.redirected
|
||||
|
||||
<small>*(spec-compliant)*</small>
|
||||
|
||||
Convenience property representing if the request has been redirected at least once. Will evaluate to true if the internal redirect counter is greater than 0.
|
||||
|
||||
<a id="class-headers"></a>
|
||||
### Class: Headers
|
||||
|
||||
|
@ -510,17 +515,17 @@ An Error thrown when the request is aborted in response to an `AbortSignal`'s `a
|
|||
|
||||
Thanks to [github/fetch](https://github.com/github/fetch) for providing a solid implementation reference.
|
||||
|
||||
`node-fetch` v1 was maintained by [@bitinn](https://github.com/bitinn), v2 is currently maintained by [@TimothyGu](https://github.com/timothygu), v2 readme is written by [@jkantr](https://github.com/jkantr).
|
||||
`node-fetch` v1 was maintained by [@bitinn](https://github.com/bitinn); v2 was maintained by [@TimothyGu](https://github.com/timothygu), [@bitinn](https://github.com/bitinn) and [@jimmywarting](https://github.com/jimmywarting); v2 readme is written by [@jkantr](https://github.com/jkantr).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/node-fetch.svg?style=flat-square
|
||||
[npm-image]: https://flat.badgen.net/npm/v/node-fetch
|
||||
[npm-url]: https://www.npmjs.com/package/node-fetch
|
||||
[travis-image]: https://img.shields.io/travis/bitinn/node-fetch.svg?style=flat-square
|
||||
[travis-image]: https://flat.badgen.net/travis/bitinn/node-fetch
|
||||
[travis-url]: https://travis-ci.org/bitinn/node-fetch
|
||||
[codecov-image]: https://img.shields.io/codecov/c/github/bitinn/node-fetch.svg?style=flat-square
|
||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/node-fetch/master
|
||||
[codecov-url]: https://codecov.io/gh/bitinn/node-fetch
|
||||
[install-size-image]: https://flat.badgen.net/packagephobia/install/node-fetch
|
||||
[install-size-url]: https://packagephobia.now.sh/result?p=node-fetch
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-fetch",
|
||||
"version": "2.4.1",
|
||||
"version": "2.5.0",
|
||||
"description": "A light-weight module that brings window.fetch to node.js",
|
||||
"main": "lib/index",
|
||||
"browser": "./browser.js",
|
||||
|
|
|
@ -189,7 +189,8 @@ export default function fetch(url, opts) {
|
|||
statusText: res.statusMessage,
|
||||
headers: headers,
|
||||
size: request.size,
|
||||
timeout: request.timeout
|
||||
timeout: request.timeout,
|
||||
counter: request.counter
|
||||
};
|
||||
|
||||
// HTTP-network fetch step 12.1.1.3
|
||||
|
|
|
@ -40,7 +40,8 @@ export default class Response {
|
|||
url: opts.url,
|
||||
status,
|
||||
statusText: opts.statusText || STATUS_CODES[status],
|
||||
headers
|
||||
headers,
|
||||
counter: opts.counter
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -59,6 +60,10 @@ export default class Response {
|
|||
return this[INTERNALS].status >= 200 && this[INTERNALS].status < 300;
|
||||
}
|
||||
|
||||
get redirected() {
|
||||
return this[INTERNALS].counter > 0;
|
||||
}
|
||||
|
||||
get statusText() {
|
||||
return this[INTERNALS].statusText;
|
||||
}
|
||||
|
@ -78,9 +83,9 @@ export default class Response {
|
|||
status: this.status,
|
||||
statusText: this.statusText,
|
||||
headers: this.headers,
|
||||
ok: this.ok
|
||||
ok: this.ok,
|
||||
redirected: this.redirected
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,6 +95,7 @@ Object.defineProperties(Response.prototype, {
|
|||
url: { enumerable: true },
|
||||
status: { enumerable: true },
|
||||
ok: { enumerable: true },
|
||||
redirected: { enumerable: true },
|
||||
statusText: { enumerable: true },
|
||||
headers: { enumerable: true },
|
||||
clone: { enumerable: true }
|
||||
|
|
18
test/test.js
18
test/test.js
|
@ -489,6 +489,20 @@ describe('node-fetch', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should set redirected property on response when redirect', function() {
|
||||
const url = `${base}redirect/301`;
|
||||
return fetch(url).then(res => {
|
||||
expect(res.redirected).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it('should not set redirected property on response without redirect', function() {
|
||||
const url = `${base}hello`;
|
||||
return fetch(url).then(res => {
|
||||
expect(res.redirected).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore invalid headers', function() {
|
||||
var headers = {
|
||||
'Invalid-Header ': 'abc\r\n',
|
||||
|
@ -2196,12 +2210,12 @@ describe('Response', function () {
|
|||
}
|
||||
for (const toCheck of [
|
||||
'body', 'bodyUsed', 'arrayBuffer', 'blob', 'json', 'text',
|
||||
'url', 'status', 'ok', 'statusText', 'headers', 'clone'
|
||||
'url', 'status', 'ok', 'redirected', 'statusText', 'headers', 'clone'
|
||||
]) {
|
||||
expect(enumerableProperties).to.contain(toCheck);
|
||||
}
|
||||
for (const toCheck of [
|
||||
'body', 'bodyUsed', 'url', 'status', 'ok', 'statusText',
|
||||
'body', 'bodyUsed', 'url', 'status', 'ok', 'redirected', 'statusText',
|
||||
'headers'
|
||||
]) {
|
||||
expect(() => {
|
||||
|
|
Loading…
Reference in New Issue