From c3d422b9a5e4aad18e48c432e03c3a179f7f4912 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 17 Jul 2019 11:39:31 -0700 Subject: [PATCH] Update the request headers in View Source. https://redmine.stoutner.com/issues/445 --- .../privacybrowser/asynctasks/GetSource.java | 62 ++++++++++++------- app/src/main/res/values-de/strings.xml | 5 +- app/src/main/res/values-es/strings.xml | 5 +- app/src/main/res/values-it/strings.xml | 5 +- app/src/main/res/values-ru/strings.xml | 5 +- 5 files changed, 53 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java index 680fb7f8..2a320c39 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetSource.java @@ -108,7 +108,7 @@ public class GetSource extends AsyncTask // Open a connection to the URL. No data is actually sent at this point. HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection(); - // Instantiate the variables necessary to build the request headers. + // Define the variables necessary to build the request headers. requestHeadersBuilder = new SpannableStringBuilder(); int oldRequestHeadersBuilderLength; int newRequestHeadersBuilderLength; @@ -146,37 +146,37 @@ public class GetSource extends AsyncTask requestHeadersBuilder.append(": keep-alive"); - // Set the `User-Agent` header property. - httpUrlConnection.setRequestProperty("User-Agent", userAgent); + // Set the `Upgrade-Insecure-Requests` header property. + httpUrlConnection.setRequestProperty("Upgrade-Insecure-Requests", "1"); - // Add the `User-Agent` header to the string builder and format the text. + // Add the `Upgrade-Insecure-Requests` header to the string builder and format the text. requestHeadersBuilder.append(System.getProperty("line.separator")); if (Build.VERSION.SDK_INT >= 21) { // Newer versions of Android are so smart. - requestHeadersBuilder.append("User-Agent", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + requestHeadersBuilder.append("Upgrade-Insecure-Requests", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { // Older versions not so much. oldRequestHeadersBuilderLength = requestHeadersBuilder.length(); - requestHeadersBuilder.append("User-Agent"); + requestHeadersBuilder.append("Upgrade-Insecure_Requests"); newRequestHeadersBuilderLength = requestHeadersBuilder.length(); requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } - requestHeadersBuilder.append(": "); - requestHeadersBuilder.append(userAgent); + requestHeadersBuilder.append(": 1"); - // Set the `Upgrade-Insecure-Requests` header property. - httpUrlConnection.setRequestProperty("Upgrade-Insecure-Requests", "1"); + // Set the `User-Agent` header property. + httpUrlConnection.setRequestProperty("User-Agent", userAgent); - // Add the `Upgrade-Insecure-Requests` header to the string builder and format the text. + // Add the `User-Agent` header to the string builder and format the text. requestHeadersBuilder.append(System.getProperty("line.separator")); if (Build.VERSION.SDK_INT >= 21) { // Newer versions of Android are so smart. - requestHeadersBuilder.append("Upgrade-Insecure-Requests", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + requestHeadersBuilder.append("User-Agent", new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { // Older versions not so much. oldRequestHeadersBuilderLength = requestHeadersBuilder.length(); - requestHeadersBuilder.append("Upgrade-Insecure_Requests"); + requestHeadersBuilder.append("User-Agent"); newRequestHeadersBuilderLength = requestHeadersBuilder.length(); requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } - requestHeadersBuilder.append(": 1"); + requestHeadersBuilder.append(": "); + requestHeadersBuilder.append(userAgent); // Set the `x-requested-with` header property. @@ -218,7 +218,7 @@ public class GetSource extends AsyncTask // Set the `Accept` header property. - httpUrlConnection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); + httpUrlConnection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"); // Add the `Accept` header to the string builder and format the text. requestHeadersBuilder.append(System.getProperty("line.separator")); @@ -231,7 +231,7 @@ public class GetSource extends AsyncTask requestHeadersBuilder.setSpan(new StyleSpan(Typeface.BOLD), oldRequestHeadersBuilderLength + 1, newRequestHeadersBuilderLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } requestHeadersBuilder.append(": "); - requestHeadersBuilder.append("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); + requestHeadersBuilder.append("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"); // Instantiate a locale string. @@ -255,17 +255,37 @@ public class GetSource extends AsyncTask localesStringBuilder.append(","); } - // Get the indicated locale from the list. - localesStringBuilder.append(localeList.get(i)); + // Get the locale from the list. + Locale locale = localeList.get(i); - // If not the first locale, append `;q=0.i`, which drops by .1 for each removal from the main locale. + // Add the locale to the string. `locale` by default displays as `en_US`, but WebView uses the `en-US` format. + localesStringBuilder.append(locale.getLanguage()); + localesStringBuilder.append("-"); + localesStringBuilder.append(locale.getCountry()); + + // If not the first locale, append `;q=0.x`, which drops by .1 for each removal from the main locale until q=0.1. if (q < 10) { localesStringBuilder.append(";q=0."); localesStringBuilder.append(q); } - // Decrement `q`. - q--; + // Decrement `q` if it is greater than 1. + if (q > 1) { + q--; + } + + // Add a second entry for the language only portion of the locale. + localesStringBuilder.append(","); + localesStringBuilder.append(locale.getLanguage()); + + // Append `1;q=0.x`, which drops by .1 for each removal form the main locale until q=0.1. + localesStringBuilder.append(";q=0."); + localesStringBuilder.append(q); + + // Decrement `q` if it is greater than 1. + if (q > 1) { + q--; + } } // Store the populated string builder in the locale string. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 29b2dafc..ebec1e0d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -194,6 +194,7 @@ In neuem Tab öffnen + Grafik in neuem Tab öffnen URL kopieren Download URL E-Mail-Adresse @@ -510,9 +511,9 @@ Alle Zugriffe auf Dritt-Anbieter-Inhalte zu blockieren verbessert die Privatsphäre, kann jedoch Webseiten verunstalten. URL-Bereinigung Google Analytics - Entfernt “?utm_” oder “&utm_” sowie alles danach aus URLs. + Entfernt “?utm_” und “&utm_” sowie alles danach aus URLs. Facebook Click-IDs - Entfernt “?fbclid=” or “&fbclid=” sowie alles danach aus URLs. + Entfernt “?fbclid=”, “&fbclid=”, “?fbadid=” und “&fbadid=” sowie alles danach aus URLs. Twitter AMP-Umleitungen Entfernt “?amp=1” sowie alles danach URLs. Tor diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 769a5c94..28892e85 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -191,6 +191,7 @@ Abrir en nueva pestaña + Abrir imagen en nueva pestaña Copiar URL Descargar URL Correo electrónico @@ -509,9 +510,9 @@ Bloquear todas las solicitudes de terceras partes aumenta la privacidad, pero rompe muchas páginas web. Modificación de URL Google Analytics - Eliminar “?utm_” o “&utm_” y cualquier cosa después de esto de las URLs. + Eliminar “?utm_”, “&utm_” y cualquier cosa tras ello de las URLs. IDs de clics en Facebook - Eliminar “?fbclid=” o “&fbclid=” y cualquier cosa después de esto de las URLs. + Eliminar “?fbclid=”, “&fbclid=”, “?fbadid=”, “&fbadid=” y cualquier cosa tras ello de las URLs. Redirecciones de Twitter AMP Eliminar “?amp=1” y cualquier cosa después de esto de las URLs. Tor diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 854c72da..f36315db 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -191,6 +191,7 @@ Apri in una nuova Scheda + Apri l\'immagine in una nuova scheda Copia URL Scarica URL Indirizzo Email @@ -509,9 +510,9 @@ Il blocco di tutte le richieste di Terze Parti aumenta privacy, ma impedisce la visualizzazione di molti siti web. Modifica delle URL Google Analytics - Rimuovi “?utm_” o “&utm_” e tutto quello che segue dalle URL. + Rimuovi “?utm_” e “&utm_” e tutto quello che segue dalle URL. Facebook Click ID - Rimuovi “?fbclid=” o “&fbclid=” e tutto quello che segue dalle URL. + Rimuovi “?fbclid=”, “&fbclid=”, “?fbadid=”, e “&fbadid=” e tutto quello che segue dalle URL. Reindirizzamenti Twitter AMP Rimuovi “?amp=1” e tutto quello che segue dalle URL. Tor diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index e1aa0a42..4f42f347 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -188,6 +188,7 @@ Открыть в новой вкладке + Открыть изображение в новой вкладке Копировать URL Загрузить URL Адрес email @@ -503,9 +504,9 @@ Блокировка всех сторонних запросов повышает конфиденциальность, но ломает многие веб-сайты. Модификация URL Google Analytics - Удалять из URL “?utm_” или “&utm_” и все что будет после. + Удалять из URL “?utm_” и “&utm_” и все что будет после. Идентификаторы кликов в Facebook - Удалять из URL “?fbclid=” или “&fbclid=” и все что будет после. + Удалять из URL “?fbclid=”, “&fbclid=”, “?fbadid=”, и “&fbadid=” и все что будет после. AMP-перенаправления в Twitter Удалять из URL “?amp=1” и все что будет после. Tor -- 2.45.2