Socket
Socket
Sign inDemoInstall

got

Package Overview
Dependencies
Maintainers
2
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

got - npm Package Compare versions

Comparing version 12.4.1 to 12.5.0

7

dist/source/core/index.d.ts

@@ -6,12 +6,8 @@ /// <reference types="node" />

/// <reference types="node" />
/// <reference types="node" />
import { Duplex } from 'node:stream';
import { URL } from 'node:url';
import { ServerResponse } from 'node:http';
import type { ClientRequest } from 'node:http';
import type { Socket } from 'node:net';
import CacheableRequest from 'cacheable-request';
import type { Timings } from '@szmarczak/http-timer';
import type ResponseLike from 'responselike';
import Options, { type NativeRequestOptions } from './options.js';
import Options from './options.js';
import { type PlainResponse, type Response } from './response.js';

@@ -91,3 +87,2 @@ import { RequestError } from './errors.js';

};
export declare type CacheableRequestFunction = (options: string | URL | NativeRequestOptions, cb?: (response: ServerResponse | ResponseLike) => void) => CacheableRequest.Emitter;
declare type UrlType = ConstructorParameters<typeof Options>[0];

@@ -94,0 +89,0 @@ declare type OptionsType = ConstructorParameters<typeof Options>[1];

18

dist/source/core/index.js

@@ -7,3 +7,3 @@ import process from 'node:process';

import timer from '@szmarczak/http-timer';
import CacheableRequest from 'cacheable-request';
import CacheableRequest, { CacheError as CacheableCacheError, } from 'cacheable-request';
import decompressResponse from 'decompress-response';

@@ -435,3 +435,2 @@ import is from '@sindresorhus/is';

}
// The `!destroyed` check is required to prevent `uploadProgress` being emitted after the stream was destroyed
if (!error) {

@@ -633,6 +632,6 @@ this._bodySize = this._uploadedSize;

const updatedOptions = new Options(undefined, undefined, this.options);
const shouldBeGet = statusCode === 303 && updatedOptions.method !== 'GET' && updatedOptions.method !== 'HEAD';
if (shouldBeGet || updatedOptions.methodRewriting) {
// Server responded with "see other", indicating that the resource exists at another location,
// and the client should request it from that location via GET or HEAD.
const serverRequestedGet = statusCode === 303 && updatedOptions.method !== 'GET' && updatedOptions.method !== 'HEAD';
const canRewrite = statusCode !== 307 && statusCode !== 308;
const userRequestedGet = updatedOptions.methodRewriting && canRewrite;
if (serverRequestedGet || userRequestedGet) {
updatedOptions.method = 'GET';

@@ -827,3 +826,3 @@ updatedOptions.body = undefined;

if (!cacheableStore.has(cache)) {
cacheableStore.set(cache, new CacheableRequest(((requestOptions, handler) => {
const cacheableRequest = new CacheableRequest(((requestOptions, handler) => {
const result = requestOptions._request(requestOptions, handler);

@@ -866,3 +865,4 @@ // TODO: remove this when `cacheable-request` supports async request functions.

return result;
}), cache));
}), cache);
cacheableStore.set(cache, cacheableRequest.request());
}

@@ -976,3 +976,3 @@ }

catch (error) {
if (error instanceof CacheableRequest.CacheError) {
if (error instanceof CacheableCacheError) {
throw new CacheError(error, this);

@@ -979,0 +979,0 @@ }

@@ -23,3 +23,3 @@ /// <reference types="node" />

import type { FormDataLike } from 'form-data-encoder';
import type CacheableRequest from 'cacheable-request';
import type { StorageAdapter } from 'cacheable-request';
import type ResponseLike from 'responselike';

@@ -851,3 +851,3 @@ import type { IncomingMessageWithTimings } from '@szmarczak/http-timer';

Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), Got will automatically request the resource pointed to in the location header via `GET`.
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4). You can optionally turn on this behavior also for other redirect codes - see `methodRewriting`.

@@ -872,4 +872,4 @@ @default true

*/
get cache(): string | CacheableRequest.StorageAdapter | boolean | undefined;
set cache(value: string | CacheableRequest.StorageAdapter | boolean | undefined);
get cache(): string | StorageAdapter | boolean | undefined;
set cache(value: string | StorageAdapter | boolean | undefined);
/**

@@ -917,3 +917,3 @@ Determines if a `got.HTTPError` is thrown for unsuccessful responses.

__Note__: The [RFC 7321](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.
__Note__: The [RFC 7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.

@@ -934,6 +934,9 @@ @default false

/**
Specifies if the redirects should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4).
Specifies if the HTTP request method should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4) on redirects.
If `false`, when sending a POST request and receiving a `302`, it will resend the body to the new location using the same HTTP method (`POST` in this case).
As the [specification](https://tools.ietf.org/html/rfc7231#section-6.4) prefers to rewrite the HTTP method only on `303` responses, this is Got's default behavior.
Setting `methodRewriting` to `true` will also rewrite `301` and `302` responses, as allowed by the spec. This is the behavior followed by `curl` and browsers.
__Note__: Got never performs method rewriting on `307` and `308` responses, as this is [explicitly prohibited by the specification](https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7).
@default false

@@ -1168,3 +1171,3 @@ */

maxRedirects: number;
cache: string | boolean | CacheableRequest.StorageAdapter | undefined;
cache: string | boolean | StorageAdapter | undefined;
throwHttpErrors: boolean;

@@ -1171,0 +1174,0 @@ http2: boolean;

@@ -1007,3 +1007,3 @@ import process from 'node:process';

Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), Got will automatically request the resource pointed to in the location header via `GET`.
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).
This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4). You can optionally turn on this behavior also for other redirect codes - see `methodRewriting`.

@@ -1137,3 +1137,3 @@ @default true

__Note__: The [RFC 7321](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.
__Note__: The [RFC 7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.

@@ -1169,6 +1169,9 @@ @default false

/**
Specifies if the redirects should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4).
Specifies if the HTTP request method should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4) on redirects.
If `false`, when sending a POST request and receiving a `302`, it will resend the body to the new location using the same HTTP method (`POST` in this case).
As the [specification](https://tools.ietf.org/html/rfc7231#section-6.4) prefers to rewrite the HTTP method only on `303` responses, this is Got's default behavior.
Setting `methodRewriting` to `true` will also rewrite `301` and `302` responses, as allowed by the spec. This is the behavior followed by `curl` and browsers.
__Note__: Got never performs method rewriting on `307` and `308` responses, as this is [explicitly prohibited by the specification](https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7).
@default false

@@ -1175,0 +1178,0 @@ */

{
"name": "got",
"version": "12.4.1",
"version": "12.5.0",
"description": "Human-friendly and powerful HTTP request library for Node.js",

@@ -50,7 +50,6 @@ "license": "MIT",

"@szmarczak/http-timer": "^5.0.1",
"@types/cacheable-request": "^6.0.2",
"cacheable-lookup": "^6.0.4",
"cacheable-request": "^7.0.2",
"cacheable-request": "^10.1.2",
"decompress-response": "^6.0.0",
"form-data-encoder": "^2.1.0",
"form-data-encoder": "^2.1.2",
"get-stream": "^6.0.1",

@@ -64,3 +63,3 @@ "http2-wrapper": "^2.1.10",

"@hapi/bourne": "^3.0.0",
"@sindresorhus/tsconfig": "^2.0.0",
"@sindresorhus/tsconfig": "^3.0.1",
"@sinonjs/fake-timers": "^9.1.1",

@@ -77,3 +76,3 @@ "@types/benchmark": "^2.1.2",

"@types/tough-cookie": "^4.0.1",
"ava": "^3.15.0",
"ava": "^4.3.3",
"axios": "^0.27.2",

@@ -89,3 +88,3 @@ "benchmark": "^2.1.4",

"form-data": "^4.0.0",
"formdata-node": "^4.3.2",
"formdata-node": "^5.0.0",
"nock": "^13.2.4",

@@ -103,6 +102,7 @@ "node-fetch": "^3.2.3",

"tempy": "^3.0.0",
"then-busboy": "^5.1.1",
"then-busboy": "^5.2.1",
"to-readable-stream": "^3.0.0",
"tough-cookie": "4.0.0",
"ts-node": "^10.8.2",
"type-fest": "^2.19.0",
"typescript": "~4.8.2",

@@ -117,6 +117,2 @@ "xo": "^0.52.2"

"timeout": "1m",
"nonSemVerExperiments": {
"nextGenConfig": true,
"configurableModuleFormat": true
},
"extensions": {

@@ -123,0 +119,0 @@ "ts": "module"

@@ -40,11 +40,2 @@ <div align="center">

<br>
<a href="https://keygen.sh">
<div>
<img src="https://sindresorhus.com/assets/thanks/keygen-logo.svg" width="180" alt="Keygen">
</div>
<b>A dead-simple software licensing and distribution API built for developers</b>
</a>
<br>
<br>
<br>
<a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-light-mode-only">

@@ -80,4 +71,18 @@ <div>

<br>
<a href="https://sizzy.co/?utm_campaign=github_repo&utm_source=github&utm_medium=referral&utm_content=got&utm_term=sindre">
<div>
<img src="https://sindresorhus.com/assets/thanks/sizzy-logo.png" width="240" alt="Sizzy">
</div>
<div>
<sub>
<b>Before Sizzy:</b> web development is stressing you out, responsive design is hard, you have an overwhelming amount of opened tabs & apps.
<br>
<b>After Sizzy:</b> all the tools you need in one place, responsive design is a breeze, no more context switching.
</sub>
</div>
</a>
<br>
<br>
<br>
<br>
</p>

@@ -84,0 +89,0 @@ <br>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc