-
Notifications
You must be signed in to change notification settings - Fork 267
/
http.ts
29 lines (25 loc) · 1.12 KB
/
http.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* Copyright (C) 2018-2023 Garden Technologies, Inc. <info@garden.io>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import _got, { Response, HTTPError as GotHttpError, OptionsOfJSONResponseBody } from "got"
import { bootstrap } from "global-agent"
import { OptionsOfTextResponseBody, Headers } from "got"
// Handle proxy environment settings
// (see https://github.com/gajus/global-agent#what-is-the-reason-global-agentbootstrap-does-not-use-http_proxy)
const isProxyEnvSet = process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.NO_PROXY
if (isProxyEnvSet) {
bootstrap({
environmentVariableNamespace: "",
})
}
// Exporting from here to make sure the global-agent bootstrap is executed, and for convenience as well
export const got = _got
export type GotTextOptions = OptionsOfTextResponseBody
export type GotJsonOptions = OptionsOfJSONResponseBody
export type GotResponse<T = unknown> = Response<T>
export type GotHeaders = Headers
export { GotHttpError }