mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 16:19:33 +01:00
Open up link previews to work with all sites.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.thoughtcrime.securesms.net;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -52,7 +54,13 @@ public class ContentProxySafetyInterceptor implements Interceptor {
|
||||
return isWhitelisted(url.toString());
|
||||
}
|
||||
|
||||
private static boolean isWhitelisted(@Nullable String url) {
|
||||
return LinkPreviewUtil.isWhitelistedLinkUrl(url) || LinkPreviewUtil.isWhitelistedMediaUrl(url);
|
||||
private static boolean isWhitelisted(@Nullable String rawUrl) {
|
||||
if (rawUrl == null) return false;
|
||||
|
||||
HttpUrl url = HttpUrl.parse(rawUrl);
|
||||
|
||||
return url != null &&
|
||||
"https".equals(url.scheme()) &&
|
||||
ContentProxySelector.WHITELISTED_DOMAINS.contains(url.topPrivateDomain());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package org.thoughtcrime.securesms.net;
|
||||
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewDomains;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -25,10 +21,9 @@ public class ContentProxySelector extends ProxySelector {
|
||||
|
||||
private static final String TAG = ContentProxySelector.class.getSimpleName();
|
||||
|
||||
private static final Set<String> WHITELISTED_DOMAINS = new HashSet<>();
|
||||
public static final Set<String> WHITELISTED_DOMAINS = new HashSet<>();
|
||||
static {
|
||||
WHITELISTED_DOMAINS.addAll(LinkPreviewDomains.LINKS);
|
||||
WHITELISTED_DOMAINS.addAll(LinkPreviewDomains.IMAGES);
|
||||
WHITELISTED_DOMAINS.add("giphy.com");
|
||||
}
|
||||
|
||||
private final List<Proxy> CONTENT = new ArrayList<Proxy>(1) {{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.thoughtcrime.securesms.net;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
|
||||
/**
|
||||
* The user agent that should be used by default -- includes app name, version, etc.
|
||||
*/
|
||||
public class StandardUserAgentInterceptor extends UserAgentInterceptor {
|
||||
|
||||
public StandardUserAgentInterceptor() {
|
||||
super("Signal-Android " + BuildConfig.VERSION_NAME + " (API " + Build.VERSION.SDK_INT + ")");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,7 @@
|
||||
package org.thoughtcrime.securesms.net;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
@@ -13,12 +9,16 @@ import okhttp3.Response;
|
||||
|
||||
public class UserAgentInterceptor implements Interceptor {
|
||||
|
||||
private static final String USER_AGENT = "Signal-Android " + BuildConfig.VERSION_NAME + " (API " + Build.VERSION.SDK_INT + ")";
|
||||
private final String userAgent;
|
||||
|
||||
public UserAgentInterceptor(@NonNull String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(@NonNull Chain chain) throws IOException {
|
||||
return chain.proceed(chain.request().newBuilder()
|
||||
.header("User-Agent", USER_AGENT)
|
||||
.header("User-Agent", userAgent)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user