Commit 20f5c0f7 authored by Mirko Friedenhagen's avatar Mirko Friedenhagen Committed by Tim Olshansky

Modify user agent (#187)

* Add additional fields for Runner.

The current model is missing some fields.

* Make the User-Agent settable.

This makes it easier to see which program executed requests.
parent ca6cf2a7
...@@ -48,6 +48,7 @@ public class GitlabAPI { ...@@ -48,6 +48,7 @@ public class GitlabAPI {
private AuthMethod authMethod; private AuthMethod authMethod;
private boolean ignoreCertificateErrors = false; private boolean ignoreCertificateErrors = false;
private int requestTimeout = 0; private int requestTimeout = 0;
private String userAgent = GitlabAPI.class.getCanonicalName() + "/" + System.getProperty("java.version");
private GitlabAPI(String hostUrl, String apiToken, TokenType tokenType, AuthMethod method) { private GitlabAPI(String hostUrl, String apiToken, TokenType tokenType, AuthMethod method) {
this.hostUrl = hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl; this.hostUrl = hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl;
...@@ -2482,4 +2483,17 @@ public class GitlabAPI { ...@@ -2482,4 +2483,17 @@ public class GitlabAPI {
projects = Arrays.asList(response); projects = Arrays.asList(response);
return projects; return projects;
} }
/**
* Set the User-Agent header for the requests.
*
* @param userAgent
*/
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
public String getUserAgent() {
return userAgent;
}
} }
...@@ -380,7 +380,7 @@ public class GitlabHTTPRequestor { ...@@ -380,7 +380,7 @@ public class GitlabHTTPRequestor {
throw (IOException) new IOException("Failed to set the custom verb").initCause(x); throw (IOException) new IOException("Failed to set the custom verb").initCause(x);
} }
} }
connection.setRequestProperty("User-Agent", root.getUserAgent());
connection.setRequestProperty("Accept-Encoding", "gzip"); connection.setRequestProperty("Accept-Encoding", "gzip");
return connection; return connection;
} }
......
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