[Fix] enable curl compression only on curl >=7.21.0
Before adoption: this commit came in with the history the project adopted, so no landing records it.
curl < 7.21.0 will output redirection reponse body to the output when compressed, which will cause tarball is prepended with redirection reponse body and leads to checksum mismatch. - add `nvm_curl_use_compression` and `nvm_curl_version`
authored by J Huang · committed by Jordan Harband · parent d2644b2 · Browse files · 3 files·+81 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+81 added−3 removed
- tests:+70 added−0 removed
- other:+11 added−3 removed
Provenance
- Commit
7965796- Tree
bf535f1- Author
J Huang <i@jhuang.me>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
d2644b2
3 files changed+81 added−3 removed
added:test/fast/Unit tests/nvm_curl_use_compression+38 added
1+#!/bin/sh2+3+cleanup () {4+ unset -f die5+}6+7+die () { echo -e "$@" ; cleanup ; exit 1; }8+9+NVM_ENV=testing \. ../../../nvm.sh10+11+curl() {12+ if [ "$1" = "-V" ]; then13+ echo "${VERSION_MESSAGE}"14+ fi15+}16+17+CURL_VERSION_ON_ARCHLINUX_WITH_LIBZ="curl 7.54.0 (x86_64-pc-linux-gnu) libcurl/7.54.0 OpenSSL/1.1.0f zlib/1.2.11 libpsl/0.17.0 (+libicu/59.1) libssh2/1.8.0 nghttp2/1.22.018+Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp19+Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"20+21+CURL_VERSION_ON_ARCHLINUX_WITHOUT_LIBZ="curl 7.54.0 (x86_64-pc-linux-gnu) libcurl/7.54.0 OpenSSL/1.1.0f zlib/1.2.11 libpsl/0.17.0 (+libicu/59.1) libssh2/1.8.0 nghttp2/1.22.022+Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp23+Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"24+25+CURL_VERSION_ON_CENTOS6_WITH_LIBZ="curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.226+Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp27+Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz"28+29+VERSION_MESSAGE="${CURL_VERSION_ON_ARCHLINUX_WITH_LIBZ}"30+nvm_curl_use_compression || die "nvm_curl_use_compression should return 0"31+32+VERSION_MESSAGE="${CURL_VERSION_ON_ARCHLINUX_WITHOUT_LIBZ}"33+! nvm_curl_use_compression || die "nvm_curl_use_compression should return 1 without libz support"34+35+VERSION_MESSAGE="${CURL_VERSION_ON_CENTOS6_WITH_LIBZ}"36+! nvm_curl_use_compression || die "nvm_curl_use_compression should return 1 when curl < 7.21.0"37+38+cleanupadded:test/fast/Unit tests/nvm_curl_version+32 added
1+#!/bin/sh2+3+cleanup () {4+ unset -f die5+ unset -f curl6+}7+8+die () { echo -e "$@" ; cleanup ; exit 1; }9+10+NVM_ENV=testing \. ../../../nvm.sh11+12+curl() {13+ if [ "$1" = "-V" ]; then14+ echo "${VERSION_MESSAGE}"15+ fi16+}17+18+assert_version_is() {19+ if [ "${1}" != "${2}" ]; then20+ die "Expected ${2}, got ${1}, origin version message:\n${VERSION_MESSAGE}"21+ return 122+ fi23+}24+25+CURL_VERSION_MESSAGE="curl 7.54.0 (x86_64-pc-linux-gnu) libcurl/7.54.0 OpenSSL/1.1.0f zlib/1.2.11 libpsl/0.17.0 (+libicu/59.1) libssh2/1.8.0 nghttp2/1.22.026+Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp27+Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"28+29+VERSION_MESSAGE="${CURL_VERSION_MESSAGE}"30+assert_version_is "$(nvm_curl_version)" "7.54.0"31+32+cleanupmodified:nvm.sh+11 added-3 removed
77 unmodified lines78 nvm_curl_libz_support() {79 curl -V 2>/dev/null | nvm_grep "^Features:" | nvm_grep -q "libz"80 }81 82+nvm_curl_use_compression() {83+ nvm_curl_libz_support && nvm_version_greater_than_or_equal_to "$(nvm_curl_version)" 7.21.0;84+}85+86 nvm_get_latest() {87 local NVM_LATEST_URL88 local CURL_COMPRESSED_FLAG89 if nvm_has "curl"; then86- if nvm_curl_libz_support; then90+ if nvm_curl_use_compression; then91 CURL_COMPRESSED_FLAG="--compressed"92 fi93 NVM_LATEST_URL="$(curl "${CURL_COMPRESSED_FLAG:-}" -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"94 elif nvm_has "wget"; then11 unmodified lines106 107 nvm_download() {108 local CURL_COMPRESSED_FLAG109 if nvm_has "curl"; then106- if nvm_curl_libz_support; then110+ if nvm_curl_use_compression; then111 CURL_COMPRESSED_FLAG="--compressed"112 fi113 curl "${CURL_COMPRESSED_FLAG:-}" -q "$@"114 elif nvm_has "wget"; then109 unmodified lines224 nvm_clang_version() {225 clang --version | command awk '{ if ($2 == "version") print $3; else if ($3 == "version") print $4 }' | command sed 's/-.*$//g'226 }227 228+nvm_curl_version() {229+ curl -V | command awk '{ if ($1 == "curl") print $2 }' | command sed 's/-.*$//g'230+}231+232 nvm_version_greater() {233 command awk 'BEGIN {234 if (ARGV[1] == "" || ARGV[2] == "") exit(1)235 split(ARGV[1], a, /\./);3055 unmodified lines3291 nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \3292 nvm_version_greater nvm_version_greater_than_or_equal_to \3293 nvm_print_npm_version nvm_npm_global_modules \3294 nvm_has_system_node nvm_has_system_iojs \3287- nvm_download nvm_get_latest nvm_has nvm_install_default_packages \3295+ nvm_download nvm_get_latest nvm_has nvm_install_default_packages nvm_curl_use_compression nvm_curl_version \3296 nvm_supports_source_options nvm_auto nvm_supports_xz \3297 nvm_echo nvm_err nvm_grep nvm_cd \3298 nvm_die_on_prefix nvm_get_make_jobs nvm_get_minor_version \3299 nvm_has_solaris_binary nvm_is_merged_node_version \111 unmodified lines