Skip to content

Commit

Permalink
Remove useless annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Aug 10, 2021
1 parent 2c65b1d commit 5cd9921
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 52 deletions.
24 changes: 2 additions & 22 deletions src/agent/transform-headers-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import { WrappedAgent } from './wrapped-agent';
const { _storeHeader } = OutgoingMessage.prototype;

/**
* @description Transforms the casing of the headers to Pascal-Case.
* Transforms the casing of the headers to Pascal-Case.
*/
class TransformHeadersAgent extends WrappedAgent {
// Rewritten from https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_outgoing.js#L442-L479
/**
* @description Transforms the request via header normalization.
* @see {TransformHeadersAgent.toPascalCase}
* @param {ClientRequest} request
* @param {string[]} sortedHeaders - headers in order, optional
* Transforms the request via header normalization.
*/
transformRequest(request: ClientRequest, sortedHeaders: string[]) {
const headers: Record<string, string | number | string[]> = {};
Expand Down Expand Up @@ -96,24 +93,12 @@ class TransformHeadersAgent extends WrappedAgent {
return super.addRequest(request, options);
}

/**
* @param {string} header - header with unknown casing
* @returns {string} - header in Pascal-Case
*/
toPascalCase(header: string) {
return header.split('-').map((part) => {
return part[0]!.toUpperCase() + part.slice(1).toLowerCase();
}).join('-');
}

/**
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
* @param {string} a - header a
* @param {string} b - header b
* @param {string[]} sortedHeaders - array of headers in order
* @returns header a or header b, depending which one is more important
*/
sort(a: string, b: string, sortedHeaders: string[]) {
const rawA = sortedHeaders.indexOf(a);
const rawB = sortedHeaders.indexOf(b);
Expand All @@ -131,11 +116,6 @@ class TransformHeadersAgent extends WrappedAgent {
return 0;
}

/**
*
* @param {string[]} sortedHeaders - array of headers in order
* @returns {Function} - sort function
*/
createSort(sortedHeaders: string[]) {
const sortWithSortedHeaders = (a: string, b: string) => this.sort(a, b, sortedHeaders);

Expand Down
4 changes: 2 additions & 2 deletions src/agent/wrapped-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Agent as HttpsAgent } from 'https';
* @see https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_client.js#L129-L162
* @see https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_client.js#L234-L246
* @see https://github.com/nodejs/node/blob/533cafcf7e3ab72e98a2478bc69aedfdf06d3a5e/lib/_http_client.js#L304-L305
* @description Wraps an existing Agent instance,
* so there's no need to replace `agent.addRequest`.
* Wraps an existing Agent instance,
* so there's no need to replace `agent.addRequest`.
*/
class WrappedAgent {
agent: HttpAgent | HttpsAgent;
Expand Down
6 changes: 0 additions & 6 deletions src/hooks/browser-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { Context } from '../context';
/**
* Merges original generated headers and user provided overrides.
* All header overrides will have the original header case, because of antiscraping.
* @param {object} original
* @param {object} overrides
* @returns
*/
export function mergeHeaders(original: Record<string, string>, overrides: Record<string, string>) {
const fixedHeaders = new Map();
Expand All @@ -29,9 +26,6 @@ export function mergeHeaders(original: Record<string, string>, overrides: Record
return headers;
}

/**
* @param {object} options
*/
export async function browserHeadersHook(options: Options) {
const { context } = options;
const {
Expand Down
3 changes: 0 additions & 3 deletions src/hooks/custom-options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Options, OptionsInit as GotOptionsInit } from 'got-cjs';
import { OptionsInit } from '../context';

/**
* @param {object} options
*/
export function customOptionsHook(raw: GotOptionsInit, options: Options): void {
const typedRaw = raw as OptionsInit;

Expand Down
3 changes: 0 additions & 3 deletions src/hooks/options-validation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import ow from 'ow';

/**
* @param {object} options
*/
export function optionsValidationHandler(options: unknown): void {
const validationSchema = {
proxyUrl: ow.optional.string.url,
Expand Down
15 changes: 0 additions & 15 deletions src/hooks/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const isAmbiguousAgent = (agent: Agent): boolean => {

/**
* @see https://github.com/TooTallNate/node-agent-base/issues/61
* @param {Agent} agent
*/
const fixAgentBase = (agent: Agent) => {
if (isAmbiguousAgent(agent)) {
Expand All @@ -45,19 +44,13 @@ const fixAgentBase = (agent: Agent) => {
return agent;
};

/**
* @param {Agent} agent
*/
const fixAgent = (agent: Agent) => {
agent = fixAgentBase(agent);
agent = new TransformHeadersAgent(agent) as unknown as Agent;

return agent;
};

/**
* @param {object} options
*/
export async function proxyHook(options: Options) {
const { context: { proxyUrl } } = options;

Expand All @@ -70,9 +63,6 @@ export async function proxyHook(options: Options) {
}
}

/**
* @param {string} protocol
*/
function validateProxyProtocol(protocol: string) {
const isSupported = protocol === 'http:' || protocol === 'https:';

Expand All @@ -83,11 +73,6 @@ function validateProxyProtocol(protocol: string) {

export const agentCache = new QuickLRU({ maxSize: 1000 });

/**
* @param {URL} parsedProxyUrl parsed proxyUrl
* @param {boolean} rejectUnauthorized
* @returns {object}
*/
async function getAgents(parsedProxyUrl: URL, rejectUnauthorized: boolean) {
const key = `${rejectUnauthorized}:${parsedProxyUrl.href}`;

Expand Down
1 change: 0 additions & 1 deletion src/scraping-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const SCRAPING_DEFAULT_OPTIONS = {

/**
* Reorders the default NodeJs ciphers so the request tries to negotiate the modern TLS version first, same as browsers do.
* @returns {string} ciphers list
*/
function ensureModernTlsFirst() {
const modernTlsCiphers = ['TLS_AES_256_GCM_SHA384', 'TLS_AES_128_GCM_SHA256', 'TLS_CHACHA20_POLY1305_SHA256'];
Expand Down

0 comments on commit 5cd9921

Please sign in to comment.