Skip to content

Commit

Permalink
chore: review PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Oct 23, 2024
1 parent 8109fdc commit 2121cd7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
4.0.6 / 2024/10/23
4.0.7 / 2024/10/23
====================
- Handles proxy authentication consistently throughout the codebase (solves e.g. this [`http2-wrapper`](https://github.com/szmarczak/http2-wrapper/issues/108) issue).

Expand Down
6 changes: 3 additions & 3 deletions src/agent/h1-proxy-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import https from 'node:https';
import { isIPv6 } from 'node:net';
import tls, { type ConnectionOptions } from 'node:tls';
import { URL } from 'node:url';
import { getBasic } from '../auth.js';
import { buildBasicAuthHeader } from '../auth.js';

interface AgentOptions extends http.AgentOptions {
proxy: string | URL;
Expand Down Expand Up @@ -63,7 +63,7 @@ export class HttpRegularProxyAgent extends http.Agent {

request.path = url.href;

const basic = getBasic(this.proxy);
const basic = buildBasicAuthHeader(this.proxy);
if (basic) {
request.setHeader('proxy-authorization', basic);
}
Expand Down Expand Up @@ -101,7 +101,7 @@ export class HttpProxyAgent extends http.Agent {
host: hostport,
};

const basic = getBasic(this.proxy);
const basic = buildBasicAuthHeader(this.proxy);
if (basic) {
headers['proxy-authorization'] = basic;
headers.authorization = basic;
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param url URL object to process
* @returns `Basic BASE64` string
*/
export function getBasic(url: URL): string | null {
export function buildBasicAuthHeader(url: URL): string | null {
if (!url.username && !url.password) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import http2, { auto } from 'http2-wrapper';
import { URL } from 'node:url';
import { HttpProxyAgent, HttpRegularProxyAgent, HttpsProxyAgent } from '../agent/h1-proxy-agent.js';
import { TransformHeadersAgent } from '../agent/transform-headers-agent.js';
import { getBasic } from '../auth.js';
import { buildBasicAuthHeader } from '../auth.js';

const {
HttpOverHttp2,
Expand Down Expand Up @@ -39,7 +39,7 @@ async function getAgents(parsedProxyUrl: URL, rejectUnauthorized: boolean) {
// Sockets must not be reused, the proxy server may rotate upstream proxies as well.

const headers: Record<string, string> = {};
const basic = getBasic(parsedProxyUrl);
const basic = buildBasicAuthHeader(parsedProxyUrl);

if (basic) {
headers.authorization = basic;
Expand Down
4 changes: 2 additions & 2 deletions src/resolve-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type Headers } from 'got';
import { auto, type ResolveProtocolConnectFunction, type ResolveProtocolFunction } from 'http2-wrapper';
import QuickLRU from 'quick-lru';
import { ProxyError } from './hooks/proxy.js';
import { getBasic } from './auth.js';
import { buildBasicAuthHeader } from './auth.js';

const connect = async (proxyUrl: string, options: tls.ConnectionOptions, callback: () => void) => new Promise<TLSSocket>((resolve, reject) => {
let host = `${options.host}:${options.port}`;
Expand All @@ -21,7 +21,7 @@ const connect = async (proxyUrl: string, options: tls.ConnectionOptions, callbac
};

const url = new URL(proxyUrl);
const basic = getBasic(url);
const basic = buildBasicAuthHeader(url);

if (basic) {
headers.authorization = basic;
Expand Down

0 comments on commit 2121cd7

Please sign in to comment.