mirror of https://github.com/sbt/sbt.git
Add back support for partial downloads
Broken when adding support for not-found caching
This commit is contained in:
parent
aa836864a3
commit
a6c488812c
|
|
@ -386,27 +386,27 @@ object Cache {
|
||||||
|
|
||||||
val conn0 = urlConn(url)
|
val conn0 = urlConn(url)
|
||||||
|
|
||||||
if (is404(conn0))
|
val (partialDownload, conn) = conn0 match {
|
||||||
|
case conn0: HttpURLConnection if alreadyDownloaded > 0L =>
|
||||||
|
conn0.setRequestProperty("Range", s"bytes=$alreadyDownloaded-")
|
||||||
|
|
||||||
|
if (conn0.getResponseCode == partialContentResponseCode) {
|
||||||
|
val ackRange = Option(conn0.getHeaderField("Content-Range")).getOrElse("")
|
||||||
|
|
||||||
|
if (ackRange.startsWith(s"bytes $alreadyDownloaded-"))
|
||||||
|
(true, conn0)
|
||||||
|
else
|
||||||
|
// unrecognized Content-Range header -> start a new connection with no resume
|
||||||
|
(false, urlConn(url))
|
||||||
|
} else
|
||||||
|
(false, conn0)
|
||||||
|
|
||||||
|
case _ => (false, conn0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is404(conn))
|
||||||
FileError.NotFound(url, permanent = Some(true)).left
|
FileError.NotFound(url, permanent = Some(true)).left
|
||||||
else {
|
else {
|
||||||
val (partialDownload, conn) = conn0 match {
|
|
||||||
case conn0: HttpURLConnection if alreadyDownloaded > 0L =>
|
|
||||||
conn0.setRequestProperty("Range", s"bytes=$alreadyDownloaded-")
|
|
||||||
|
|
||||||
if (conn0.getResponseCode == partialContentResponseCode) {
|
|
||||||
val ackRange = Option(conn0.getHeaderField("Content-Range")).getOrElse("")
|
|
||||||
|
|
||||||
if (ackRange.startsWith(s"bytes $alreadyDownloaded-"))
|
|
||||||
(true, conn0)
|
|
||||||
else
|
|
||||||
// unrecognized Content-Range header -> start a new connection with no resume
|
|
||||||
(false, urlConn(url))
|
|
||||||
} else
|
|
||||||
(false, conn0)
|
|
||||||
|
|
||||||
case _ => (false, conn0)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (len0 <- Option(conn.getContentLengthLong) if len0 >= 0L) {
|
for (len0 <- Option(conn.getContentLengthLong) if len0 >= 0L) {
|
||||||
val len = len0 + (if (partialDownload) alreadyDownloaded else 0L)
|
val len = len0 + (if (partialDownload) alreadyDownloaded else 0L)
|
||||||
logger.foreach(_.downloadLength(url, len, alreadyDownloaded))
|
logger.foreach(_.downloadLength(url, len, alreadyDownloaded))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue