Bug 1881128 - Add additional headers for Google requests

(cherry picked from commit 9bc558c887908470ee1746518cc9926a930ecc3e)
fenix/124.1.0
Gabriel Luong 3 months ago committed by mergify[bot]
parent ae5f908543
commit 36886c0d0a

@ -19,8 +19,8 @@ import mozilla.components.concept.engine.request.RequestInterceptor
*/
class UrlRequestInterceptor(private val isDeviceRamAboveThreshold: Boolean) : RequestInterceptor {
private val isGoogleSearchRequest by lazy {
Regex("^https://www\\.google\\.(?:.+)/search")
private val isGoogleRequest by lazy {
Regex("^https://www\\.google\\..+")
}
@VisibleForTesting
@ -41,7 +41,7 @@ class UrlRequestInterceptor(private val isDeviceRamAboveThreshold: Boolean) : Re
uri: String,
isSubframeRequest: Boolean,
): Boolean {
return !isSubframeRequest && isGoogleSearchRequest.containsMatchIn(uri)
return !isSubframeRequest && isGoogleRequest.containsMatchIn(uri)
}
override fun onLoadRequest(

@ -59,15 +59,21 @@ class UrlRequestInterceptorTest {
fun `WHEN should intercept request is called THEN return the correct boolean value`() {
val urlRequestInterceptor = getUrlRequestInterceptor()
assertFalse(
assertTrue(
urlRequestInterceptor.shouldInterceptRequest(
uri = "https://getpocket.com",
uri = "https://www.google.com",
isSubframeRequest = false,
),
)
assertFalse(
assertTrue(
urlRequestInterceptor.shouldInterceptRequest(
uri = "https://www.google.com",
uri = "https://www.google.com/webhp",
isSubframeRequest = false,
),
)
assertTrue(
urlRequestInterceptor.shouldInterceptRequest(
uri = "https://www.google.com/preferences",
isSubframeRequest = false,
),
)
@ -89,6 +95,13 @@ class UrlRequestInterceptorTest {
isSubframeRequest = false,
),
)
assertFalse(
urlRequestInterceptor.shouldInterceptRequest(
uri = "https://getpocket.com",
isSubframeRequest = false,
),
)
assertFalse(
urlRequestInterceptor.shouldInterceptRequest(
uri = "https://www.google.com/search?q=blue",
@ -114,13 +127,24 @@ class UrlRequestInterceptorTest {
}
@Test
fun `WHEN a Google request is loaded THEN request is not intercepted`() {
fun `WHEN a Google request is loaded THEN request is intercepted`() {
val uri = "https://www.google.com"
val response = getUrlRequestInterceptor().onLoadRequest(
uri = uri,
)
assertNull(response)
assertEquals(
RequestInterceptor.InterceptionResponse.Url(
url = uri,
flags = LoadUrlFlags.select(
LOAD_FLAGS_BYPASS_LOAD_URI_DELEGATE,
ALLOW_ADDITIONAL_HEADERS,
),
additionalHeaders = mapOf(
"X-Search-Subdivision" to "0",
),
),
getUrlRequestInterceptor().onLoadRequest(
uri = uri,
),
)
}
@Test

Loading…
Cancel
Save