Added support for User-Agent Client Hints

pull/208/head
M66B 3 years ago
parent 862fa5fba9
commit ea0483a842

@ -1510,7 +1510,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
urlConnection.setReadTimeout(UPDATE_TIMEOUT);
urlConnection.setConnectTimeout(UPDATE_TIMEOUT);
urlConnection.setDoOutput(false);
urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, urlConnection);
urlConnection.connect();
int status = urlConnection.getResponseCode();

@ -136,7 +136,7 @@ public class Bimi {
connection.setReadTimeout(READ_TIMEOUT);
connection.setConnectTimeout(CONNECT_TIMEOUT);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
try {
@ -174,7 +174,7 @@ public class Bimi {
connection.setReadTimeout(READ_TIMEOUT);
connection.setConnectTimeout(CONNECT_TIMEOUT);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
// Fetch PEM objects

@ -37,6 +37,7 @@ import com.sun.mail.iap.ConnectionException;
import com.sun.mail.util.FolderClosedIOException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
@ -623,4 +624,17 @@ public class ConnectionHelper {
}
return result;
}
static void setUserAgent(Context context, HttpURLConnection connection) {
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
// https://web.dev/migrate-to-ua-ch/
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA
connection.setRequestProperty("Sec-CH-UA", "\"Chromium\"");
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile
connection.setRequestProperty("Sec-CH-UA-Mobile", "?1");
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Platform
connection.setRequestProperty("Sec-CH-UA-Platform", "Android");
}
}

@ -571,7 +571,7 @@ public class ContactInfo {
return true;
}
});
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
Document doc;
@ -627,7 +627,7 @@ public class ContactInfo {
m.setReadTimeout(FAVICON_READ_TIMEOUT);
m.setConnectTimeout(FAVICON_CONNECT_TIMEOUT);
m.setInstanceFollowRedirects(true);
m.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, m);
m.connect();
try {
@ -859,7 +859,7 @@ public class ContactInfo {
return true;
}
});
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
try {
@ -888,7 +888,7 @@ public class ContactInfo {
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(GRAVATAR_READ_TIMEOUT);
urlConnection.setConnectTimeout(GRAVATAR_CONNECT_TIMEOUT);
urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, urlConnection);
urlConnection.connect();
try {
@ -934,7 +934,7 @@ public class ContactInfo {
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(LIBRAVATAR_READ_TIMEOUT);
urlConnection.setConnectTimeout(LIBRAVATAR_CONNECT_TIMEOUT);
urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, urlConnection);
urlConnection.connect();
try {

@ -254,7 +254,7 @@ public class DeepL {
connection.setDoOutput(true);
connection.setReadTimeout(DEEPL_TIMEOUT * 1000);
connection.setConnectTimeout(DEEPL_TIMEOUT * 1000);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Content-Length", Integer.toString(request.length()));
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
@ -315,7 +315,7 @@ public class DeepL {
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setReadTimeout(DEEPL_TIMEOUT * 1000);
connection.setConnectTimeout(DEEPL_TIMEOUT * 1000);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
try {

@ -117,7 +117,7 @@ public class DisconnectBlacklist {
connection.setRequestMethod("GET");
connection.setReadTimeout(FETCH_TIMEOUT);
connection.setConnectTimeout(FETCH_TIMEOUT);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
try {

@ -597,7 +597,7 @@ public class EmailProvider implements Parcelable {
request.setReadTimeout(ISPDB_TIMEOUT);
request.setConnectTimeout(ISPDB_TIMEOUT);
request.setDoInput(true);
request.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, request);
request.connect();
int status = request.getResponseCode();

@ -133,7 +133,7 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
connection.setReadTimeout(METADATA_READ_TIMEOUT);
connection.setConnectTimeout(METADATA_CONNECT_TIMEOUT);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
try {

@ -694,7 +694,7 @@ public class FragmentOAuth extends FragmentBase {
connection.setRequestMethod("GET");
connection.setReadTimeout(MAILRU_TIMEOUT);
connection.setConnectTimeout(MAILRU_TIMEOUT);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
try {

@ -2063,7 +2063,7 @@ public class Helper {
urlConnection.setReadTimeout(timeout);
urlConnection.setConnectTimeout(timeout);
urlConnection.setInstanceFollowRedirects(true);
urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, urlConnection);
urlConnection.connect();
try {

@ -75,7 +75,7 @@ public class IPInfo {
connection.setRequestMethod("GET");
connection.setReadTimeout(FETCH_TIMEOUT);
connection.setConnectTimeout(FETCH_TIMEOUT);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.connect();
Organization organization = new Organization();

@ -75,7 +75,7 @@ public class LanguageTool {
connection.setDoOutput(true);
connection.setReadTimeout(LT_TIMEOUT * 1000);
connection.setConnectTimeout(LT_TIMEOUT * 1000);
connection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
ConnectionHelper.setUserAgent(context, connection);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Length", Integer.toString(request.length()));
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

Loading…
Cancel
Save