@typespec/ts-http-runtime 1.0.0-alpha.20240207.1 → 1.0.0-alpha.20240213.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1817,34 +1817,6 @@ function getDefaultProxySettings(proxyUrl) {
|
|
|
1817
1817
|
password: parsedUrl.password,
|
|
1818
1818
|
};
|
|
1819
1819
|
}
|
|
1820
|
-
/**
|
|
1821
|
-
* @internal
|
|
1822
|
-
*/
|
|
1823
|
-
function getProxyAgentOptions(proxySettings, { headers, tlsSettings }) {
|
|
1824
|
-
let parsedProxyUrl;
|
|
1825
|
-
try {
|
|
1826
|
-
parsedProxyUrl = new URL(proxySettings.host);
|
|
1827
|
-
}
|
|
1828
|
-
catch (_error) {
|
|
1829
|
-
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`);
|
|
1830
|
-
}
|
|
1831
|
-
if (tlsSettings) {
|
|
1832
|
-
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
1833
|
-
}
|
|
1834
|
-
const proxyAgentOptions = {
|
|
1835
|
-
hostname: parsedProxyUrl.hostname,
|
|
1836
|
-
port: proxySettings.port,
|
|
1837
|
-
protocol: parsedProxyUrl.protocol,
|
|
1838
|
-
headers: headers.toJSON(),
|
|
1839
|
-
};
|
|
1840
|
-
if (proxySettings.username && proxySettings.password) {
|
|
1841
|
-
proxyAgentOptions.auth = `${proxySettings.username}:${proxySettings.password}`;
|
|
1842
|
-
}
|
|
1843
|
-
else if (proxySettings.username) {
|
|
1844
|
-
proxyAgentOptions.auth = `${proxySettings.username}`;
|
|
1845
|
-
}
|
|
1846
|
-
return proxyAgentOptions;
|
|
1847
|
-
}
|
|
1848
1820
|
function setProxyAgentOnRequest(request, cachedAgents) {
|
|
1849
1821
|
// Custom Agent should take precedence so if one is present
|
|
1850
1822
|
// we should skip to avoid overwriting it.
|
|
@@ -1855,17 +1827,26 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
1855
1827
|
const isInsecure = url.protocol !== "https:";
|
|
1856
1828
|
const proxySettings = request.proxySettings;
|
|
1857
1829
|
if (proxySettings) {
|
|
1830
|
+
let parsedProxyUrl;
|
|
1831
|
+
try {
|
|
1832
|
+
parsedProxyUrl = new URL(proxySettings.host);
|
|
1833
|
+
}
|
|
1834
|
+
catch (_error) {
|
|
1835
|
+
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`);
|
|
1836
|
+
}
|
|
1837
|
+
if (request.tlsSettings) {
|
|
1838
|
+
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
1839
|
+
}
|
|
1840
|
+
const headers = request.headers.toJSON();
|
|
1858
1841
|
if (isInsecure) {
|
|
1859
1842
|
if (!cachedAgents.httpProxyAgent) {
|
|
1860
|
-
|
|
1861
|
-
cachedAgents.httpProxyAgent = new httpProxyAgent.HttpProxyAgent(proxyAgentOptions);
|
|
1843
|
+
cachedAgents.httpProxyAgent = new httpProxyAgent.HttpProxyAgent(parsedProxyUrl, { headers });
|
|
1862
1844
|
}
|
|
1863
1845
|
request.agent = cachedAgents.httpProxyAgent;
|
|
1864
1846
|
}
|
|
1865
1847
|
else {
|
|
1866
1848
|
if (!cachedAgents.httpsProxyAgent) {
|
|
1867
|
-
|
|
1868
|
-
cachedAgents.httpsProxyAgent = new httpsProxyAgent.HttpsProxyAgent(proxyAgentOptions);
|
|
1849
|
+
cachedAgents.httpsProxyAgent = new httpsProxyAgent.HttpsProxyAgent(parsedProxyUrl, { headers });
|
|
1869
1850
|
}
|
|
1870
1851
|
request.agent = cachedAgents.httpsProxyAgent;
|
|
1871
1852
|
}
|