Skip to content

Commit f4006dc

Browse files
authored
Merge pull request #2 from journeyapps/updates
Updates
2 parents 76b391b + 8e8d3a2 commit f4006dc

10 files changed

Lines changed: 162 additions & 92 deletions

File tree

.circleci/config.yml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
version: 2
22
jobs:
3-
build:
3+
build_8:
44
docker:
5-
- image: circleci/node:8.11.4
5+
- image: circleci/node:8.17.0
66
steps:
77
- checkout
88
- run: echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
9-
- restore_cache:
10-
keys:
11-
- modules-{{ checksum "yarn.lock" }}
12-
- run: yarn install --check-files --frozen-lockfile
13-
- save_cache:
14-
key: modules-{{ checksum "yarn.lock" }}
15-
paths:
16-
- node_modules
9+
- run: yarn install --frozen-lockfile || yarn install --frozen-lockfile || yarn install --frozen-lockfile
1710
- run: yarn run build
1811
- run: yarn run test
12+
13+
build_10:
14+
docker:
15+
- image: circleci/node:10.18.1
16+
steps:
17+
- checkout
18+
- run: echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
19+
- run: yarn install --frozen-lockfile || yarn install --frozen-lockfile || yarn install --frozen-lockfile
20+
- run: yarn run build
21+
- run: yarn run test
22+
23+
build_12:
24+
docker:
25+
- image: circleci/node:12.14.1
26+
steps:
27+
- checkout
28+
- run: echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
29+
- run: yarn install --frozen-lockfile || yarn install --frozen-lockfile || yarn install --frozen-lockfile
30+
- run: yarn run build
31+
- run: yarn run test
32+
1933
publish:
2034
docker:
21-
- image: circleci/node:8.11.4
35+
- image: circleci/node:12.14.1
2236
steps:
2337
- checkout
2438
- run: echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
25-
- restore_cache:
26-
keys:
27-
- modules-{{ checksum "yarn.lock" }}
28-
- run: yarn install --check-files --frozen-lockfile
29-
- save_cache:
30-
key: modules-{{ checksum "yarn.lock" }}
31-
paths:
32-
- node_modules
39+
- run: yarn install --frozen-lockfile || yarn install --frozen-lockfile || yarn install --frozen-lockfile
3340
- run: yarn run build
3441
- run: ./node_modules/.bin/journey-deploy execute
3542

3643
workflows:
3744
version: 2
38-
build_and_publish:
45+
build:
3946
jobs:
40-
- build:
41-
filters:
42-
branches:
43-
only: /.*/
44-
ignore: /.*deploy-cli.*/
45-
tags:
46-
only: /.*/
47-
ignore: /.*dev.*/
47+
- build_8
48+
- build_10
49+
- build_12

LICENSE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 Journey Mobile, Inc.
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,47 @@ but adapted to expose raw Sockets, instead of just http/https requests.
99

1010
yarn add @journeyapps/https-proxy-socket
1111

12-
## Usage
13-
12+
## Usage - node-fetch
1413

1514
const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
16-
const proxy = new HttpsProxySocket({
17-
// Connection options
18-
host: 'my-proxy.test',
19-
port: 443
20-
}, {
21-
auth: 'myuser:mypassword' // Optional: proxy basic auth
15+
const fetch = require('node-fetch');
16+
17+
// Proxy connection options
18+
const proxy = new HttpsProxySocket('https://my-proxy.test', {
19+
// Proxy auth and headers may be set here, for example:
20+
auth: 'myuser:mypassword' // Basic auth
2221
});
2322

24-
const socket = await proxy.connect({host: 'myhost.test', port: 1234});
23+
const agent = proxy.agent({
24+
// Additional TLS options for the host may be set here, for example:
25+
// rejectUnauthorized: false, // Disable TLS checks completely (dangerous)
26+
// ca: fs.readFileSync('my-ca-cert.pem') // Use a custom CA cert
27+
28+
// Documentation of the available options is available here:
29+
// https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
30+
// https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
31+
});
2532

26-
## Usage with mssql
33+
const response = await fetch('https://myhost.test', { agent: agent });
34+
35+
## Usage - Direct socket
36+
37+
const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
38+
const proxy = new HttpsProxySocket('https://my-proxy.test');
39+
40+
const socket = await proxy.connect({host: 'myhost.test', port: 1234});
2741

42+
## Usage - mssql
2843

2944
const sql = require('mssql')
30-
const { useProxy } = require('@journeyapps/https-proxy-socket/lib/TediousPatch');
45+
const { HttpsProxySocket, useProxyForTedious } = require('@journeyapps/https-proxy-socket');
3146

32-
const { HttpsProxySocket } = require('./lib/HttpsProxySocket');
3347
const proxy = new HttpsProxySocket({
3448
// Same as above
3549
});
3650

3751
// Register the proxy globally for tedious/mssql
38-
useProxy(proxy);
52+
useProxyForTedious(proxy);
3953

4054
async function run() {
4155
// Connect using the proxy

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"name": "@journeyapps/https-proxy-socket",
3-
"version": "0.0.1",
3+
"version": "0.2.0",
44
"author": "JourneyApps",
5+
"repository": "journeyapps/https-proxy-socket",
6+
"license": "MIT",
57
"scripts": {
68
"build": "tsc",
79
"test": "mocha src/*.spec.ts",
@@ -20,15 +22,14 @@
2022
"mocha": "^6.0.2",
2123
"mssql": "^4.3.2",
2224
"node-fetch": "^2.3.0",
23-
"proxy": "^0.2.4",
25+
"proxy": "^1.0.1",
2426
"ts-node": "^8.0.2",
2527
"typescript": "3.2.4"
2628
},
2729
"main": "./lib/index.js",
2830
"dependencies": {},
2931
"files": [
3032
"/README.md",
31-
"/src",
3233
"/lib"
3334
]
3435
}

src/HttpsProxySocket.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as tls from 'tls';
44
import * as url from 'url';
5+
import { proxyAgent } from './proxyAgent';
56

67
const debug = require('debug')('https-proxy');
78

@@ -69,6 +70,15 @@ export class HttpsProxySocket {
6970
});
7071
}
7172

73+
/**
74+
* Construct an agent for http(s) requests.
75+
*
76+
* @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
77+
*/
78+
agent(options?: tls.ConnectionOptions) {
79+
return proxyAgent(this, options);
80+
}
81+
7282
private _connect(opts: ConnectionOptions, cb: (error: any, socket: tls.TLSSocket) => void) {
7383
const proxy = this.proxy;
7484

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './HttpsProxySocket';
2+
export * from './tediousPatch';
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import * as fs from 'fs';
44
import * as http from 'http';
55
import * as https from 'https';
66
import * as assert from 'assert';
7-
import * as url from 'url';
87

98
import { HttpsProxySocket, HttpsProxyConfig } from './HttpsProxySocket';
10-
import { agent as proxyAgent } from './HttpsProxyAgent';
9+
import { proxyAgent } from './proxyAgent';
1110
import { ConnectionOptions } from 'tls';
1211
import { AddressInfo } from 'net';
1312

@@ -70,24 +69,15 @@ describe('HttpsProxyAgent', function() {
7069

7170
// shut down test HTTP server
7271
after(function(done) {
73-
server.once('close', function() {
74-
done();
75-
});
76-
server.close();
72+
server.close(done);
7773
});
7874

7975
after(function(done) {
80-
sslServer.once('close', function() {
81-
done();
82-
});
83-
sslServer.close();
76+
sslServer.close(done);
8477
});
8578

8679
after(function(done) {
87-
sslProxy.once('close', function() {
88-
done();
89-
});
90-
sslProxy.close();
80+
sslProxy.close(done);
9181
});
9282

9383
describe('constructor', function() {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as tls from 'tls';
88
* @param proxy - the proxy to use
99
* @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
1010
*/
11-
export function agent(proxy: HttpsProxySocket, options?: tls.ConnectionOptions) {
11+
export function proxyAgent(proxy: HttpsProxySocket, options?: tls.ConnectionOptions) {
1212
return agentBase(async (req, opts: any) => {
1313
const socket = await proxy.connect(opts);
1414

@@ -26,6 +26,7 @@ export function agent(proxy: HttpsProxySocket, options?: tls.ConnectionOptions)
2626
const tlsSocket = tls.connect(tlsOptions);
2727
return tlsSocket;
2828
} else {
29+
socket.resume();
2930
return socket;
3031
}
3132
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const debug = require('debug')('https-proxy');
88
*
99
* @param proxy - the proxy to use
1010
*/
11-
export function useProxy(proxy: HttpsProxySocket) {
11+
export function useProxyForTedious(proxy: HttpsProxySocket) {
1212
const { Connector } = require('tedious/lib/connector');
1313
Connector.prototype.execute = async function(cb: any) {
1414
debug(`opening sql connection to ${this.options.host}:${this.options.port}`);

0 commit comments

Comments
 (0)