Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make redirection from HTTP to HTTPS work #2426

Merged
merged 2 commits into from Sep 26, 2019

Commits on Sep 24, 2019

  1. Make redirection from HTTP to HTTPS work

    When calling an HTTP resource redirecting to a HTTPS one with a keepAlive agent. We get the following error:
    ```
    TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
        at new ClientRequest (_http_client.js:119:11)
        at Object.request (https.js:281:10)
        at RedirectableRequest._performRequest (/Users/jthomassey/projects/ecom-shop-web/node_modules/follow-redirects/index.js:169:24)
        at RedirectableRequest._processResponse (/Users/jthomassey/projects/ecom-shop-web/node_modules/follow-redirects/index.js:260:10)
        at ClientRequest.RedirectableRequest._onNativeResponse (/Users/jthomassey/projects/ecom-shop-web/node_modules/follow-redirects/index.js:50:10)
        at Object.onceWrapper (events.js:277:13)
        at ClientRequest.emit (events.js:189:13)
        at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
        at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
        at Socket.socketOnData (_http_client.js:442:20)
    ```
    
    This can be tested here : 
    ```
    const http = require('http');
    const https = require('https');
    const axios = require('axios');
    
    axios.get('http://www.photobox.fr', { httpAgent: http.Agent({ keepAlive:true }), httpsAgent: https.Agent({ keepAlive:true }) })
      .then(response => {
        console.log(response);
        console.log(response.headers);
      })
      .catch(error => {
        console.log(error);
      });
    ```
    
    Axios delegate the redirection to the follow-redirect package which accept an option `agents` for both http and https agent see : https://github.com/follow-redirects/follow-redirects#per-request-options
    JitixPhotobox committed Sep 24, 2019
    Copy the full SHA
    03171f5 View commit details
    Browse the repository at this point in the history

Commits on Sep 26, 2019

  1. Copy the full SHA
    7c2c7d3 View commit details
    Browse the repository at this point in the history