forked from mozilla-mobile/focus-android
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes mozilla-mobile#4764: Create wrapper for Client to prevent non-…
…private requests.
- Loading branch information
Showing
6 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/org/mozilla/focus/engine/ClientWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.engine | ||
|
||
import mozilla.components.concept.fetch.Client | ||
import mozilla.components.concept.fetch.Request | ||
import mozilla.components.concept.fetch.Response | ||
|
||
/** | ||
* A wrapper around [Client] preventing [Request]s without the private flag set. | ||
*/ | ||
class ClientWrapper( | ||
private val actual: Client | ||
) : Client() { | ||
override fun fetch(request: Request): Response { | ||
if (!request.private) { | ||
throw IllegalStateException("Non-private request") | ||
} | ||
|
||
return actual.fetch(request) | ||
} | ||
|
||
@Deprecated("Non-private Client usage should be prevented") | ||
fun unwrap(): Client { | ||
return actual | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters