File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ # Request Interception
2+
3+ Starting from version 1.9.8, this library provides a ` RequestInterceptor ` to allow developers to
4+ intercept the request and modify the request headers. It only supports the Android and iOS platform
5+ for now.
6+
7+ ## RequestInterceptor
8+
9+ ``` kotlin
10+ /* *
11+ * Interface for intercepting requests in WebView.
12+ */
13+ interface RequestInterceptor {
14+ fun onInterceptUrlRequest (
15+ request : WebRequest ,
16+ navigator : WebViewNavigator ,
17+ ): WebRequestInterceptResult
18+ }
19+ ```
20+
21+ The ` onInterceptUrlRequest ` method will be called when the WebView sends a request.
22+
23+ ## Sample
24+
25+ Developers can implement the ` RequestInterceptor ` interface to define their own interceptor.
26+ Then they can pass it to the ` rememberWebViewNavigator ` method to intercept the request.
27+
28+ ``` kotlin
29+ val navigator =
30+ rememberWebViewNavigator(
31+ requestInterceptor =
32+ object : RequestInterceptor {
33+ override fun onInterceptUrlRequest (
34+ request : WebRequest ,
35+ navigator : WebViewNavigator ,
36+ ): WebRequestInterceptResult {
37+ return if (request.url.contains(" kotlin" )) {
38+ WebRequestInterceptResult .Modify (
39+ WebRequest (
40+ url = " https://kotlinlang.org/docs/multiplatform.html" ,
41+ headers = mutableMapOf (" info" to " test" ),
42+ ),
43+ )
44+ } else {
45+ WebRequestInterceptResult .Allow
46+ }
47+ }
48+ },
49+ )
50+ ```
You can’t perform that action at this time.
0 commit comments