chore: updated dependencies

This commit is contained in:
SethCohen
2023-09-23 12:37:35 -04:00
parent f228faeb5e
commit 24b80abb6f
25 changed files with 124 additions and 92 deletions
+3 -2
View File
@@ -147,7 +147,7 @@ export type RequestRedirect = 'error' | 'follow' | 'manual';
export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
export type RequestInfo = string | Request;
export class Request extends BodyMixin {
constructor(input: RequestInfo, init?: RequestInit);
constructor(input: URL | RequestInfo, init?: RequestInit);
/**
* Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header.
@@ -196,6 +196,7 @@ export class Response extends BodyMixin {
static error(): Response;
static redirect(url: string, status?: number): Response;
static json(data: any, init?: ResponseInit): Response;
}
export class FetchError extends Error {
@@ -215,4 +216,4 @@ export class AbortError extends Error {
}
export function isRedirect(code: number): boolean;
export default function fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
export default function fetch(url: URL | RequestInfo, init?: RequestInit): Promise<Response>;
+6 -5
View File
@@ -269,8 +269,8 @@ It is common to create a helper function to check that the response contains no
import fetch from 'node-fetch';
class HTTPResponseError extends Error {
constructor(response, ...args) {
super(`HTTP Error Response: ${response.status} ${response.statusText}`, ...args);
constructor(response) {
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
this.response = response;
}
}
@@ -400,7 +400,7 @@ console.log(response.headers.raw()['set-cookie']);
### Post data using a file
```js
import fetch {
import fetch, {
Blob,
blobFrom,
blobFromSync,
@@ -539,7 +539,6 @@ If no values are set, the following request headers will be sent automatically:
| ------------------- | ------------------------------------------------------ |
| `Accept-Encoding` | `gzip, deflate, br` (when `options.compress === true`) |
| `Accept` | `*/*` |
| `Connection` | `close` _(when no `options.agent` is present)_ |
| `Content-Length` | _(automatically calculated, if possible)_ |
| `Host` | _(host and port information from the target URI)_ |
| `Transfer-Encoding` | `chunked` _(when `req.body` is a stream)_ |
@@ -558,6 +557,8 @@ The `agent` option allows you to specify networking related options which are ou
See [`http.Agent`](https://nodejs.org/api/http.html#http_new_agent_options) for more information.
If no agent is specified, the default agent provided by Node.js is used. Note that [this changed in Node.js 19](https://github.com/nodejs/node/blob/4267b92604ad78584244488e7f7508a690cb80d0/lib/_http_agent.js#L564) to have `keepalive` true by default. If you wish to enable `keepalive` in an earlier version of Node.js, you can override the agent as per the following code sample.
In addition, the `agent` option accepts a function that returns `http`(s)`.Agent` instance given current [URL](https://nodejs.org/api/url.html), this is useful during a redirection chain across HTTP and HTTPS protocol.
```js
@@ -627,7 +628,7 @@ results in an [opaque-redirect filtered response](https://fetch.spec.whatwg.org/
node-fetch gives you the typical [basic filtered response](https://fetch.spec.whatwg.org/#concept-filtered-response-basic) instead.
```js
const fetch = require('node-fetch');
import fetch from 'node-fetch';
const response = await fetch('https://httpbin.org/status/301', { redirect: 'manual' });
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "node-fetch",
"version": "3.2.10",
"version": "3.3.2",
"description": "A light-weight module that brings Fetch API to node.js",
"main": "./src/index.js",
"sideEffects": false,
-4
View File
@@ -288,10 +288,6 @@ export const getNodeRequestOptions = request => {
agent = agent(parsedURL);
}
if (!headers.has('Connection') && !agent) {
headers.set('Connection', 'close');
}
// HTTP-network fetch step 4.2
// chunked encoding is handled by Node.js
+19
View File
@@ -124,6 +124,25 @@ export default class Response extends Body {
return response;
}
static json(data = undefined, init = {}) {
const body = JSON.stringify(data);
if (body === undefined) {
throw new TypeError('data is not JSON serializable');
}
const headers = new Headers(init && init.headers);
if (!headers.has('content-type')) {
headers.set('content-type', 'application/json');
}
return new Response(body, {
...init,
headers
});
}
get [Symbol.toStringTag]() {
return 'Response';
}