got
Advanced tools
Comparing version 11.1.3 to 11.1.4
import { RetryFunction } from './types'; | ||
declare const calculateRetryDelay: RetryFunction; | ||
declare type Returns<T extends (...args: any) => unknown, V> = (...args: Parameters<T>) => V; | ||
declare const calculateRetryDelay: Returns<RetryFunction, number>; | ||
export default calculateRetryDelay; |
@@ -42,2 +42,7 @@ "use strict"; | ||
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.isStream); | ||
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.responseType); | ||
// `options.responseType` | ||
if (options.responseType === undefined) { | ||
options.responseType = 'text'; | ||
} | ||
// `options.retry` | ||
@@ -44,0 +49,0 @@ const { retry } = options; |
@@ -54,3 +54,3 @@ "use strict"; | ||
globalRequest = request; | ||
request.once('response', async (response) => { | ||
const onResponse = async (response) => { | ||
response.retryCount = retryCount; | ||
@@ -130,4 +130,5 @@ if (response.request.aborted) { | ||
resolve(options.resolveBodyOnly ? response.body : response); | ||
}); | ||
request.once('error', (error) => { | ||
}; | ||
request.once('response', onResponse); | ||
request.once('error', async (error) => { | ||
if (promise.isCanceled) { | ||
@@ -140,6 +141,7 @@ return; | ||
} | ||
request.off('response', onResponse); | ||
let backoff; | ||
retryCount++; | ||
try { | ||
backoff = options.retry.calculateDelay({ | ||
backoff = await options.retry.calculateDelay({ | ||
attemptCount: retryCount, | ||
@@ -187,3 +189,4 @@ retryOptions: options.retry, | ||
if (error instanceof types_1.HTTPError) { | ||
// It will be handled by the `response` event | ||
// The error will be handled by the `response` event | ||
onResponse(request._response); | ||
return; | ||
@@ -190,0 +193,0 @@ } |
@@ -16,3 +16,3 @@ /// <reference types="node" /> | ||
} | ||
export declare type RetryFunction = (retryObject: RetryObject) => number; | ||
export declare type RetryFunction = (retryObject: RetryObject) => number | Promise<number>; | ||
export interface RequiredRetryOptions { | ||
@@ -19,0 +19,0 @@ limit: number; |
@@ -7,3 +7,3 @@ /// <reference types="node" /> | ||
import http = require('http'); | ||
import { ClientRequest, RequestOptions, IncomingMessage, ServerResponse, request as httpRequest } from 'http'; | ||
import { ClientRequest, RequestOptions, ServerResponse, request as httpRequest } from 'http'; | ||
import https = require('https'); | ||
@@ -69,3 +69,3 @@ import { Timings, IncomingMessageWithTimings } from '@szmarczak/http-timer'; | ||
export declare const knownHookEvents: HookEvent[]; | ||
declare type AcceptableResponse = IncomingMessage | ResponseLike; | ||
declare type AcceptableResponse = IncomingMessageWithTimings | ResponseLike; | ||
declare type AcceptableRequestResult = AcceptableResponse | ClientRequest | Promise<AcceptableResponse | ClientRequest> | undefined; | ||
@@ -254,4 +254,4 @@ export declare type RequestFunction = (url: URL, options: RequestOptions, callback?: (response: AcceptableResponse) => void) => AcceptableRequestResult; | ||
[kResponseSize]?: number; | ||
[kResponse]?: IncomingMessage; | ||
[kOriginalResponse]?: IncomingMessage; | ||
[kResponse]?: IncomingMessageWithTimings; | ||
[kOriginalResponse]?: IncomingMessageWithTimings; | ||
[kRequest]?: ClientRequest; | ||
@@ -269,3 +269,3 @@ _noPipe?: boolean; | ||
_finalizeBody(): Promise<void>; | ||
_onResponse(response: IncomingMessage): Promise<void>; | ||
_onResponse(response: IncomingMessageWithTimings): Promise<void>; | ||
_onRequest(request: ClientRequest): void; | ||
@@ -287,2 +287,3 @@ _createCacheableRequest(url: URL, options: RequestOptions): Promise<ClientRequest | ResponseLike>; | ||
get isFromCache(): boolean | undefined; | ||
get _response(): Response | undefined; | ||
pipe<T extends NodeJS.WritableStream>(destination: T, options?: { | ||
@@ -289,0 +290,0 @@ end?: boolean; |
@@ -11,5 +11,5 @@ "use strict"; | ||
const http_timer_1 = require("@szmarczak/http-timer"); | ||
const decompressResponse = require("decompress-response"); | ||
const cacheable_lookup_1 = require("cacheable-lookup"); | ||
const CacheableRequest = require("cacheable-request"); | ||
const decompressResponse = require("decompress-response"); | ||
// @ts-ignore Missing types | ||
@@ -333,2 +333,3 @@ const http2wrapper = require("http2-wrapper"); | ||
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.rejectUnauthorized); | ||
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.localAddress); | ||
// `options.method` | ||
@@ -419,8 +420,2 @@ if (is_1.default.string(options.method)) { | ||
} | ||
// Trigger search params normalization | ||
if (options.url.search) { | ||
const triggerSearchParameters = '_GOT_INTERNAL_TRIGGER_NORMALIZATION'; | ||
options.url.searchParams.append(triggerSearchParameters, ''); | ||
options.url.searchParams.delete(triggerSearchParameters); | ||
} | ||
// Protocol check | ||
@@ -472,3 +467,3 @@ if (protocol !== 'http:' && protocol !== 'https:') { | ||
} | ||
else if (!is_1.default.undefined(options.dnsCache) && !(options.dnsCache instanceof cacheable_lookup_1.default)) { | ||
else if (!is_1.default.undefined(options.dnsCache) && !options.dnsCache.lookup) { | ||
throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is_1.default(options.dnsCache)}`); | ||
@@ -706,4 +701,5 @@ } | ||
try { | ||
// Do not remove. See https://github.com/sindresorhus/got/pull/214 | ||
const redirectBuffer = Buffer.from(response.headers.location, 'binary').toString(); | ||
// Handles invalid URLs. See https://github.com/sindresorhus/got/issues/604 | ||
const redirectBuffer = Buffer.from(response.headers.location, 'binary').toString(); | ||
const redirectUrl = new url_1.URL(redirectBuffer, url); | ||
@@ -840,2 +836,4 @@ const redirectString = redirectUrl.toString(); | ||
const { req } = typedResponse; | ||
// TODO: Fix `cacheable-response` | ||
typedResponse._readableState.autoDestroy = false; | ||
if (req) { | ||
@@ -1039,2 +1037,6 @@ req.emit('cacheableResponse', typedResponse); | ||
} | ||
if (this[kRequest].destroyed) { | ||
callback(); | ||
return; | ||
} | ||
this[kRequest].end((error) => { | ||
@@ -1124,2 +1126,5 @@ if (!error) { | ||
} | ||
get _response() { | ||
return this[kResponse]; | ||
} | ||
pipe(destination, options) { | ||
@@ -1126,0 +1131,0 @@ if (this[kStartedReading]) { |
@@ -63,2 +63,3 @@ "use strict"; | ||
})); | ||
// Got interface | ||
const got = ((url, options) => { | ||
@@ -132,3 +133,4 @@ var _a, _b; | ||
}; | ||
got.paginate = (async function* (url, options) { | ||
// Pagination | ||
const paginateEach = (async function* (url, options) { | ||
let normalizedOptions = normalizeArguments(url, options, defaults.options); | ||
@@ -178,2 +180,5 @@ normalizedOptions.resolveBodyOnly = false; | ||
}); | ||
got.paginate = ((url, options) => { | ||
return paginateEach(url, options); | ||
}); | ||
got.paginate.all = (async (url, options) => { | ||
@@ -186,3 +191,7 @@ const results = []; | ||
}); | ||
// For those who like very descriptive names | ||
got.paginate.each = paginateEach; | ||
// Stream API | ||
got.stream = ((url, options) => got(url, { ...options, isStream: true })); | ||
// Shortcuts | ||
for (const method of aliases) { | ||
@@ -189,0 +198,0 @@ got[method] = ((url, options) => got(url, { ...options, method })); |
@@ -45,4 +45,6 @@ /// <reference types="node" /> | ||
<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>; | ||
<T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>; | ||
each<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>; | ||
each<T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>; | ||
all<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>): Promise<T[]>; | ||
<T, R = unknown>(options?: OptionsWithPagination<T, R>): AsyncIterableIterator<T>; | ||
all<T, R = unknown>(options?: OptionsWithPagination<T, R>): Promise<T[]>; | ||
@@ -49,0 +51,0 @@ } |
{ | ||
"name": "got", | ||
"version": "11.1.3", | ||
"version": "11.1.4", | ||
"description": "Human-friendly and powerful HTTP request library for Node.js", | ||
@@ -50,5 +50,5 @@ "license": "MIT", | ||
"@types/responselike": "^1.0.0", | ||
"cacheable-lookup": "^4.3.0", | ||
"cacheable-lookup": "^5.0.3", | ||
"cacheable-request": "^7.0.1", | ||
"decompress-response": "^5.0.0", | ||
"decompress-response": "^6.0.0", | ||
"get-stream": "^5.1.0", | ||
@@ -63,5 +63,5 @@ "http2-wrapper": "^1.0.0-beta.4.5", | ||
"@sindresorhus/tsconfig": "^0.7.0", | ||
"@sinonjs/fake-timers": "^6.0.1", | ||
"@types/benchmark": "^1.0.31", | ||
"@types/express": "^4.17.6", | ||
"@types/lolex": "^5.1.0", | ||
"@types/node": "^13.13.4", | ||
@@ -81,3 +81,2 @@ "@types/node-fetch": "^2.5.5", | ||
"form-data": "^3.0.0", | ||
"lolex": "^6.0.0", | ||
"nock": "^12.0.0", | ||
@@ -131,3 +130,4 @@ "node-fetch": "^2.6.0", | ||
} | ||
} | ||
}, | ||
"runkitExampleFilename": "./documentation/examples/runkit-example.js" | ||
} |
Sorry, the diff of this file is too big to display
184190
31
2814
1943
+ Addedcacheable-lookup@5.0.4(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addedmimic-response@3.1.0(transitive)
- Removedcacheable-lookup@4.3.0(transitive)
- Removeddecompress-response@5.0.0(transitive)
- Removedmimic-response@2.1.0(transitive)
Updatedcacheable-lookup@^5.0.3
Updateddecompress-response@^6.0.0