Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dguyonvarch authored and guyonvarch-d committed Nov 27, 2018
0 parents commit 9cf72c5
Show file tree
Hide file tree
Showing 11 changed files with 2,772 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
"indent": ["error", 2],
"quotes": ["error", "single"]
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.nyc_output/
.vscode/
coverage/
node_modules/
yarn.lock
Empty file added .npmrc
Empty file.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: node_js
node_js:
- "8"
cache:
-node_modules
install:
- npm ci
- npm run lint
script:
- npm run test
after_script:
- npm install coveralls && cat ./coverage/lcov.info | coveralls
deploy:
provider: npm
on:
tags: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 MGDIS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const debug = require('debug')('got-proxy');
const URL = require('url');
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
const tunnel = require('tunnel-agent');

function getAgent(url) {
let agent;
const proxyUrl = getProxyForUrl(url);
if (proxyUrl) {
debug(`Using proxy ${proxyUrl} for ${url}`);
const parsedUrl = URL.parse(url);
const tunnelUrlProtocol = parsedUrl.protocol === 'https:' ? 'https' : 'http';
const parsedProxyUrl = URL.parse(proxyUrl);
const tunnelProxyProtocol = parsedProxyUrl.protocol === 'https:' ? 'Https' : 'Http';
const method = `${tunnelUrlProtocol}Over${tunnelProxyProtocol}`;
agent = tunnel[method];
}
return agent;
}

module.exports = getAgent;
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

const got = require('got');
const gotAgent = require('./agent');

function gotWrapper(url, options) {
if (!options || !options.agent) options.agent = gotAgent(url);
return got(url, options);
}

module.exports = gotWrapper;

0 comments on commit 9cf72c5

Please sign in to comment.