Commit 26b5b225 authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Added more sophisticed URI building to allow for URLs with spaces and more

parent 5c983c82
Pipeline #348 failed with stage
in 4 minutes and 29 seconds
package workers
import java.io.RandomAccessFile
import java.net.URL
import java.net.{URI, URL}
import java.nio.charset.StandardCharsets
import java.security.cert.X509Certificate
import org.apache.http.auth.{AuthScope, UsernamePasswordCredentials}
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.{HttpGet, HttpHead}
import org.apache.http.client.utils.{URIBuilder, URLEncodedUtils}
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
import org.apache.http.impl.client.{BasicCredentialsProvider, HttpClients}
import org.apache.http.ssl.{SSLContexts, TrustStrategy}
......@@ -30,7 +32,7 @@ class HttpWorker (override protected val downloadJob: DownloadJob,
var httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).disableContentCompression()
.setSSLSocketFactory(sslConnectionSocketFactory).build()
val port = { if (url.getPort == -1) url.getDefaultPort else url.getPort }
val method = new HttpHead(url.toURI)
val method = new HttpHead(getURIFromURL(url))
try {
method.addHeader("Connection", "close")
......@@ -71,7 +73,7 @@ class HttpWorker (override protected val downloadJob: DownloadJob,
var httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).disableContentCompression()
.setSSLSocketFactory(sslConnectionSocketFactory).build()
val port = { if (url.getPort == -1) url.getDefaultPort else url.getPort }
val method = new HttpHead(url.toURI)
val method = new HttpHead(getURIFromURL(url))
try {
method.addHeader("Connection", "close")
......@@ -118,7 +120,7 @@ class HttpWorker (override protected val downloadJob: DownloadJob,
.disableContentCompression()
.setSSLSocketFactory(sslConnectionSocketFactory).build()
val port = { if (downloadJob.url.getPort == -1) downloadJob.url.getDefaultPort else downloadJob.url.getPort }
val method = new HttpGet(downloadJob.url.toURI)
val method = new HttpGet(getURIFromURL(downloadJob.url))
try {
method.addHeader("Range", s"bytes=${slot._1}-${slot._2}")
......@@ -169,4 +171,13 @@ class HttpWorker (override protected val downloadJob: DownloadJob,
}
}
}
private def getURIFromURL(url: URL): URI = {
new URIBuilder()
.setScheme(url.getProtocol)
.setHost(url.getHost)
.setPath(url.getPath)
.setParameters(URLEncodedUtils.parse(url.getQuery, StandardCharsets.UTF_8))
.build()
}
}
name := "sget2"
version := "1.3.1"
version := "1.3.2"
lazy val `sget2` = (project in file(".")).enablePlugins(PlayScala)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment