Java Code Examples for android.webkit.WebResourceRequest#getRequestHeaders()
The following examples show how to use
android.webkit.WebResourceRequest#getRequestHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebViewCacheImpl.java From FastWebView with MIT License | 6 votes |
@Override public WebResourceResponse getResource(WebResourceRequest webResourceRequest, int cacheMode, String userAgent) { if (mFastCacheMode == FastCacheMode.DEFAULT) { throw new IllegalStateException("an error occurred."); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { String url = webResourceRequest.getUrl().toString(); String extension = MimeTypeMapUtils.getFileExtensionFromUrl(url); String mimeType = MimeTypeMapUtils.getMimeTypeFromExtension(extension); CacheRequest cacheRequest = new CacheRequest(); cacheRequest.setUrl(url); cacheRequest.setMime(mimeType); cacheRequest.setForceMode(mFastCacheMode == FastCacheMode.FORCE); cacheRequest.setUserAgent(userAgent); cacheRequest.setWebViewCacheMode(cacheMode); Map<String, String> headers = webResourceRequest.getRequestHeaders(); cacheRequest.setHeaders(headers); return getOfflineServer().get(cacheRequest); } throw new IllegalStateException("an error occurred."); }
Example 2
Source File: HybridCacheManager.java From HybridCache with MIT License | 5 votes |
/** * call this method in {@link android.webkit.WebViewClient#shouldInterceptRequest(WebView, WebResourceRequest)} * * @param request the web res request * @return */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public WebResourceResponse interceptWebResRequest(WebResourceRequest request) { String url = request.getUrl().toString(); Map<String, String> headers = request.getRequestHeaders(); return interceptWebResRequest(url, headers); }
Example 3
Source File: Web3ViewClient.java From Web3View with GNU General Public License v3.0 | 4 votes |
@Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { if (request == null) { return null; } if (!request.getMethod().equalsIgnoreCase("GET") || !request.isForMainFrame()) { if (request.getMethod().equalsIgnoreCase("GET") && (request.getUrl().toString().contains(".js") || request.getUrl().toString().contains("json") || request.getUrl().toString().contains("css"))) { synchronized (lock) { if (!isInjected) { injectScriptFile(view); isInjected = true; } } } super.shouldInterceptRequest(view, request); return null; } HttpUrl httpUrl = HttpUrl.parse(request.getUrl().toString()); if (httpUrl == null) { return null; } Map<String, String> headers = request.getRequestHeaders(); JsInjectorResponse response; try { response = jsInjectorClient.loadUrl(httpUrl.toString(), headers); } catch (Exception ex) { return null; } if (response == null || response.isRedirect) { return null; } else { ByteArrayInputStream inputStream = new ByteArrayInputStream(response.data.getBytes()); WebResourceResponse webResourceResponse = new WebResourceResponse( response.mime, response.charset, inputStream); synchronized (lock) { isInjected = true; } return webResourceResponse; } }
Example 4
Source File: Web3ViewClient.java From alpha-wallet-android with MIT License | 4 votes |
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { if (request == null) { return null; } if (!request.getMethod().equalsIgnoreCase("GET") || !request.isForMainFrame()) { if (request.getMethod().equalsIgnoreCase("GET") && (request.getUrl().toString().contains(".js") || request.getUrl().toString().contains("json") || request.getUrl().toString().contains("css"))) { synchronized (lock) { if (!isInjected) { injectScriptFile(view); isInjected = true; } } } super.shouldInterceptRequest(view, request); return null; } //check for known extensions if (handleTrustedExtension(request.getUrl().toString())) { return null; } HttpUrl httpUrl = HttpUrl.parse(request.getUrl().toString()); if (httpUrl == null) { return null; } Map<String, String> headers = request.getRequestHeaders(); JsInjectorResponse response; try { response = jsInjectorClient.loadUrl(httpUrl.toString(), headers); } catch (Exception ex) { return null; } if (response == null || response.isRedirect) { return null; } else if (TextUtils.isEmpty(response.data)){ return null; } else { ByteArrayInputStream inputStream = new ByteArrayInputStream(response.data.getBytes()); WebResourceResponse webResourceResponse = new WebResourceResponse( response.mime, response.charset, inputStream); synchronized (lock) { isInjected = true; } return webResourceResponse; } }