Skip to content
Myr

[New] Enable curl auto compression/decompression

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Peter Dave Hello · committed by Peter Dave Hello · parent 4c97828 · Browse files · 4 files+8 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+8 added−4 removed

  • tests:+1 added−1 removed
  • other:+7 added−3 removed

4 files+8 added−4 removed

modified:test/slow/nvm_get_latest/nvm_get_latest+1 added-1 removed
8 unmodified lines
9\. ../../../nvm.sh1011EXPECTED_VERSION="v12.3.456"12URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION"13EXPECTED_CURL_ARGS="-q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"13EXPECTED_CURL_ARGS="--compressed -q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"14EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"1516curl() {17 if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then
100 unmodified lines
modified:install.sh+2 added-1 removed
60 unmodified lines
61}6263nvm_download() {64 if nvm_has "curl"; then65 curl -q "$@"65 curl --compressed -q "$@"66 elif nvm_has "wget"; then67 # Emulate curl with wget68 ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \69 -e 's/-L //' \70 -e 's/--compressed //' \71 -e 's/-I /--server-response /' \72 -e 's/-s /-q /' \73 -e 's/-o /-O /' \74 -e 's/-C - /-c /')
300 unmodified lines
modified:nvm.sh+3 added-2 removed
58 unmodified lines
5960nvm_get_latest() {61 local NVM_LATEST_URL62 if nvm_has "curl"; then63 NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"63 NVM_LATEST_URL="$(curl --compressed -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"64 elif nvm_has "wget"; then65 NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"66 else67 nvm_err 'nvm needs curl or wget to proceed.'
7 unmodified lines
75}7677nvm_download() {78 if nvm_has "curl"; then79 curl -q "$@"79 curl --compressed -q "$@"80 elif nvm_has "wget"; then81 # Emulate curl with wget82 ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \83 -e 's/--compressed //' \84 -e 's/-L //' \85 -e 's/-I /--server-response /' \86 -e 's/-s /-q /' \87 -e 's/-o /-O /' \
3203 unmodified lines
modified:README.markdown+2 added
58 unmodified lines
59**Note:** If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade.6061**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.6263**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).6465### Install script6667To install or update nvm, you can use the [install script][2] using cURL:68
413 unmodified lines