Skip to content

Commit

Permalink
Fix: --ignoreInvalidTLS has no effect (hyperjumptech#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennypradipta authored Dec 9, 2024
1 parent 77e8e0e commit 71ae938
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/components/probe/prober/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ export class HTTPProber extends BaseProber {
responses: ProbeRequestResponse[]
) {
return httpRequest({
requestConfig: { ...config, signal },
requestConfig: {
...config,
allowUnauthorized:
config.allowUnauthorized ?? getContext().flags.ignoreInvalidTLS,
signal,
},
responses,
})
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/probe/prober/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export async function httpRequest({
timeout,
body,
ping,
allowUnauthorized = requestConfig.allowUnauthorized ??
getContext().flags.ignoreInvalidTLS,
allowUnauthorized,
followRedirects,
signal,
} = requestConfig
Expand Down
8 changes: 5 additions & 3 deletions src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type HttpRequestParams = {
// More information here: https://rakshanshetty.in/nodejs-http-keep-alive/
const httpAgent = new http.Agent({ keepAlive: true })
const httpsAgent = new https.Agent({ keepAlive: true })
const insecureHttpsAgent = new https.Agent({
keepAlive: true,
rejectUnauthorized: false,
})
export const DEFAULT_TIMEOUT = 10_000

// Create an instance of axios here so it will be reused instead of creating a new one all the time.
Expand All @@ -57,9 +61,7 @@ export async function sendHttpRequest(
headers: convertHeadersToAxios(headers),
timeout: timeout ?? DEFAULT_TIMEOUT, // Ensure default timeout if not filled.
httpAgent,
httpsAgent: allowUnauthorizedSsl
? new https.Agent({ keepAlive: true, rejectUnauthorized: true })
: httpsAgent,
httpsAgent: allowUnauthorizedSsl ? insecureHttpsAgent : httpsAgent,
})
}

Expand Down

0 comments on commit 71ae938

Please sign in to comment.