diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-09-12 20:42:35 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-09-12 20:42:35 +0200 |
commit | 092beba1ba5f54c5cdfbc53cbc7eb70724bce8ca (patch) | |
tree | 47babe1bfc9ad9002a7e0fc94488d818c548274f /src/main/java/de/pixart/messenger | |
parent | 88574e39d27a44bab1555f25dde062b1abf602bc (diff) |
set Messenger identity as userAgent for RichPreview and ChannelDiscovery
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java | 23 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/RichPreview.java | 1 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java b/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java index ac790b10f..e78d1702c 100644 --- a/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java +++ b/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java @@ -5,6 +5,8 @@ import android.util.Log; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import org.jetbrains.annotations.NotNull; + import java.io.IOException; import java.util.Collections; import java.util.List; @@ -14,7 +16,9 @@ import java.util.concurrent.TimeUnit; import de.pixart.messenger.Config; import de.pixart.messenger.http.HttpConnectionManager; import de.pixart.messenger.http.services.MuclumbusService; +import okhttp3.Interceptor; import okhttp3.OkHttpClient; +import okhttp3.Request; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -43,6 +47,7 @@ public class ChannelDiscoveryService { throw new RuntimeException("Unable to use Tor proxy", e); } } + builder.networkInterceptors().add(new UserAgentInterceptor(service.getIqGenerator().getUserAgent())); Retrofit retrofit = new Retrofit.Builder() .client(builder.build()) .baseUrl(Config.CHANNEL_DISCOVERY) @@ -118,4 +123,22 @@ public class ChannelDiscoveryService { public interface OnChannelSearchResultsFound { void onChannelSearchResultsFound(List<MuclumbusService.Room> results); } + + private class UserAgentInterceptor implements Interceptor { + private final String userAgent; + + UserAgentInterceptor(String userAgent) { + this.userAgent = userAgent; + } + + @NotNull + @Override + public okhttp3.Response intercept(Chain chain) throws IOException { + Request originalRequest = chain.request(); + Request requestWithUserAgent = originalRequest.newBuilder() + .header("User-Agent", userAgent) + .build(); + return chain.proceed(requestWithUserAgent); + } + } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/utils/RichPreview.java b/src/main/java/de/pixart/messenger/utils/RichPreview.java index 0759b185b..7325f9af4 100644 --- a/src/main/java/de/pixart/messenger/utils/RichPreview.java +++ b/src/main/java/de/pixart/messenger/utils/RichPreview.java @@ -183,6 +183,7 @@ public class RichPreview { try { doc = Jsoup.connect(url) .timeout(Config.CONNECT_TIMEOUT * 1000) + .userAgent(xmppConnectionService.getIqGenerator().getUserAgent()) .get(); } catch (Exception e) { e.printStackTrace(); |