|
19 | 19 |
|
20 | 20 | package org.apache.cloudstack.direct.download; |
21 | 21 |
|
| 22 | + |
22 | 23 | import java.io.File; |
23 | 24 | import java.io.FileOutputStream; |
24 | 25 | import java.io.IOException; |
|
32 | 33 | import com.cloud.utils.Pair; |
33 | 34 | import com.cloud.utils.UriUtils; |
34 | 35 | import com.cloud.utils.exception.CloudRuntimeException; |
| 36 | +import com.cloud.utils.net.HttpClientCloudStackUserAgent; |
35 | 37 | import com.cloud.utils.storage.QCOW2Utils; |
36 | 38 | import org.apache.commons.collections.MapUtils; |
37 | 39 | import org.apache.commons.httpclient.HttpClient; |
38 | 40 | import org.apache.commons.httpclient.HttpStatus; |
39 | 41 | import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
40 | 42 | import org.apache.commons.httpclient.methods.GetMethod; |
41 | 43 | import org.apache.commons.httpclient.methods.HeadMethod; |
| 44 | +import org.apache.commons.httpclient.params.HttpMethodParams; |
42 | 45 | import org.apache.commons.io.IOUtils; |
43 | 46 |
|
44 | 47 | public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { |
@@ -68,6 +71,7 @@ public HttpDirectTemplateDownloader(String url, Long templateId, String destPool |
68 | 71 | protected GetMethod createRequest(String downloadUrl, Map<String, String> headers) { |
69 | 72 | GetMethod request = new GetMethod(downloadUrl); |
70 | 73 | request.setFollowRedirects(this.isFollowRedirects()); |
| 74 | + request.getParams().setParameter(HttpMethodParams.USER_AGENT, HttpClientCloudStackUserAgent.CLOUDSTACK_USER_AGENT); |
71 | 75 | if (MapUtils.isNotEmpty(headers)) { |
72 | 76 | for (String key : headers.keySet()) { |
73 | 77 | request.setRequestHeader(key, headers.get(key)); |
@@ -111,6 +115,7 @@ protected Pair<Boolean, String> performDownload() { |
111 | 115 | public boolean checkUrl(String url) { |
112 | 116 | HeadMethod httpHead = new HeadMethod(url); |
113 | 117 | httpHead.setFollowRedirects(this.isFollowRedirects()); |
| 118 | + httpHead.getParams().setParameter(HttpMethodParams.USER_AGENT, HttpClientCloudStackUserAgent.CLOUDSTACK_USER_AGENT); |
114 | 119 | try { |
115 | 120 | int responseCode = client.executeMethod(httpHead); |
116 | 121 | if (responseCode != HttpStatus.SC_OK) { |
|
0 commit comments