From f6d37dc1856a7c3522a28d19bb3b7c5323f78703 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Thu, 12 Oct 2023 13:36:32 -0400 Subject: [PATCH 1/6] Update README.md --- x/mobileproxy/README.md | 42 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index d4043298..078ace14 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -2,7 +2,7 @@ This package enables the use Go Mobile to generate a mobile library to run a local proxy and configure your app networking libraries. -### Build the Go Mobile binaries with [`go build`](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) +## Build the Go Mobile binaries with [`go build`](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) From the `x/` directory: @@ -10,7 +10,7 @@ From the `x/` directory: go build -o ./out/ golang.org/x/mobile/cmd/gomobile golang.org/x/mobile/cmd/gobind ``` -### Build the iOS and Android libraries with [`gomobile bind`](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile#hdr-Build_a_library_for_Android_and_iOS) +## Build the iOS and Android libraries with [`gomobile bind`](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile#hdr-Build_a_library_for_Android_and_iOS) ```bash PATH="$(pwd)/out:$PATH" gomobile bind -ldflags='-s -w' -target=ios -iosversion=11.0 -o "$(pwd)/out/mobileproxy.xcframework" github.com/Jigsaw-Code/outline-sdk/x/mobileproxy @@ -181,12 +181,46 @@ public final class Proxy implements Seq.Proxy { -### Integrate into your mobile project +## Add the library to your mobile project To add the library to your mobile project, see Go Mobile's [Building and deploying to iOS](https://github.com/golang/go/wiki/Mobile#building-and-deploying-to-ios-1) and [Building and deploying to Android](https://github.com/golang/go/wiki/Mobile#building-and-deploying-to-android-1). +## Use the library -### Clean up +You need to call the `RunProxy` function passing the local address to use, and the transport configuration. + +In Java, you have: +```java +// Use port zero to let the system pick an open port for you. +mobileproxy.Proxy proxy = mobileproxy.runProxy("localhost:0", "split:3"); +// Find the address the local proxy is bound to. +String proxyAddress = proxy.address(); +// Configure your networking library with proxyAddress. +... +// Stops the proxy. +proxy.stop(); +``` + +## Configure your HTTP client or networking library + +You need to configure your networking library to use the local proxy. How you do it depends on the networking library you are using. + +### Flutter HttpClient + +Set the proxy with the the [HttpClient.findProxy]([url](https://api.flutter.dev/flutter/dart-io/HttpClient/findProxy.html)) function. Example: + +```dart + HttpClient client = HttpClient(); + client.findProxy = (Uri uri) { + return "PROXY localhost:1234"; + }; +``` + + +### OkHttp (Android only) + + +## Clean up ```bash rm -rf ./out/ From fabe27ad6b60a7fbee8f73175230d2e6ab775522 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Thu, 12 Oct 2023 15:21:33 -0400 Subject: [PATCH 2/6] Update README.md --- x/mobileproxy/README.md | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index 078ace14..f8be0000 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -205,9 +205,12 @@ proxy.stop(); You need to configure your networking library to use the local proxy. How you do it depends on the networking library you are using. -### Flutter HttpClient -Set the proxy with the the [HttpClient.findProxy]([url](https://api.flutter.dev/flutter/dart-io/HttpClient/findProxy.html)) function. Example: +### Dart/Flutter HttpClient + +Set the proxy with the [`HttpClient.findProxy`]([url](https://api.flutter.dev/flutter/dart-io/HttpClient/findProxy.html)) function. + +Dart example: ```dart HttpClient client = HttpClient(); @@ -219,6 +222,27 @@ Set the proxy with the the [HttpClient.findProxy]([url](https://api.flutter.dev/ ### OkHttp (Android only) +Set the proxy with [`OkHttpClient.Builder.proxy`](https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/proxy/). + +Kotlin example: + +```kotlin +val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", 1234)) +val client = OkHttpClient.Builder().proxy(proxy).build() +``` +https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/proxy/ + + +### Java + +In the JVM, you can configure the proxy to use with [system properties](https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html): +```java +System.setProperty("http.proxyHost", "localhost"); +System.setProperty("http.proxyPort", "1234"); +``` + +Note that this may not fully work on Android, since it will only affect the JVM, not native code. You should also make sure you set this early in your code. + ## Clean up From 95924f06511c18503a28b6ca18ed782d3eef95ff Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Thu, 12 Oct 2023 15:23:29 -0400 Subject: [PATCH 3/6] Update Android example to use kotlin --- x/mobileproxy/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index f8be0000..a7efdf95 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -189,16 +189,16 @@ To add the library to your mobile project, see Go Mobile's [Building and deployi You need to call the `RunProxy` function passing the local address to use, and the transport configuration. -In Java, you have: -```java +On Android, you can have the following Kotlin code: +```kotlin // Use port zero to let the system pick an open port for you. -mobileproxy.Proxy proxy = mobileproxy.runProxy("localhost:0", "split:3"); +val proxy = mobileproxy.runProxy("localhost:0", "split:3") // Find the address the local proxy is bound to. -String proxyAddress = proxy.address(); +val proxyAddress = proxy.address() // Configure your networking library with proxyAddress. -... -// Stops the proxy. -proxy.stop(); +// ... +// Stop running the proxy. +proxy.stop() ``` ## Configure your HTTP client or networking library From 23a972789b6a912efca5adb85d8045f300ca7314 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Thu, 12 Oct 2023 15:28:44 -0400 Subject: [PATCH 4/6] Update JVM example to use Kotlin --- x/mobileproxy/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index a7efdf95..6ad54aa0 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -233,12 +233,12 @@ val client = OkHttpClient.Builder().proxy(proxy).build() https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/-builder/proxy/ -### Java +### JVM (Java, Kotlin) In the JVM, you can configure the proxy to use with [system properties](https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html): -```java -System.setProperty("http.proxyHost", "localhost"); -System.setProperty("http.proxyPort", "1234"); +```kotlin +System.setProperty("http.proxyHost", "localhost") +System.setProperty("http.proxyPort", "1234") ``` Note that this may not fully work on Android, since it will only affect the JVM, not native code. You should also make sure you set this early in your code. From 1f7ec473e320793de35236e5f81aa91aa76375ab Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 13 Oct 2023 12:20:03 -0600 Subject: [PATCH 5/6] Add Web View --- x/mobileproxy/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index 6ad54aa0..8de39036 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -239,10 +239,19 @@ In the JVM, you can configure the proxy to use with [system properties](https:// ```kotlin System.setProperty("http.proxyHost", "localhost") System.setProperty("http.proxyPort", "1234") +System.setProperty("https.proxyHost", "localhost") +System.setProperty("https.proxyPort", "1234") ``` Note that this may not fully work on Android, since it will only affect the JVM, not native code. You should also make sure you set this early in your code. +### Web View + +We are working on instructions on how use the local proxy in a Webview. + +On Android, you will likely have to implement [WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)) to fulfill requests using an HTTP client that uses the local proxy. + +On iOS, we are still looking for ideas. There's [WKWebViewConfiguration.setURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler), but the documentation says it can't be used to intercept HTTPS. If you know how do use a proxy with WKWebView, please let us know! ## Clean up From 3659c2074270a7853bf6135c4b14a2fcc57709dd Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 13 Oct 2023 12:20:49 -0600 Subject: [PATCH 6/6] Update README.md --- x/mobileproxy/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index 8de39036..f76abef8 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -251,7 +251,7 @@ We are working on instructions on how use the local proxy in a Webview. On Android, you will likely have to implement [WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)) to fulfill requests using an HTTP client that uses the local proxy. -On iOS, we are still looking for ideas. There's [WKWebViewConfiguration.setURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler), but the documentation says it can't be used to intercept HTTPS. If you know how do use a proxy with WKWebView, please let us know! +On iOS, we are still looking for ideas. There's [WKWebViewConfiguration.setURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler), but the documentation says it can't be used to intercept HTTPS. If you know how to use a proxy with the WKWebView, please let us know! ## Clean up