Skip to content
Myr

[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

3 files+81 added−3 removed

added:test/fast/Unit tests/nvm_curl_use_compression+38 added
1#!/bin/sh23cleanup () {4 unset -f die5}67die () { echo -e "$@" ; cleanup ; exit 1; }89NVM_ENV=testing \. ../../../nvm.sh1011curl() {12 if [ "$1" = "-V" ]; then13 echo "${VERSION_MESSAGE}"14 fi15}1617CURL_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.018Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp19Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"2021CURL_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.022Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp23Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"2425CURL_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.226Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp27Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz"2829VERSION_MESSAGE="${CURL_VERSION_ON_ARCHLINUX_WITH_LIBZ}"30nvm_curl_use_compression || die "nvm_curl_use_compression should return 0"3132VERSION_MESSAGE="${CURL_VERSION_ON_ARCHLINUX_WITHOUT_LIBZ}"33! nvm_curl_use_compression || die "nvm_curl_use_compression should return 1 without libz support"3435VERSION_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"3738cleanup
added:test/fast/Unit tests/nvm_curl_version+32 added
1#!/bin/sh23cleanup () {4 unset -f die5 unset -f curl6}78die () { echo -e "$@" ; cleanup ; exit 1; }910NVM_ENV=testing \. ../../../nvm.sh1112curl() {13 if [ "$1" = "-V" ]; then14 echo "${VERSION_MESSAGE}"15 fi16}1718assert_version_is() {19 if [ "${1}" != "${2}" ]; then20 die "Expected ${2}, got ${1}, origin version message:\n${VERSION_MESSAGE}"21 return 122 fi23}2425CURL_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.026Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp27Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"2829VERSION_MESSAGE="${CURL_VERSION_MESSAGE}"30assert_version_is "$(nvm_curl_version)" "7.54.0"3132cleanup
modified:nvm.sh+11 added-3 removed
77 unmodified lines
78nvm_curl_libz_support() {79 curl -V 2>/dev/null | nvm_grep "^Features:" | nvm_grep -q "libz"80}8182nvm_curl_use_compression() {83 nvm_curl_libz_support && nvm_version_greater_than_or_equal_to "$(nvm_curl_version)" 7.21.0;84}8586nvm_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"; then
11 unmodified lines
106107nvm_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"; then
109 unmodified lines
224nvm_clang_version() {225 clang --version | command awk '{ if ($2 == "version") print $3; else if ($3 == "version") print $4 }' | command sed 's/-.*$//g'226}227228nvm_curl_version() {229 curl -V | command awk '{ if ($1 == "curl") print $2 }' | command sed 's/-.*$//g'230}231232nvm_version_greater() {233 command awk 'BEGIN {234 if (ARGV[1] == "" || ARGV[2] == "") exit(1)235 split(ARGV[1], a, /\./);
3055 unmodified lines
3291 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