Skip to content

Commit c1eb8a5

Browse files
committed
handle review comment
1 parent 1fe48e1 commit c1eb8a5

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,8 @@ public class ApiConstants {
13641364

13651365
public static final String RECURSIVE_DOMAINS = "recursivedomains";
13661366

1367+
public static final String CLOUDSTACK_USER_AGENT = "CloudStack-Agent";
1368+
13671369
/**
13681370
* This enum specifies IO Drivers, each option controls specific policies on I/O.
13691371
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).

core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.cloud.storage.template;
2121

2222
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
23+
import static org.apache.cloudstack.api.ApiConstants.CLOUDSTACK_USER_AGENT;
2324

2425
import java.io.File;
2526
import java.io.IOException;
@@ -125,7 +126,7 @@ private GetMethod createRequest(String downloadUrl) {
125126
GetMethod request = new GetMethod(downloadUrl);
126127
request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
127128
request.setFollowRedirects(followRedirects);
128-
request.setRequestHeader("User-Agent", "CloudStack-Agent");
129+
request.getParams().setParameter(HttpMethodParams.USER_AGENT, CLOUDSTACK_USER_AGENT);
129130
return request;
130131
}
131132

core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
//
1919
package com.cloud.storage.template;
2020

21+
import static org.apache.cloudstack.api.ApiConstants.CLOUDSTACK_USER_AGENT;
22+
2123
import com.cloud.storage.StorageLayer;
2224
import com.cloud.utils.UriUtils;
2325
import org.apache.commons.httpclient.HttpClient;
@@ -59,6 +61,7 @@ protected GetMethod createRequest(String downloadUrl) {
5961
GetMethod request = new GetMethod(downloadUrl);
6062
request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
6163
request.setFollowRedirects(followRedirects);
64+
request.getParams().setParameter(HttpMethodParams.USER_AGENT, CLOUDSTACK_USER_AGENT);
6265
if (!toFileSet) {
6366
String[] parts = downloadUrl.split("/");
6467
String filename = parts[parts.length - 1];

core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.cloud.storage.template;
1919

2020
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
21+
import static org.apache.cloudstack.api.ApiConstants.CLOUDSTACK_USER_AGENT;
2122

2223
import java.io.File;
2324
import java.io.IOException;
@@ -95,6 +96,7 @@ private GetMethod createRequest(String downloadUrl) {
9596
GetMethod request = new GetMethod(downloadUrl);
9697
request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
9798
request.setFollowRedirects(followRedirects);
99+
request.getParams().setParameter(HttpMethodParams.USER_AGENT, CLOUDSTACK_USER_AGENT);
98100
return request;
99101
}
100102

core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.apache.cloudstack.direct.download;
2121

22+
import static org.apache.cloudstack.api.ApiConstants.CLOUDSTACK_USER_AGENT;
23+
2224
import java.io.File;
2325
import java.io.FileOutputStream;
2426
import java.io.IOException;
@@ -39,6 +41,7 @@
3941
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
4042
import org.apache.commons.httpclient.methods.GetMethod;
4143
import org.apache.commons.httpclient.methods.HeadMethod;
44+
import org.apache.commons.httpclient.params.HttpMethodParams;
4245
import org.apache.commons.io.IOUtils;
4346

4447
public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl {
@@ -68,6 +71,7 @@ public HttpDirectTemplateDownloader(String url, Long templateId, String destPool
6871
protected GetMethod createRequest(String downloadUrl, Map<String, String> headers) {
6972
GetMethod request = new GetMethod(downloadUrl);
7073
request.setFollowRedirects(this.isFollowRedirects());
74+
request.getParams().setParameter(HttpMethodParams.USER_AGENT, CLOUDSTACK_USER_AGENT);
7175
if (MapUtils.isNotEmpty(headers)) {
7276
for (String key : headers.keySet()) {
7377
request.setRequestHeader(key, headers.get(key));

0 commit comments

Comments
 (0)