title: Nodejs Axios get request with 502 Bad Gateway response for some sites
body: <p>Hi I'm developing a small Node JS script for downloading to local files images from differents weather sat/radar sites. For exapmple <a href="https://radar.weather.gov/ridge/lite/KBYX_loop.gif" rel="nofollow noreferrer">https://radar.weather.gov/ridge/lite/KBYX_loop.gif</a> when I open this url in my browser it opens perfectly the gif radar image. However when I call a get request using axios the response is 502 Bad Gateway. I'm working behind a company proxy so I have to pass my auth credentials. This code works perfectly with other sites for example for this site <a href="https://weather.cod.edu/satrad/assets/php/scripts/mkgif.php?parms=global-atlantic-14-1&amp;start=445&amp;end=445&amp;rate=&amp;pause=&amp;checked=map&amp;colorbar=data" rel="nofollow noreferrer">https://weather.cod.edu/satrad/assets/php/scripts/mkgif.php?parms=global-atlantic-14-1&amp;start=445&amp;end=445&amp;rate=&amp;pause=&amp;checked=map&amp;colorbar=data</a></p>
  <p>Here is my code:</p>
  <pre><code>Axios.interceptors.request.use(
    function (config) {
      console.log(config);
      // console.log('Base URL: ', config.baseURL);
      // console.log('URL: ', config.url);
      // console.log('Params: ', config.params);
      return config;
    },
    function (error) {
      console.log(err);
  
      // Do something with request error
      return Promise.reject(error);
    }
  );
  
  Axios.interceptors.response.use(
    function (response) {
      console.log(response);
      return response;
    },
    function (error) {
      return Promise.reject(error);
    }
  );
  
  const download = async (fileUrl, outputLocationPath, config, params) =&gt; {
    const writer = fs.createWriteStream(outputLocationPath);
    return Axios({
      method: 'get',
      url: fileUrl,
      params: params,
      proxy: {
        host: config.host,
        port: config.port,
        auth: { username: config.user, password: config.pass },
      },
      responseType: 'stream',
    }).then((response) =&gt; {
      return new Promise((resolve, reject) =&gt; {
        response.data.pipe(writer);
        let error = null;
        writer.on('error', (err) =&gt; {
          error = err;
          writer.close();
          reject(err);
        });
        writer.on('close', () =&gt; {
          if (!error) {
            resolve(response);
          }
        });
      });
    })
    .catch(err =&gt;  console.log(err));
  };
  </code></pre>
  <p>And this is the response:</p>
  <pre><code>response: {
      status: 502,
      statusText: 'Bad Gateway',
      headers: {
        server: 'squid/4.13',
        'mime-version': '1.0',
        date: 'Wed, 30 Mar 2022 14:39:01 GMT',
        'content-type': 'text/html;charset=utf-8',
        'content-length': '3842',
        'x-squid-error': 'ERR_READ_ERROR 0',
        vary: 'Accept-Language',
        'content-language': 'en',
        'x-cache': 'MISS from ProxyB',
        'x-cache-lookup': 'MISS from ProxyB:3128',
        via: '1.1 ProxyB (squid/4.13)',
        connection: 'close'
      },
      config: {
        transitional: [Object],
        adapter: [Function: httpAdapter],
        transformRequest: [Array],
        transformResponse: [Array],
        timeout: 0,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        maxBodyLength: -1,
        validateStatus: [Function: validateStatus],
        headers: [Object],
        method: 'get',
        url: 'https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/11/latest.jpg',
        params: {},
        proxy: [Object],
        responseType: 'stream',
        data: undefined
      },
  </code></pre>
  <p>When I open the site in the browser I get the correct response and get the gif image.</p>
  <p>I hope you can understand my issue and thanks in adv for any help or clarification.</p>