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

Curl --compressed handling #1550

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ nvm_curl_libz_support() {
curl -V 2>/dev/null | nvm_grep "^Features:" | nvm_grep -q "libz"
}

nvm_curl_use_compression() {
nvm_curl_libz_support && nvm_version_greater_than_or_equal_to "$(nvm_curl_version)" 7.21.0;
}

nvm_get_latest() {
local NVM_LATEST_URL
local CURL_COMPRESSED_FLAG
if nvm_has "curl"; then
if nvm_curl_libz_support; then
if nvm_curl_use_compression; then
CURL_COMPRESSED_FLAG="--compressed"
fi
NVM_LATEST_URL="$(curl "${CURL_COMPRESSED_FLAG:-}" -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
Expand All @@ -103,7 +107,7 @@ nvm_get_latest() {
nvm_download() {
local CURL_COMPRESSED_FLAG
if nvm_has "curl"; then
if nvm_curl_libz_support; then
if nvm_curl_use_compression; then
CURL_COMPRESSED_FLAG="--compressed"
fi
curl "${CURL_COMPRESSED_FLAG:-}" -q "$@"
Expand Down Expand Up @@ -221,6 +225,10 @@ nvm_clang_version() {
clang --version | command awk '{ if ($2 == "version") print $3; else if ($3 == "version") print $4 }' | command sed 's/-.*$//g'
}

nvm_curl_version() {
curl -V | command awk '{ if ($1 == "curl") print $2 }' | command sed 's/-.*$//g'
}

nvm_version_greater() {
command awk 'BEGIN {
if (ARGV[1] == "" || ARGV[2] == "") exit(1)
Expand Down Expand Up @@ -3284,7 +3292,7 @@ nvm() {
nvm_version_greater nvm_version_greater_than_or_equal_to \
nvm_print_npm_version nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \
nvm_download nvm_get_latest nvm_has nvm_install_default_packages \
nvm_download nvm_get_latest nvm_has nvm_install_default_packages nvm_curl_use_compression nvm_curl_version \
nvm_supports_source_options nvm_auto nvm_supports_xz \
nvm_echo nvm_err nvm_grep nvm_cd \
nvm_die_on_prefix nvm_get_make_jobs nvm_get_minor_version \
Expand Down
38 changes: 38 additions & 0 deletions test/fast/Unit tests/nvm_curl_use_compression
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

cleanup () {
unset -f die
}

die () { echo -e "$@" ; cleanup ; exit 1; }

NVM_ENV=testing \. ../../../nvm.sh

curl() {
if [ "$1" = "-V" ]; then
echo "${VERSION_MESSAGE}"
fi
}

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.0
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"

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.0
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"

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.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz"

VERSION_MESSAGE="${CURL_VERSION_ON_ARCHLINUX_WITH_LIBZ}"
nvm_curl_use_compression || die "nvm_curl_use_compression should return 0"

VERSION_MESSAGE="${CURL_VERSION_ON_ARCHLINUX_WITHOUT_LIBZ}"
! nvm_curl_use_compression || die "nvm_curl_use_compression should return 1 without libz support"

VERSION_MESSAGE="${CURL_VERSION_ON_CENTOS6_WITH_LIBZ}"
! nvm_curl_use_compression || die "nvm_curl_use_compression should return 1 when curl < 7.21.0"

cleanup
32 changes: 32 additions & 0 deletions test/fast/Unit tests/nvm_curl_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

cleanup () {
unset -f die
unset -f curl
}

die () { echo -e "$@" ; cleanup ; exit 1; }

NVM_ENV=testing \. ../../../nvm.sh

curl() {
if [ "$1" = "-V" ]; then
echo "${VERSION_MESSAGE}"
fi
}

assert_version_is() {
if [ "${1}" != "${2}" ]; then
die "Expected ${2}, got ${1}, origin version message:\n${VERSION_MESSAGE}"
return 1
fi
}

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.0
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL"

VERSION_MESSAGE="${CURL_VERSION_MESSAGE}"
assert_version_is "$(nvm_curl_version)" "7.54.0"

cleanup