130 lines
3.9 KiB
JavaScript
130 lines
3.9 KiB
JavaScript
"use strict";
|
|
function __export(m) {
|
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
}
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const url_1 = require("url");
|
|
const create_1 = require("./create");
|
|
const defaults = {
|
|
options: {
|
|
method: 'GET',
|
|
retry: {
|
|
limit: 2,
|
|
methods: [
|
|
'GET',
|
|
'PUT',
|
|
'HEAD',
|
|
'DELETE',
|
|
'OPTIONS',
|
|
'TRACE'
|
|
],
|
|
statusCodes: [
|
|
408,
|
|
413,
|
|
429,
|
|
500,
|
|
502,
|
|
503,
|
|
504,
|
|
521,
|
|
522,
|
|
524
|
|
],
|
|
errorCodes: [
|
|
'ETIMEDOUT',
|
|
'ECONNRESET',
|
|
'EADDRINUSE',
|
|
'ECONNREFUSED',
|
|
'EPIPE',
|
|
'ENOTFOUND',
|
|
'ENETUNREACH',
|
|
'EAI_AGAIN'
|
|
],
|
|
maxRetryAfter: undefined,
|
|
calculateDelay: ({ computedValue }) => computedValue
|
|
},
|
|
timeout: {},
|
|
headers: {
|
|
'user-agent': 'got (https://github.com/sindresorhus/got)'
|
|
},
|
|
hooks: {
|
|
init: [],
|
|
beforeRequest: [],
|
|
beforeRedirect: [],
|
|
beforeRetry: [],
|
|
beforeError: [],
|
|
afterResponse: []
|
|
},
|
|
decompress: true,
|
|
throwHttpErrors: true,
|
|
followRedirect: true,
|
|
isStream: false,
|
|
cache: false,
|
|
dnsCache: false,
|
|
useElectronNet: false,
|
|
responseType: 'text',
|
|
resolveBodyOnly: false,
|
|
maxRedirects: 10,
|
|
prefixUrl: '',
|
|
methodRewriting: true,
|
|
allowGetBody: false,
|
|
ignoreInvalidCookies: false,
|
|
context: {},
|
|
_pagination: {
|
|
transform: (response) => {
|
|
if (response.request.options.responseType === 'json') {
|
|
return response.body;
|
|
}
|
|
return JSON.parse(response.body);
|
|
},
|
|
paginate: response => {
|
|
if (!Reflect.has(response.headers, 'link')) {
|
|
return false;
|
|
}
|
|
const items = response.headers.link.split(',');
|
|
let next;
|
|
for (const item of items) {
|
|
const parsed = item.split(';');
|
|
if (parsed[1].includes('next')) {
|
|
next = parsed[0].trimStart().trim();
|
|
next = next.slice(1, -1);
|
|
break;
|
|
}
|
|
}
|
|
if (next) {
|
|
const options = {
|
|
url: new url_1.URL(next)
|
|
};
|
|
return options;
|
|
}
|
|
return false;
|
|
},
|
|
filter: () => true,
|
|
shouldContinue: () => true,
|
|
countLimit: Infinity
|
|
}
|
|
},
|
|
handlers: [create_1.defaultHandler],
|
|
mutableDefaults: false
|
|
};
|
|
const got = create_1.default(defaults);
|
|
exports.default = got;
|
|
// For CommonJS default export support
|
|
module.exports = got;
|
|
module.exports.default = got;
|
|
// Export types
|
|
__export(require("./types"));
|
|
var as_stream_1 = require("./as-stream");
|
|
exports.ResponseStream = as_stream_1.ProxyStream;
|
|
var errors_1 = require("./errors");
|
|
exports.GotError = errors_1.GotError;
|
|
exports.CacheError = errors_1.CacheError;
|
|
exports.RequestError = errors_1.RequestError;
|
|
exports.ReadError = errors_1.ReadError;
|
|
exports.ParseError = errors_1.ParseError;
|
|
exports.HTTPError = errors_1.HTTPError;
|
|
exports.MaxRedirectsError = errors_1.MaxRedirectsError;
|
|
exports.UnsupportedProtocolError = errors_1.UnsupportedProtocolError;
|
|
exports.TimeoutError = errors_1.TimeoutError;
|
|
exports.CancelError = errors_1.CancelError;
|