Skip to content

Commit 397ab69

Browse files
committed
More polish.
1 parent 5cab0dd commit 397ab69

6 files changed

Lines changed: 60 additions & 33 deletions

File tree

.circleci/config.yml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
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

README.md

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

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

12-
## Usage
12+
## Usage - node-fetch
1313

14+
const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
15+
const fetch = require('node-fetch');
16+
17+
// Proxy connection options
18+
const proxy = new HttpsProxySocket('https://my-proxy.test', {
19+
// Additional options for the proxy may be set here, for example:
20+
auth: 'myuser:mypassword' // Basic auth
21+
});
22+
23+
const agent = proxy.agent({
24+
// Additional TLS options for the host may be set here, for example:
25+
// rejectUnauthorized: false
26+
});
27+
28+
const response = await fetch('https://myhost.test', { agent: agent });
29+
30+
## Usage - Direct socket
1431

1532
const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
16-
const proxy = new HttpsProxySocket({
17-
// Connection options
18-
host: 'my-proxy.test',
19-
port: 443
20-
}, {
33+
const proxy = new HttpsProxySocket('https://my-proxy.test', {
2134
auth: 'myuser:mypassword' // Optional: proxy basic auth
2235
});
2336

2437
const socket = await proxy.connect({host: 'myhost.test', port: 1234});
2538

26-
## Usage with mssql
27-
39+
## Usage - mssql
2840

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

32-
const { HttpsProxySocket } = require('./lib/HttpsProxySocket');
3344
const proxy = new HttpsProxySocket({
3445
// Same as above
3546
});
3647

3748
// Register the proxy globally for tedious/mssql
38-
useProxy(proxy);
49+
useProxyForTedious(proxy);
3950

4051
async function run() {
4152
// Connect using the proxy

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './HttpsProxySocket';
22
export * from './tediousPatch';
3-
export * from './agent';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as https from 'https';
66
import * as assert from 'assert';
77

88
import { HttpsProxySocket, HttpsProxyConfig } from './HttpsProxySocket';
9-
import { agent as proxyAgent } from './agent';
9+
import { proxyAgent } from './proxyAgent';
1010
import { ConnectionOptions } from 'tls';
1111
import { AddressInfo } from 'net';
1212

src/agent.ts renamed to src/proxyAgent.ts

Lines changed: 1 addition & 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

0 commit comments

Comments
 (0)