diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index d85e262..22e6244 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -265,7 +265,15 @@ } } else + { std.net.curl.download(url, filename, conn); + // workaround https://issues.dlang.org/show_bug.cgi?id=18318 + auto sl = conn.statusLine; + logDebug("Download %s %s", url, sl); + if (sl.code / 100 != 2) + throw new HTTPStatusException(sl.code, + "Downloading %s failed with %d (%s).".format(url, sl.code, sl.reason)); + } } else version (Have_vibe_d_http) { import vibe.inet.urltransfer; vibe.inet.urltransfer.download(url, filename); diff --git a/test/fetchzip.sh b/test/fetchzip.sh index ecfedae..05c3a98 100755 --- a/test/fetchzip.sh +++ b/test/fetchzip.sh @@ -20,10 +20,10 @@ fi dub remove gitcompatibledubpackage --non-interactive --version=1.0.4 -echo "Trying to download gitcompatibledubpackage (1.0.3) from a broken registry" +echo "Downloads should be retried when the zip is corrupted - gitcompatibledubpackage (1.0.3)" zipCount=$(! timeout 1s "$DUB" fetch gitcompatibledubpackage --version=1.0.3 --skip-registry=all --registry=http://localhost:$PORT 2>&1| grep -Fc 'Failed to extract zip archive') rc=$? -if [ "$zipCount" -le 3 ] ; then +if [ "$zipCount" -lt 3 ] ; then die 'DUB should have tried to download the zip archive multiple times.' elif [ $rc -eq 124 ]; then die 'DUB timed out unexpectedly.' @@ -31,3 +31,16 @@ if dub remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null; then die 'DUB should not have installed a broken package.' fi + +echo "HTTP status errors on downloads should be retried - gitcompatibledubpackage (1.0.2)" +retryCount=$(! timeout 1s "$DUB" fetch gitcompatibledubpackage --version=1.0.2 --skip-registry=all --registry=http://localhost:$PORT --vverbose 2>&1| grep -Fc 'Bad Gateway') +rc=$? +if [ "$retryCount" -lt 3 ] ; then + die 'DUB should have retried download on server error multiple times.' +elif [ $rc -eq 124 ]; then + die 'DUB timed out unexpectedly.' +fi +if dub remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null; then + die 'DUB should not have installed a package.' +fi + diff --git a/test/test_registry.d b/test/test_registry.d index c736845..4e10024 100644 --- a/test/test_registry.d +++ b/test/test_registry.d @@ -13,6 +13,9 @@ res.writeVoidBody; exitEventLoop(); }); + router.get("/packages/gitcompatibledubpackage/1.0.2.zip", (req, res) { + res.writeBody("", HTTPStatus.badGateway); + }); router.get("*", folder.serveStaticFiles); listenHTTP(text(":", port), router); runApplication();