From 6a3b1dd2c376d39daab7ec3a9fc1d4a3943ebf03 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 20 Mar 2017 04:08:48 +0800 Subject: [PATCH] [New] Enable curl auto compression/decompression Enable `--compressed` parameter on curl to automatically enable compression on request content by sending coressponding header, if the server side supports compression format like deflate or gzip, curl will also decompress the content automatically, so there is no additional works need to done manually on client side, but just enjoy the benifits of bandwidth and time saving! Take https://nodejs.org/dist/index.tab as an example which is last modified on Tue, 14 Mar 2017 22:41:05 GMT, the compressed transmission only take 4829 bytes howevet the not compressed on taks 48000 bytes, which is about 10 times larger! This feature can be traced back to Sep 3 2002, in curl commit: - https://github.com/curl/curl/commit/64bbe9dfafc6693a96b742f3133c636385835a19 So should be supported on various versions widely. --- README.markdown | 2 ++ install.sh | 3 ++- nvm.sh | 5 +++-- test/slow/nvm_get_latest/nvm_get_latest | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index eb155b8..2696a20 100644 --- a/README.markdown +++ b/README.markdown @@ -60,6 +60,8 @@ Homebrew installation is not supported. If you have issues with homebrew-install **Note:** Git versions before v1.7 may face a problem of cloning nvm source from GitHub via https protocol, and there is also different behavior of git before v1.6, so the minimum required git version is v1.7.0 and we recommend v1.7.9.5 as it's the default version of the widely used Ubuntu 12.04 LTS. If you are interested in the problem we mentioned here, please refer to GitHub's [HTTPS cloning errors](https://help.github.com/articles/https-cloning-errors/) article. +**Note:** `nvm` uses `curl` with the `--compressed` option which was introduced on September 3rd, 2002([curl/curl@64bbe9d](https://github.com/curl/curl/commit/64bbe9dfafc6693a96b742f3133c636385835a19)). It's unlikely, but if you have `curl` compiled without that feature, `nvm` may not be able to install or list remote `node` versions. Please file an issue if your `curl` does not work with `--compressed` (and you didn't explicitly compile `curl` to not have compression support). + ### Install script To install or update nvm, you can use the [install script][2] using cURL: diff --git a/install.sh b/install.sh index 6c1fbfe..790bde5 100755 --- a/install.sh +++ b/install.sh @@ -62,11 +62,12 @@ nvm_node_version() { nvm_download() { if nvm_has "curl"; then - curl -q "$@" + curl --compressed -q "$@" elif nvm_has "wget"; then # Emulate curl with wget ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ -e 's/-L //' \ + -e 's/--compressed //' \ -e 's/-I /--server-response /' \ -e 's/-s /-q /' \ -e 's/-o /-O /' \ diff --git a/nvm.sh b/nvm.sh index 94376b7..67ef6df 100644 --- a/nvm.sh +++ b/nvm.sh @@ -60,7 +60,7 @@ nvm_has_colors() { nvm_get_latest() { local NVM_LATEST_URL if nvm_has "curl"; then - NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)" + NVM_LATEST_URL="$(curl --compressed -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)" elif nvm_has "wget"; then NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')" else @@ -76,10 +76,11 @@ nvm_get_latest() { nvm_download() { if nvm_has "curl"; then - curl -q "$@" + curl --compressed -q "$@" elif nvm_has "wget"; then # Emulate curl with wget ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \ + -e 's/--compressed //' \ -e 's/-L //' \ -e 's/-I /--server-response /' \ -e 's/-s /-q /' \ diff --git a/test/slow/nvm_get_latest/nvm_get_latest b/test/slow/nvm_get_latest/nvm_get_latest index 2bdcbad..9f2f53c 100755 --- a/test/slow/nvm_get_latest/nvm_get_latest +++ b/test/slow/nvm_get_latest/nvm_get_latest @@ -10,7 +10,7 @@ cleanup() { EXPECTED_VERSION="v12.3.456" URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION" -EXPECTED_CURL_ARGS="-q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null" +EXPECTED_CURL_ARGS="--compressed -q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null" EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null" curl() {