denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.81k stars 5.38k forks source link

npm:got 'agent' and npm:axios 'proxy' configuration not working #20939

Open drag0n-app opened 1 year ago

drag0n-app commented 1 year ago

got & hpagent

import { HttpProxyAgent, HttpsProxyAgent } from 'npm:hpagent';
import got from 'npm:got';

const ip = await got.get('http://api.ipify.org/', {
    agent: {
        http: new HttpProxyAgent({ proxy: 'http://127.0.0.1:8000' }),
        https: new HttpsProxyAgent({ proxy: 'http://127.0.0.1:8000' }),
    }
}).text();
console.log(ip);

axios

import axios from 'npm:axios';
const ip = await axios.get('http://api.ipify.org/', {
    proxy: {
        protocol: 'http',
        host: '127.0.0.1',
        port: 8000,
    }
});
console.log(ip.data);

They don't work at all. But they work well with Node.js.

chibat commented 1 year ago

As a workaround, the Deno fetch API can use proxy. The --unstable option is required. https://deno.land/api@v1.37.2?unstable=&s=Deno.CreateHttpClientOptions#prop_proxy

satyarohith commented 2 months ago

The axios script when run with deno hits a different path. I think there is some misconfiguration of headers.

Image

Note: the 404 responses are by deno, and the 200 response is by node.