Bug 1884666 - Only add Google additional header in search, preferences and webhp urls

(cherry picked from commit dcc48c0e7c0e8f650234a72c0bd805077bc64ce9)
fenix/124.1.0
Roger Yang 2 months ago committed by mergify[bot]
parent b62c0405d5
commit 085ee21558

@ -11,6 +11,8 @@ import mozilla.components.concept.engine.EngineSession.LoadUrlFlags.Companion.AL
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags.Companion.BYPASS_CACHE
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags.Companion.LOAD_FLAGS_BYPASS_LOAD_URI_DELEGATE
import mozilla.components.concept.engine.request.RequestInterceptor
import java.net.MalformedURLException
import java.net.URL
/**
* [RequestInterceptor] implementation for intercepting URL load requests to allow custom
@ -23,6 +25,7 @@ class UrlRequestInterceptor(private val isDeviceRamAboveThreshold: Boolean) : Re
private val isGoogleRequest by lazy {
Regex("^https://www\\.google\\..+")
}
private val googleRequestPaths = setOf("/search", "/webhp", "/preferences")
@VisibleForTesting
internal fun getAdditionalHeaders(isDeviceRamAboveThreshold: Boolean): Map<String, String> {
@ -42,7 +45,15 @@ class UrlRequestInterceptor(private val isDeviceRamAboveThreshold: Boolean) : Re
uri: String,
isSubframeRequest: Boolean,
): Boolean {
return !isSubframeRequest && isGoogleRequest.containsMatchIn(uri)
if (isSubframeRequest || !isGoogleRequest.containsMatchIn(uri)) {
return false
}
return try {
googleRequestPaths.contains(URL(uri).path)
} catch (e: MalformedURLException) {
false
}
}
override fun onLoadRequest(

@ -60,7 +60,7 @@ class UrlRequestInterceptorTest {
fun `WHEN should intercept request is called THEN return the correct boolean value`() {
val urlRequestInterceptor = getUrlRequestInterceptor()
assertTrue(
assertFalse(
urlRequestInterceptor.shouldInterceptRequest(
uri = "https://www.google.com",
isSubframeRequest = false,
@ -128,8 +128,8 @@ class UrlRequestInterceptorTest {
}
@Test
fun `WHEN a Google request is loaded THEN request is intercepted`() {
val uri = "https://www.google.com"
fun `WHEN a Google preferences request is loaded THEN request is intercepted`() {
val uri = "https://www.google.com/preferences"
assertEquals(
RequestInterceptor.InterceptionResponse.Url(

Loading…
Cancel
Save