<p dir="auto"><strong>Describe the bug</strong><br>
I use axios.get method with custom httpsAgent and httpAgent in node.js. The node_internals _http_client.js emit a warn when the server response http statue code 302 and headers location's protocol is different with the initiator url's protocol.</p>
<p dir="auto"><strong>To Reproduce</strong><br>
Code snippet to reproduce, ideally that will work by pasting into something like <a href="https://npm.runkit.com/axios" rel="nofollow">https://npm.runkit.com/axios</a>, a hosted solution, or a repository that illustrates the issue. <strong>If your problem is not reproducible, please file under Support or Usage Question</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// Example code here
const axios = require(&quot;axios&quot;);
const https = require(&quot;https&quot;);
const http = require(&quot;http&quot;);
const httpsAgent = new https.Agent({keepAlive: true})
const httpAgent = new http.Agent({keepAlive: true})
const url = 'https://xxxxx';
axios
  .get(url, {
    httpsAgent,
    httpAgent
  })
  .then(() =&gt; {
    console.log(&quot;success&quot;);
  })
  .catch(() =&gt; {
    console.error(&quot;error:&quot;);
  });
"><pre class="notranslate"><span class="pl-c">// Example code here</span>
<span class="pl-k">const</span> <span class="pl-s1">axios</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"axios"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">https</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"https"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">http</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"http"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">httpsAgent</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-s1">https</span><span class="pl-kos">.</span><span class="pl-c1">Agent</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">keepAlive</span>: <span class="pl-c1">true</span><span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">httpAgent</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-s1">http</span><span class="pl-kos">.</span><span class="pl-c1">Agent</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">keepAlive</span>: <span class="pl-c1">true</span><span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">'https://xxxxx'</span><span class="pl-kos">;</span>
<span class="pl-s1">axios</span>
  <span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
    httpsAgent<span class="pl-kos">,</span>
    httpAgent
  <span class="pl-kos">}</span><span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"success"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-en">catch</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">error</span><span class="pl-kos">(</span><span class="pl-s">"error:"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">I had read the axios' code , the httpFollow and httpsFollow's options should includes customer's agent</p>
<p dir="auto"><strong>Expected behavior</strong><br>
axios use a new agent adapter the redirect url protocol</p>
<p dir="auto"><strong>Environment:</strong></p>
<ul dir="auto">
<li>Axios Version: 0.19.0</li>
<li>Node Version: v12.14.0</li>
</ul>
<p dir="auto"><strong>Additional context/Screenshots</strong><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12745859/71676135-5f0bd780-2dba-11ea-9689-43c701f628fa.png"><img src="https://user-images.githubusercontent.com/12745859/71676135-5f0bd780-2dba-11ea-9689-43c701f628fa.png" alt="image" style="max-width: 100%;"></a></p>
<h4 dir="auto">Description</h4>
<p dir="auto">I try to setup HTTPS-session using Axios which works fine through Fiddler.<br>
This fails by the way on the current stable release <a href="https://github.com/axios/axios/releases/tag/v0.18.0">v0.18.0</a>, I guess this is issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="232289309" data-permission-text="Title is private" data-url="https://github.com/axios/axios/issues/925" data-hovercard-type="issue" data-hovercard-url="/axios/axios/issues/925/hovercard" href="https://github.com/axios/axios/issues/925">#925</a>, fixed in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="236171190" data-permission-text="Title is private" data-url="https://github.com/axios/axios/issues/959" data-hovercard-type="pull_request" data-hovercard-url="/axios/axios/pull/959/hovercard" href="https://github.com/axios/axios/pull/959">#959</a>.</p>
<p dir="auto">As soon as I remove Fiddle, it no longer works. I suspect that it is, because the connection is pooled by Fiddler. So in order to make it work without the Fiddler proxy, I inject httpsAgent to keep the connection alive e.g.:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import * as http from 'https';
import * as https from 'https';

const Fiddler = {
  host: '127.0.0.1',
  port: 8888
};

this.axios = Axios.create({
   proxy: Fiddler
   httpAgent: new http.Agent({keepAlive: true}),
   httpsAgent: new https.Agent({keepAlive: true, rejectUnauthorized: false})"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">http</span> <span class="pl-k">from</span> <span class="pl-s">'https'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">https</span> <span class="pl-k">from</span> <span class="pl-s">'https'</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-v">Fiddler</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">host</span>: <span class="pl-s">'127.0.0.1'</span><span class="pl-kos">,</span>
  <span class="pl-c1">port</span>: <span class="pl-c1">8888</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">axios</span> <span class="pl-c1">=</span> <span class="pl-v">Axios</span><span class="pl-kos">.</span><span class="pl-c1">create</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
   <span class="pl-c1">proxy</span>: <span class="pl-v">Fiddler</span>
   <span class="pl-s1">httpAgent</span>: <span class="pl-k">new</span> <span class="pl-s1">http</span><span class="pl-kos">.</span><span class="pl-c1">Agent</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">keepAlive</span>: <span class="pl-c1">true</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
   <span class="pl-c1">httpsAgent</span>: <span class="pl-k">new</span> <span class="pl-s1">https</span><span class="pl-kos">.</span><span class="pl-c1">Agent</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">keepAlive</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span> <span class="pl-c1">rejectUnauthorized</span>: <span class="pl-c1">false</span><span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">I can't get it work with the https-agent assigned, not with a proxy:</p>
<h4 dir="auto">Stacktrace:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError [ERR_INVALID_PROTOCOL]: Protocol &quot;http:&quot; not supported. Expected &quot;https:&quot;
    at new ClientRequest (_http_client.js:118:11)
    at Object.request (http.js:41:10)
    at RedirectableRequest._performRequest (node_modules\follow-redirects\index.js:186:24)
    at new RedirectableRequest (node_modules\follow-redirects\index.js:69:8)
    at Object.wrappedProtocol.request (node_modules\follow-redirects\index.js:363:14)
    at dispatchHttpRequest (node_modules\axios\lib\adapters\http.js:180:25)
    at new Promise (&lt;anonymous&gt;)
    at httpAdapter (node_modules\axios\lib\adapters\http.js:20:10)
    at dispatchRequest (node_modules\axios\lib\core\dispatchRequest.js:59:10)"><pre class="notranslate"><code class="notranslate">TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
    at new ClientRequest (_http_client.js:118:11)
    at Object.request (http.js:41:10)
    at RedirectableRequest._performRequest (node_modules\follow-redirects\index.js:186:24)
    at new RedirectableRequest (node_modules\follow-redirects\index.js:69:8)
    at Object.wrappedProtocol.request (node_modules\follow-redirects\index.js:363:14)
    at dispatchHttpRequest (node_modules\axios\lib\adapters\http.js:180:25)
    at new Promise (&lt;anonymous&gt;)
    at httpAdapter (node_modules\axios\lib\adapters\http.js:20:10)
    at dispatchRequest (node_modules\axios\lib\core\dispatchRequest.js:59:10)
</code></pre></div>
<p dir="auto">Not without a proxy.</p>
<h4 dir="auto">Context</h4>
<ul dir="auto">
<li>axios version: <em>e.g.: (v0.19.0-beta.1)[https://github.com/axios/axios/releases/tag/v0.19.0-beta.1]</em></li>
<li>Environment: <em>e.g.: node v10.13.0, Windows 10</em></li>
</ul>
<h4 dir="auto">Related issues</h4>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="383153580" data-permission-text="Title is private" data-url="https://github.com/axios/axios/issues/1885" data-hovercard-type="issue" data-hovercard-url="/axios/axios/issues/1885/hovercard" href="https://github.com/axios/axios/issues/1885">#1885</a> (that one using a socks proxy, therefor I consider this one to be different)</li>
</ul>