From 5a5e0e7121d2c068db33c70e1f26475e42ca7ade Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 23 Sep 2015 18:05:51 +0200 Subject: [PATCH] use Conversations 1.x.y as user agent string in http upload and download --- .../eu/siacs/conversations/generator/AbstractGenerator.java | 6 +++--- .../eu/siacs/conversations/http/HttpDownloadConnection.java | 2 ++ .../eu/siacs/conversations/http/HttpUploadConnection.java | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java index 69bb18036..879a56802 100644 --- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java @@ -36,8 +36,8 @@ public abstract class AbstractGenerator { "urn:xmpp:receipts" }; private String mVersion = null; - public final String IDENTITY_NAME = "Conversations"; - public final String IDENTITY_TYPE = "phone"; + protected final String IDENTITY_NAME = "Conversations"; + protected final String IDENTITY_TYPE = "phone"; private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); @@ -54,7 +54,7 @@ public abstract class AbstractGenerator { return this.mVersion; } - protected String getIdentityName() { + public String getIdentityName() { return IDENTITY_NAME + " " + getIdentityVersion(); } diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 0d202bb92..5fa7bf816 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -181,6 +181,7 @@ public class HttpDownloadConnection implements Transferable { changeStatus(STATUS_CHECKING); HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection(); connection.setRequestMethod("HEAD"); + connection.setRequestProperty("User-Agent", mXmppConnectionService.getIqGenerator().getIdentityName()); if (connection instanceof HttpsURLConnection) { mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive); } @@ -236,6 +237,7 @@ public class HttpDownloadConnection implements Transferable { if (connection instanceof HttpsURLConnection) { mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive); } + connection.setRequestProperty("User-Agent",mXmppConnectionService.getIqGenerator().getIdentityName()); connection.connect(); is = new BufferedInputStream(connection.getInputStream()); file.getParentFile().mkdirs(); diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index 38e25e7af..3aa288813 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -165,6 +165,7 @@ public class HttpUploadConnection implements Transferable { connection.setRequestMethod("PUT"); connection.setFixedLengthStreamingMode((int) file.getExpectedSize()); connection.setRequestProperty("Content-Type", mime == null ? "application/octet-stream" : mime); + connection.setRequestProperty("User-Agent",mXmppConnectionService.getIqGenerator().getIdentityName()); connection.setDoOutput(true); connection.connect(); os = connection.getOutputStream();