-
Notifications
You must be signed in to change notification settings - Fork 13
Android proxy implementation #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
NiklasMerz
wants to merge
9
commits into
master
Choose a base branch
from
android
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c7e490
(android): Add basic proxy test
NiklasMerz 0808b69
First https proxy
NiklasMerz b45ca2e
Switch to new approach
NiklasMerz 218446b
Merge branch 'master' into android
NiklasMerz 8cdf2b7
fixes for android
NiklasMerz 0a5ba23
Update plugin.xml
NiklasMerz 85558d4
Update plugin.xml
NiklasMerz abb05e8
Support http
NiklasMerz 5f45321
Add framework again
NiklasMerz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
| package com.gi.cordova.plugin.webviewproxy; | ||
|
|
||
| import android.util.Log; | ||
| import android.webkit.WebResourceResponse; | ||
|
|
||
| import org.apache.cordova.CallbackContext; | ||
| import org.apache.cordova.CordovaInterface; | ||
| import org.apache.cordova.CordovaPlugin; | ||
| import org.apache.cordova.CordovaPluginPathHandler; | ||
| import org.apache.cordova.CordovaWebView; | ||
| import org.json.JSONArray; | ||
|
|
||
| import java.io.BufferedInputStream; | ||
| import java.io.InputStream; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
| import java.util.HashMap; | ||
|
|
||
| import androidx.webkit.WebViewAssetLoader; | ||
|
|
||
| public class WebviewProxy extends CordovaPlugin { | ||
|
|
||
| public void initialize(CordovaInterface cordova, CordovaWebView webView) { | ||
| super.initialize(cordova, webView); | ||
|
|
||
| Log.d("WebviewProxy", "Proxy init"); | ||
| } | ||
|
|
||
| public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { | ||
| return false; | ||
| } | ||
|
|
||
| public CordovaPluginPathHandler getPathHandler() { | ||
| WebViewAssetLoader.PathHandler pathHandler = new WebViewAssetLoader.PathHandler() { | ||
| @Override | ||
| public WebResourceResponse handle(String path) { | ||
| if (path.startsWith("_https_proxy_") || path.startsWith("_http_proxy_")) { | ||
| try { | ||
| URL url = new URL(path.replace("_https_proxy_", "https://").replace("_http_proxy_", "http://")); | ||
| HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | ||
| try { | ||
| InputStream in = new BufferedInputStream(urlConnection.getInputStream()); | ||
| String mimeType = urlConnection.getContentType(); | ||
| return new WebResourceResponse(mimeType, null, in); | ||
| } finally { | ||
| //urlConnection.disconnect(); | ||
| } | ||
| } catch(Exception e) { | ||
| Log.e("WebviewProxy", e.getMessage()); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| Log.d("WebviewProxy", "Add proxy"); | ||
| return new CordovaPluginPathHandler(pathHandler); | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.