MCPcopy
hub / github.com/Kong/insomnia / request

Method request

packages/insomnia/bin/yarn-standalone.js:32386–32447  ·  view source on GitHub ↗
(pathname, opts = {}, packageName)

Source from the content-addressed store, hash-verified

32384 }
32385
32386 request(pathname, opts = {}, packageName) {
32387 var _this = this;
32388
32389 return (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function* () {
32390 // packageName needs to be escaped when if it is passed
32391 const packageIdent = packageName && NpmRegistry.escapeName(packageName) || pathname;
32392 const registry = opts.registry || _this.getRegistry(packageIdent);
32393 const requestUrl = _this.getRequestUrl(registry, pathname);
32394
32395 const alwaysAuth = _this.getRegistryOrGlobalOption(registry, 'always-auth');
32396
32397 const headers = (0, (_extends2 || _load_extends()).default)({
32398 Accept:
32399 // This is to use less bandwidth unless we really need to get the full response.
32400 // See https://github.com/npm/npm-registry-client#requests
32401 opts.unfiltered ? 'application/json' : 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
32402 }, opts.headers);
32403
32404 const isToRegistry = _this.isRequestToRegistry(requestUrl, registry) || _this.requestNeedsAuth(requestUrl);
32405
32406 // this.token must be checked to account for publish requests on non-scoped packages
32407 if (_this.token || isToRegistry && (alwaysAuth || _this.isScopedPackage(packageIdent))) {
32408 const authorization = _this.getAuth(packageIdent);
32409 if (authorization) {
32410 headers.authorization = authorization;
32411 }
32412 }
32413
32414 if (_this.otp) {
32415 headers['npm-otp'] = _this.otp;
32416 }
32417
32418 try {
32419 return yield _this.requestManager.request({
32420 url: requestUrl,
32421 method: opts.method,
32422 body: opts.body,
32423 auth: opts.auth,
32424 headers,
32425 json: !opts.buffer,
32426 buffer: opts.buffer,
32427 process: opts.process,
32428 gzip: true
32429 });
32430 } catch (error) {
32431 if (error instanceof (_errors || _load_errors()).OneTimePasswordError) {
32432 if (_this.otp) {
32433 throw new (_errors || _load_errors()).MessageError(_this.reporter.lang('incorrectOneTimePassword'));
32434 }
32435
32436 _this.reporter.info(_this.reporter.lang('twoFactorAuthenticationEnabled'));
32437 _this.otp = yield (0, (_login || _load_login()).getOneTimePassword)(_this.reporter);
32438
32439 _this.requestManager.clearCache();
32440
32441 return _this.request(pathname, opts, packageName);
32442 } else {
32443 throw error;

Callers 14

install-plugin.tsFile · 0.45
_checkUpdateMethod · 0.45
checkOutdatedMethod · 0.45
yarn-standalone.jsFile · 0.45
getRefOverHTTPMethod · 0.45
resolveOverHTTPMethod · 0.45
hasHTTPCapabilityMethod · 0.45
resolveRequestMethod · 0.45
_fetchAuditMethod · 0.45
addFunction · 0.45
fetchFromExternalMethod · 0.45
fetchBundleFunction · 0.45

Calls 15

_load_asyncToGeneratorFunction · 0.85
_load_extendsFunction · 0.85
_load_errorsFunction · 0.85
_load_loginFunction · 0.85
escapeNameMethod · 0.80
getRegistryMethod · 0.80
getRequestUrlMethod · 0.80
isRequestToRegistryMethod · 0.80
requestNeedsAuthMethod · 0.80
isScopedPackageMethod · 0.80
getAuthMethod · 0.80

Tested by

no test coverage detected