How to use the urllib.USER_AGENT function in urllib

To help you get started, we’ve selected a few urllib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-modules / autod / index.js View on Github external
const debug = require('debug')('autod');
const assert = require('assert');
const glob = require('glob');
const path = require('path');
const fs = require('fs');
const readdir = require('fs-readdir-recursive');
const crequire = require('crequire');
const EventEmitter = require('events');
const co = require('co');
const urllib = require('urllib');
const semver = require('semver');

const DEFAULT_EXCLUDE = [ '.git', 'cov', 'coverage', '.vscode' ];
const DEFAULT_TEST = [ 'test', 'tests', 'test.js', 'benchmark', 'example', 'example.js' ];
const USER_AGENT = `autod@${require('./package').version} ${urllib.USER_AGENT}`;
const MODULE_REG = /^(@[0-9a-zA-Z\-\_][0-9a-zA-Z\.\-\_]*\/)?([0-9a-zA-Z\-\_][0-9a-zA-Z\.\-\_]*)/;


class Autod extends EventEmitter {
  constructor(options) {
    super();
    this.options = Object.assign({}, options);
    this.prepare();
  }

  prepare() {
    const options = this.options;
    assert(options.root, 'options.root required');
    // default options
    options.semver = options.semver || {};
    options.registry = options.registry || 'https://registry.npm.taobao.org';
github cnpm / cnpmjs.org / common / urllib.js View on Github external
timeout: 0,
    keepAliveTimeout: 15000
  });
  httpsAgent = new HttpsAgent({
    timeout: 0,
    keepAliveTimeout: 15000
  });
}

var client = urllib.create({
  agent: httpAgent,
  httpsAgent: httpsAgent
});

module.exports = client;
module.exports.USER_AGENT = urllib.USER_AGENT;
github cnpm / npminstall / lib / get.js View on Github external
module.exports = get;

const httpKeepaliveAgent = new HttpAgent({
  keepAlive: true,
  keepAliveMsecs: 30000,
  maxSockets: 10,
  maxFreeSockets: 10,
});
const httpsKeepaliveAgent = new HttpsAgent({
  keepAlive: true,
  keepAliveMsecs: 30000,
  maxSockets: 10,
  maxFreeSockets: 10,
});

const USER_AGENT = 'npminstall/' + require('../package.json').version + ' ' + urllib.USER_AGENT;
const MAX_RETRY = 5;

async function get(url, options, globalOptions) {
  options.httpsAgent = httpsKeepaliveAgent;
  options.agent = httpKeepaliveAgent;
  options.headers = options.headers || {};
  options.headers['User-Agent'] = USER_AGENT;
  if (globalOptions) {
    options.rejectUnauthorized = globalOptions.strictSSL;
    if (globalOptions.referer) {
      options.headers.Referer = globalOptions.referer;
    }
    if (globalOptions.proxy) {
      options.enableProxy = true;
      options.proxy = globalOptions.proxy;
      debug('enableProxy: %s', options.proxy);
github node-modules / autod / lib / autod.js View on Github external
}
    var scope = parsed[1];
    var name = parsed[2];
    if (scope) {
      name = scope + name;
    }
    modules.push(name);
    self.dependencyMap[name] = self.dependencyMap[name] || [];
    self.dependencyMap[name].push(filePath);
  });

  debug('file %s get modules %j', filePath, modules);
  return modules;
};

Autod.USER_AGENT = 'autod-check/' + pkg.version + ' ' + urllib.USER_AGENT;

/**
 * @api private
 */
Autod.prototype.requestNpmTag = function (name, tag, callback) {
  if (typeof tag === 'function') {
    callback = tag;
    tag = 'latest';
  }

  var url = this.registry + '/' + name + '/' + tag;
  var options = {
    headers: {
      'user-agent': Autod.USER_AGENT,
    },
    gzip: true,

urllib

Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. Base undici fetch API.

MIT
Latest version published 12 days ago

Package Health Score

86 / 100
Full package analysis