Skip to content

Commit 0653f25

Browse files
committed
Set parallel-max-host if curl>=8.16.0
If an user provides a multiple URLs, we don't want to open too many connections to the same host in parallel due to the risk of getting throttled. wcurl will use the newly added option --parallel-max-host if available, using 5 as the default value per host. This contains an update to the docs to show how an user can remove the limit.
1 parent 04d0e45 commit 0653f25

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ should be using curl directly if your use case is not covered.
6363
* By default, **wcurl** does:
6464
* Percent-encode whitespaces in URLs;
6565
* Download multiple URLs in parallel if the installed curl's version is >= 7.66.0 (`--parallel`);
66+
* Use a total number of 5 parallel connections to the same protocol + hostname + port number target if the installed curl's version is >= 8.16.0 (`--parallel-max-host`);
6667
* Follow redirects;
6768
* Automatically choose a filename as output;
6869
* Avoid overwriting files if the installed curl's version is >= 7.83.0 (`--no-clobber`);
@@ -139,6 +140,12 @@ then performs the parsing. May be specified more than once.
139140
wcurl --curl-options="--continue-at -" example.com/filename.txt
140141
```
141142

143+
* Download multiple files without a limit in number of concurrent connections per host, the default is 5:
144+
145+
```sh
146+
wcurl --curl-options="--parallel-max-host 0" example.com/filename1.txt example.com/filename2.txt
147+
```
148+
142149
# Running the testsuite
143150

144151
If you would like to run the tests, you first need to install the

wcurl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,23 @@ exec_curl()
181181
{
182182
CMD="curl "
183183

184-
# Store version to check if it supports --no-clobber and --parallel.
184+
# Store version to check if it supports --no-clobber, --parallel and --parallel-max-host.
185185
curl_version=$($CMD --version | cut -f2 -d' ' | head -n1)
186186
curl_version_major=$(echo "$curl_version" | cut -f1 -d.)
187187
curl_version_minor=$(echo "$curl_version" | cut -f2 -d.)
188188

189189
CURL_HAS_NO_CLOBBER=""
190190
CURL_HAS_PARALLEL=""
191+
CURL_HAS_PARALLEL_MAX_HOST=""
191192
# --no-clobber is only supported since 7.83.0.
192193
# --parallel is only supported since 7.66.0.
194+
# --parallel-max-host is only supported since 8.16.0.
193195
if [ "${curl_version_major}" -ge 8 ]; then
194196
CURL_HAS_NO_CLOBBER="--no-clobber"
195197
CURL_HAS_PARALLEL="--parallel"
198+
if [ "${curl_version_minor}" -ge 16 ]; then
199+
CURL_HAS_PARALLEL_MAX_HOST="--parallel-max-host 5"
200+
fi
196201
elif [ "${curl_version_major}" -eq 7 ]; then
197202
if [ "${curl_version_minor}" -ge 83 ]; then
198203
CURL_HAS_NO_CLOBBER="--no-clobber"
@@ -202,13 +207,13 @@ exec_curl()
202207
fi
203208
fi
204209

205-
# Detecting whether we need --parallel. It's easier to rely on
210+
# Detecting whether we need --parallel. It's easier to rely on
206211
# the shell's argument parsing.
207212
# shellcheck disable=SC2086
208213
set -- $URLS
209214

210215
if [ "$#" -gt 1 ]; then
211-
CURL_PARALLEL="$CURL_HAS_PARALLEL"
216+
CURL_PARALLEL="$CURL_HAS_PARALLEL ${CURL_HAS_PARALLEL_MAX_HOST}"
212217
else
213218
CURL_PARALLEL=""
214219
fi

wcurl.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ By default, **wcurl** does:
4545
## * Download multiple URLs in parallel
4646
if the installed curl's version is \>= 7.66.0 (--parallel);
4747

48+
## * Use a total number of 5 parallel connections to the same protocol + hostname + port number target
49+
if the installed curl's version is \>= 8.16.0 (--parallel-max-host);
50+
4851
## * Follow redirects;
4952

5053
## * Automatically choose a filename as output;
@@ -129,6 +132,10 @@ be the last one in the list):
129132

130133
**wcurl --curl-options="--continue-at -" example.com/filename.txt**
131134

135+
Download multiple files without a limit in number of concurrent connections per host, the default is 5:
136+
137+
**wcurl --curl-options="--parallel-max-host 0" example.com/filename1.txt example.com/filename2.txt**
138+
132139
# AUTHORS
133140

134141
Samuel Henrique \<[email protected]\>

0 commit comments

Comments
 (0)