|
19 | 19 |
|
20 | 20 | package org.apache.cloudstack.direct.download; |
21 | 21 |
|
22 | | -import com.cloud.utils.Pair; |
23 | | -import com.cloud.utils.exception.CloudRuntimeException; |
24 | | -import com.cloud.utils.script.Script; |
25 | | -import com.cloud.utils.storage.QCOW2Utils; |
26 | | -import org.apache.cloudstack.utils.security.SSLUtils; |
27 | | -import org.apache.commons.httpclient.HttpStatus; |
28 | | -import org.apache.commons.io.IOUtils; |
29 | | -import org.apache.http.Header; |
30 | | -import org.apache.http.HttpEntity; |
31 | | -import org.apache.http.client.methods.CloseableHttpResponse; |
32 | | -import org.apache.commons.collections.MapUtils; |
33 | | -import org.apache.http.client.config.RequestConfig; |
34 | | -import org.apache.http.client.methods.HttpGet; |
35 | | -import org.apache.http.client.methods.HttpHead; |
36 | | -import org.apache.http.client.methods.HttpUriRequest; |
37 | | -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
38 | | -import org.apache.http.impl.client.CloseableHttpClient; |
39 | | -import org.apache.http.impl.client.HttpClients; |
40 | | -import org.apache.http.util.EntityUtils; |
41 | | - |
42 | | -import javax.net.ssl.HttpsURLConnection; |
43 | | -import javax.net.ssl.SSLContext; |
44 | | -import javax.net.ssl.TrustManager; |
45 | 22 | import java.io.ByteArrayInputStream; |
46 | 23 | import java.io.File; |
47 | 24 | import java.io.FileInputStream; |
|
60 | 37 | import java.util.List; |
61 | 38 | import java.util.Map; |
62 | 39 |
|
| 40 | +import javax.net.ssl.HttpsURLConnection; |
| 41 | +import javax.net.ssl.SSLContext; |
| 42 | +import javax.net.ssl.TrustManager; |
| 43 | + |
| 44 | +import org.apache.cloudstack.utils.security.SSLUtils; |
| 45 | +import org.apache.commons.collections.MapUtils; |
| 46 | +import org.apache.commons.httpclient.HttpStatus; |
| 47 | +import org.apache.commons.io.IOUtils; |
| 48 | +import org.apache.http.Header; |
| 49 | +import org.apache.http.HttpEntity; |
| 50 | +import org.apache.http.client.config.RequestConfig; |
| 51 | +import org.apache.http.client.methods.CloseableHttpResponse; |
| 52 | +import org.apache.http.client.methods.HttpGet; |
| 53 | +import org.apache.http.client.methods.HttpHead; |
| 54 | +import org.apache.http.client.methods.HttpUriRequest; |
| 55 | +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
| 56 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 57 | +import org.apache.http.impl.client.HttpClients; |
| 58 | +import org.apache.http.util.EntityUtils; |
| 59 | + |
| 60 | +import com.cloud.utils.Pair; |
| 61 | +import com.cloud.utils.UriUtils; |
| 62 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 63 | +import com.cloud.utils.script.Script; |
| 64 | +import com.cloud.utils.storage.QCOW2Utils; |
| 65 | + |
63 | 66 | public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl { |
64 | 67 |
|
65 | 68 | protected CloseableHttpClient httpsClient; |
@@ -183,8 +186,7 @@ public Long getRemoteFileSize(String url, String format) { |
183 | 186 | SSLContext context = getSSLContext(); |
184 | 187 | urlConnection.setSSLSocketFactory(context.getSocketFactory()); |
185 | 188 | urlConnection.connect(); |
186 | | - boolean isCompressed = !url.endsWith("qcow2"); |
187 | | - return QCOW2Utils.getVirtualSize(urlObj.openStream(), isCompressed); |
| 189 | + return QCOW2Utils.getVirtualSize(urlObj.openStream(), UriUtils.isUrlForCompressedFile(url)); |
188 | 190 | } catch (IOException e) { |
189 | 191 | throw new CloudRuntimeException(String.format("Cannot obtain qcow2 virtual size due to: %s", e.getMessage()), e); |
190 | 192 | } |
|
0 commit comments