Repository: nvm
Issue: nvm doesn't understand error HTTP codes, like 522
Labels: installing node

- Operating system and version:

    OS X latest, Ubuntu 16.04

- `nvm debug` output:
    <details>
    <!-- do not delete the following blank line -->

    ```sh
    nvm --version: v0.33.1
    $SHELL: /bin/zsh
    $HOME: /home/docwhat
    $NVM_DIR: '$HOME/.nvm'
    $PREFIX: ''
    $NPM_CONFIG_PREFIX: ''
    $NVM_NODEJS_ORG_MIRROR: 'https://nodejs.org/dist'
    $NVM_IOJS_ORG_MIRROR: 'https://iojs.org/dist'
    nvm current: none
    which node: node not found
    which iojs: iojs not found
    which npm: npm not found
    npm config get prefix: _zsh_nvm_nvm:109: command not found: npm
    npm root -g: _zsh_nvm_nvm:109: command not found: npm

    ```
    </details>

- `nvm ls` output:
    <details>
    <!-- do not delete the following blank line -->

    ```sh
    nvm ls
                N/A
    node -> stable (-> N/A) (default)
    iojs -> N/A (default)
    lts/* -> lts/boron (-> N/A)
    lts/argon -> v4.8.2 (-> N/A)
    lts/boron -> v6.10.2 (-> N/A)

    ```
    </details>

- How did you install `nvm`? (e.g. install script in readme, homebrew):

    `zgen load lukechilds/zsh-nvm`

- What steps did you perform?

    ``` sh
    $ nvm install node
    ```

- What happened?

    ``` sh
    $ nvm install node
    Downloading and installing node v7.8.0...
    Downloading https://nodejs.org/dist/v7.8.0/node-v7.8.0-linux-x64.tar.xz...
    ######################################################################## 100.0%
    Computing checksum with sha256sum
    Checksums do not match: 'a787603d24847638636033047c6ab4789291c7175a8355b3d1de1bc82fd2b0a3' found, '1fca4e71d6f00f7f727994fccc604716160f06aa1ad6d8689d84cd3ca5227312' expected.
    xz: (stdin): File format not recognized
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
    Binary download failed, trying source.
    Detected that you have 4 CPU core(s)
    Running with 3 threads to speed up the build
    Downloading https://nodejs.org/dist/v7.8.0/node-v7.8.0.tar.xz...
    ######################################################################## 100.0%
    Computing checksum with sha256sum
    Checksums do not match: '6776c3b22a119b521adf2ba3bc0e0e9e29012b7e3d95561c4a03f83724ae1a7a' found, '6821aaee58bbc8bc8d08fec6989a42278b725a21382500dc20fd9d9f71398f02' expected.
    xz: (stdin): File format not recognized
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
    nvm: install v7.8.0 failed!
    ```

- What did you expect to happen?

    I expected it to notice that the HTTP code from nodejs.org was 522 and not even bother with the checksum check and return a better error message.

    I understand that nodejs.org is having issues right now which is why I'm getting 522.  I just thought that `nvm` should handle it all better.

    The output of several curl attempts:

    <details>
    <!-- do not delete the following blank line -->

    ``` sh
    $ curl -v -I https://nodejs.org/dist/v7.8.0/node-v7.8.0-linux-x64.tar.xz
    *   Trying 2400:cb00:2048:1::6814:162e...
    * Connected to nodejs.org (2400:cb00:2048:1::6814:162e) port 443 (#0)
    * found 173 certificates in /etc/ssl/certs/ca-certificates.crt
    * found 699 certificates in /etc/ssl/certs
    * ALPN, offering http/1.1
    * SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
    *        server certificate verification OK
    *        server certificate status verification SKIPPED
    *        common name: *.nodejs.org (matched)
    *        server certificate expiration date OK
    *        server certificate activation date OK
    *        certificate public key: RSA
    *        certificate version: #3
    *        subject: OU=Domain Control Validated,OU=PositiveSSL Wildcard,CN=*.nodejs.org
    *        start date: Sun, 08 Nov 2015 00:00:00 GMT
    *        expire date: Tue, 22 Aug 2017 23:59:59 GMT
    *        issuer: C=GB,ST=Greater Manchester,L=Salford,O=COMODO CA Limited,CN=COMODO RSA Domain Validation Secure Server CA
    *        compression: NULL
    * ALPN, server accepted to use http/1.1
    > HEAD /dist/v7.8.0/node-v7.8.0-linux-x64.tar.xz HTTP/1.1
    > Host: nodejs.org
    > User-Agent: curl/7.47.0
    > Accept: */*
    >
    < HTTP/1.1 522 Origin Connection Time-out
    HTTP/1.1 522 Origin Connection Time-out
    < Date: Tue, 04 Apr 2017 22:48:53 GMT
    Date: Tue, 04 Apr 2017 22:48:53 GMT
    < Content-Type: text/html; charset=UTF-8
    Content-Type: text/html; charset=UTF-8
    < Connection: keep-alive
    Connection: keep-alive
    < Set-Cookie: __cfduid=dde4efe982214e8a0cb8594cb70a9b4d01491346028; expires=Wed, 04-Apr-18 22:47:08 GMT; path=/; domain=.nodejs.org; HttpOnly
    Set-Cookie: __cfduid=dde4efe982214e8a0cb8594cb70a9b4d01491346028; expires=Wed, 04-Apr-18 22:47:08 GMT; path=/; domain=.nodejs.org; HttpOnly
    < Expires: Thu, 01 Jan 1970 00:00:01 GMT
    Expires: Thu, 01 Jan 1970 00:00:01 GMT
    < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    < Pragma: no-cache
    Pragma: no-cache
    < X-Frame-Options: SAMEORIGIN
    X-Frame-Options: SAMEORIGIN
    < Server: cloudflare-nginx
    Server: cloudflare-nginx
    < CF-RAY: 34a7cec6dd9521d4-EWR
    CF-RAY: 34a7cec6dd9521d4-EWR

    <
    * Connection #0 to host nodejs.org left intact

    $ curl -v -4 -I https://nodejs.org/dist/v7.8.0/node-v7.8.0-linux-x64.tar.xz
    *   Trying 104.20.23.46...
    * Connected to nodejs.org (104.20.23.46) port 443 (#0)
    * found 173 certificates in /etc/ssl/certs/ca-certificates.crt
    * found 699 certificates in /etc/ssl/certs
    * ALPN, offering http/1.1
    * SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
    *        server certificate verification OK
    *        server certificate status verification SKIPPED
    *        common name: *.nodejs.org (matched)
    *        server certificate expiration date OK
    *        server certificate activation date OK
    *        certificate public key: RSA
    *        certificate version: #3
    *        subject: OU=Domain Control Validated,OU=PositiveSSL Wildcard,CN=*.nodejs.org
    *        start date: Sun, 08 Nov 2015 00:00:00 GMT
    *        expire date: Tue, 22 Aug 2017 23:59:59 GMT
    *        issuer: C=GB,ST=Greater Manchester,L=Salford,O=COMODO CA Limited,CN=COMODO RSA Domain Validation Secure Server CA
    *        compression: NULL
    * ALPN, server accepted to use http/1.1
    > HEAD /dist/v7.8.0/node-v7.8.0-linux-x64.tar.xz HTTP/1.1
    > Host: nodejs.org
    > User-Agent: curl/7.47.0
    > Accept: */*
    >
    < HTTP/1.1 522 Origin Connection Time-out
    HTTP/1.1 522 Origin Connection Time-out
    < Date: Tue, 04 Apr 2017 22:49:34 GMT
    Date: Tue, 04 Apr 2017 22:49:34 GMT
    < Content-Type: text/html; charset=UTF-8
    Content-Type: text/html; charset=UTF-8
    < Connection: keep-alive
    Connection: keep-alive
    < Set-Cookie: __cfduid=d0579527c0bd28fb87196985d5b65badb1491346144; expires=Wed, 04-Apr-18 22:49:04 GMT; path=/; domain=.nodejs.org; HttpOnly
    Set-Cookie: __cfduid=d0579527c0bd28fb87196985d5b65badb1491346144; expires=Wed, 04-Apr-18 22:49:04 GMT; path=/; domain=.nodejs.org; HttpOnly
    < Expires: Thu, 01 Jan 1970 00:00:01 GMT
    Expires: Thu, 01 Jan 1970 00:00:01 GMT
    < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    < Pragma: no-cache
    Pragma: no-cache
    < X-Frame-Options: SAMEORIGIN
    X-Frame-Options: SAMEORIGIN
    < Server: cloudflare-nginx
    Server: cloudflare-nginx
    < CF-RAY: 34a7d19c0858473a-EWR
    CF-RAY: 34a7d19c0858473a-EWR

    <
    * Connection #0 to host nodejs.org left intact
    ```
    </details>

- Is there anything in any of your profile files (`.bashrc`, `.bash_profile`, `.zshrc`, etc) that modifies the `PATH`?

    Tons, see https://github.com/docwhat/dotfiles for my whole setup.

<!-- if this does not apply, please delete this section -->
- If you are having installation issues, or getting "N/A", what does `curl -I --compressed -v https://nodejs.org/dist/` print out?
    <details>
    <!-- do not delete the following blank line -->

    ```sh
    $ curl -I --compressed -v https://nodejs.org/dist/
    *   Trying 2400:cb00:2048:1::6814:172e...
    * Connected to nodejs.org (2400:cb00:2048:1::6814:172e) port 443 (#0)
    * found 173 certificates in /etc/ssl/certs/ca-certificates.crt
    * found 699 certificates in /etc/ssl/certs
    * ALPN, offering http/1.1
    * SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
    *        server certificate verification OK
    *        server certificate status verification SKIPPED
    *        common name: *.nodejs.org (matched)
    *        server certificate expiration date OK
    *        server certificate activation date OK
    *        certificate public key: RSA
    *        certificate version: #3
    *        subject: OU=Domain Control Validated,OU=PositiveSSL Wildcard,CN=*.nodejs.org
    *        start date: Sun, 08 Nov 2015 00:00:00 GMT
    *        expire date: Tue, 22 Aug 2017 23:59:59 GMT
    *        issuer: C=GB,ST=Greater Manchester,L=Salford,O=COMODO CA Limited,CN=COMODO RSA Domain Validation Secure Server CA
    *        compression: NULL
    * ALPN, server accepted to use http/1.1
    > HEAD /dist/ HTTP/1.1
    > Host: nodejs.org
    > User-Agent: curl/7.47.0
    > Accept: */*
    > Accept-Encoding: deflate, gzip
    >
    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    < Date: Tue, 04 Apr 2017 23:00:13 GMT
    Date: Tue, 04 Apr 2017 23:00:13 GMT
    < Content-Type: text/html
    Content-Type: text/html
    < Connection: keep-alive
    Connection: keep-alive
    < Set-Cookie: __cfduid=db500eaf269a21c73b4ca4ec3f153ac021491346798; expires=Wed, 04-Apr-18 22:59:58 GMT; path=/; domain=.nodejs.org; HttpOnly
    Set-Cookie: __cfduid=db500eaf269a21c73b4ca4ec3f153ac021491346798; expires=Wed, 04-Apr-18 22:59:58 GMT; path=/; domain=.nodejs.org; HttpOnly
    < CF-Cache-Status: STALE
    CF-Cache-Status: STALE
    < Vary: Accept-Encoding
    Vary: Accept-Encoding
    < Expires: Wed, 05 Apr 2017 03:00:13 GMT
    Expires: Wed, 05 Apr 2017 03:00:13 GMT
    < Cache-Control: public, max-age=14400
    Cache-Control: public, max-age=14400
    < Server: cloudflare-nginx
    Server: cloudflare-nginx
    < CF-RAY: 34a7e1944fe01834-EWR
    CF-RAY: 34a7e1944fe01834-EWR
    < Content-Encoding: gzip
    Content-Encoding: gzip

    <
    * Connection #0 to host nodejs.org left intact
    ```
    </details>