Skip to content

Commit 941efab

Browse files
committed
[https-proxy-agent] Prettier
1 parent 3b258fd commit 941efab

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

packages/https-proxy-agent/src/index.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
1515
type ConnectOptsMap = {
1616
http: Omit<net.TcpNetConnectOpts, 'host' | 'port'>;
1717
https: Omit<tls.ConnectionOptions, 'host' | 'port'>;
18-
}
18+
};
1919

2020
type ConnectOpts<T> = {
2121
[P in keyof ConnectOptsMap]: Protocol<T> extends P
@@ -40,7 +40,7 @@ export type HttpsProxyAgentOptions<T> = ConnectOpts<T> & {
4040
* the connection to the proxy server has been established.
4141
*/
4242
export class HttpsProxyAgent<Uri extends string> extends Agent {
43-
static protocols = ["http", "https"] as const;
43+
static protocols = ['http', 'https'] as const;
4444

4545
readonly proxy: URL;
4646
proxyHeaders: OutgoingHttpHeaders;
@@ -52,12 +52,15 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
5252

5353
constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions<Uri>) {
5454
super();
55-
this.proxy = typeof proxy === "string" ? new URL(proxy) : proxy;
55+
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy;
5656
this.proxyHeaders = opts?.headers ?? {};
57-
debug("Creating new HttpsProxyAgent instance: %o", this.proxy.href);
57+
debug('Creating new HttpsProxyAgent instance: %o', this.proxy.href);
5858

5959
// Trim off the brackets from IPv6 addresses
60-
const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, '');
60+
const host = (this.proxy.hostname || this.proxy.host).replace(
61+
/^\[|\]$/g,
62+
''
63+
);
6164
const port = this.proxy.port
6265
? parseInt(this.proxy.port, 10)
6366
: this.secureProxy
@@ -89,10 +92,10 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
8992
// Create a socket connection to the proxy server.
9093
let socket: net.Socket;
9194
if (secureProxy) {
92-
debug("Creating `tls.Socket`: %o", this.connectOpts);
95+
debug('Creating `tls.Socket`: %o', this.connectOpts);
9396
socket = tls.connect(this.connectOpts);
9497
} else {
95-
debug("Creating `net.Socket`: %o", this.connectOpts);
98+
debug('Creating `net.Socket`: %o', this.connectOpts);
9699
socket = net.connect(this.connectOpts);
97100
}
98101

@@ -105,9 +108,9 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
105108
const auth = `${decodeURIComponent(
106109
proxy.username
107110
)}:${decodeURIComponent(proxy.password)}`;
108-
headers["Proxy-Authorization"] = `Basic ${Buffer.from(
111+
headers['Proxy-Authorization'] = `Basic ${Buffer.from(
109112
auth
110-
).toString("base64")}`;
113+
).toString('base64')}`;
111114
}
112115

113116
// The `Host` header should only include the port
@@ -118,7 +121,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
118121
}
119122
headers.Host = host;
120123

121-
headers.Connection = "close";
124+
headers.Connection = 'close';
122125
for (const name of Object.keys(headers)) {
123126
payload += `${name}: ${headers[name]}\r\n`;
124127
}
@@ -130,15 +133,15 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
130133
const { statusCode, buffered } = await proxyResponsePromise;
131134

132135
if (statusCode === 200) {
133-
req.once("socket", resume);
136+
req.once('socket', resume);
134137

135138
if (opts.secureEndpoint) {
136139
// The proxy is connecting to a TLS server, so upgrade
137140
// this socket connection to a TLS connection.
138-
debug("Upgrading socket connection to TLS");
141+
debug('Upgrading socket connection to TLS');
139142
const servername = opts.servername || opts.host;
140143
const s = tls.connect({
141-
...omit(opts, "host", "path", "port"),
144+
...omit(opts, 'host', 'path', 'port'),
142145
socket,
143146
servername,
144147
});
@@ -169,9 +172,9 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
169172
fakeSocket.readable = true;
170173

171174
// Need to wait for the "socket" event to re-play the "data" events.
172-
req.once("socket", (s: net.Socket) => {
173-
debug("Replaying proxy buffer for failed request");
174-
assert(s.listenerCount("data") > 0);
175+
req.once('socket', (s: net.Socket) => {
176+
debug('Replaying proxy buffer for failed request');
177+
assert(s.listenerCount('data') > 0);
175178

176179
// Replay the "buffered" Buffer onto the fake `socket`, since at
177180
// this point the HTTP module machinery has been hooked up for

packages/https-proxy-agent/test/test.ts

+14-22
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ describe('HttpsProxyAgent', () => {
3232
beforeAll(async () => {
3333
// setup target HTTP server
3434
server = http.createServer();
35-
serverUrl = await listen(server) as URL;
35+
serverUrl = (await listen(server)) as URL;
3636
});
3737

3838
beforeAll(async () => {
3939
// setup HTTP proxy server
4040
proxy = createProxy();
41-
proxyUrl = await listen(proxy) as URL;
41+
proxyUrl = (await listen(proxy)) as URL;
4242
});
4343

4444
beforeAll(async () => {
4545
// setup target HTTPS server
4646
sslServer = https.createServer(sslOptions);
47-
sslServerUrl = await listen(sslServer) as URL;
47+
sslServerUrl = (await listen(sslServer)) as URL;
4848
});
4949

5050
beforeAll(async () => {
5151
// setup SSL HTTP proxy server
5252
sslProxy = createProxy(https.createServer(sslOptions));
53-
sslProxyUrl = await listen(sslProxy) as URL;
53+
sslProxyUrl = (await listen(sslProxy)) as URL;
5454
});
5555

5656
// shut down the test HTTP servers
@@ -79,15 +79,11 @@ describe('HttpsProxyAgent', () => {
7979
});
8080
describe('secureProxy', () => {
8181
it('should be `false` when "http:" protocol is used', () => {
82-
const agent = new HttpsProxyAgent(
83-
proxyUrl
84-
);
82+
const agent = new HttpsProxyAgent(proxyUrl);
8583
assert.equal(false, agent.secureProxy);
8684
});
8785
it('should be `true` when "https:" protocol is used', () => {
88-
const agent = new HttpsProxyAgent(
89-
sslProxyUrl
90-
);
86+
const agent = new HttpsProxyAgent(sslProxyUrl);
9187
assert.equal(true, agent.secureProxy);
9288
});
9389
});
@@ -178,14 +174,11 @@ describe('HttpsProxyAgent', () => {
178174
});
179175

180176
it('should allow custom proxy "headers"', async () => {
181-
const agent = new HttpsProxyAgent(
182-
serverUrl,
183-
{
184-
headers: {
185-
Foo: 'bar',
186-
},
187-
}
188-
);
177+
const agent = new HttpsProxyAgent(serverUrl, {
178+
headers: {
179+
Foo: 'bar',
180+
},
181+
});
189182

190183
const connectPromise = once(server, 'connect');
191184

@@ -252,10 +245,9 @@ describe('HttpsProxyAgent', () => {
252245
res.end(JSON.stringify(req.headers));
253246
});
254247

255-
const agent = new HttpsProxyAgent(
256-
sslProxyUrl,
257-
{ rejectUnauthorized: false }
258-
);
248+
const agent = new HttpsProxyAgent(sslProxyUrl, {
249+
rejectUnauthorized: false,
250+
});
259251
agent.defaultPort = parseInt(sslServerUrl.port, 10);
260252

261253
const res = await req(sslServerUrl, {

0 commit comments

Comments
 (0)