Repository navigation
feat: support webview proxy #1006
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
Merged
+244
−26
Merged
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e1dc565
feat(macos): support proxy
pewsheen 6ef2cdd
Merge branch 'tauri-apps:dev' into proxy
pewsheen 914c237
Added WebView2 implementation
dklassic cf41c84
Update mod.rs
dklassic 560ec59
Added Webkit2gtk implementation
dklassic 4c15e5e
chore: update doc and format
pewsheen 41ca7ef
fix(macos): use TryFrom trait for nw_endpoint_t
pewsheen 6aa2b4a
fix(macos): add `mac-proxy` feature flag to enable proxy feature for …
pewsheen 7693686
chore: fix clippy
pewsheen 6d7e0b2
Change WebView2 argument construction to before async operation
dklassic 9f8c6ff
Update src/webview/mod.rs
dklassic d2dbd64
Remove unused import
dklassic 711695b
update formatting
dklassic efd9061
Added documentation at with_additional_browser_args
dklassic 09bac28
refactor: remove redundant proxy struct
pewsheen 3aa57a2
Remove redundant reference
dklassic 7965111
hide proxy module and export types needed
dklassic 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2020-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| use wry::webview::proxy::{ProxyConfig, ProxyConnection, ProxyEndpoint, ProxyType}; | ||
|
|
||
| fn main() -> wry::Result<()> { | ||
| use wry::{ | ||
| application::{ | ||
| event::{Event, StartCause, WindowEvent}, | ||
| event_loop::{ControlFlow, EventLoop}, | ||
| window::WindowBuilder, | ||
| }, | ||
| webview::WebViewBuilder, | ||
| }; | ||
|
|
||
| let event_loop = EventLoop::new(); | ||
| let window = WindowBuilder::new() | ||
| .with_title("Proxy Test") | ||
| .build(&event_loop)?; | ||
|
|
||
| let http_proxy = ProxyConnection::Http(ProxyEndpoint { | ||
| host: "localhost".to_string(), | ||
| port: "3128".to_string(), | ||
| }); | ||
|
|
||
| let _webview = WebViewBuilder::new(window)? | ||
| .with_proxy_config(ProxyConfig { | ||
| proxy_type: ProxyType::Http, | ||
| proxy_connection: http_proxy, | ||
| }) | ||
| .with_url("https://www.myip.com/")? | ||
| .build()?; | ||
|
|
||
| event_loop.run(move |event, _, control_flow| { | ||
| *control_flow = ControlFlow::Wait; | ||
|
|
||
| match event { | ||
| Event::NewEvents(StartCause::Init) => println!("Wry has started!"), | ||
| Event::WindowEvent { | ||
| event: WindowEvent::CloseRequested, | ||
| .. | ||
| } => *control_flow = ControlFlow::Exit, | ||
| _ => (), | ||
| } | ||
| }); | ||
| } |
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,26 @@ | ||
| #[derive(Debug, Clone)] | ||
| pub enum ProxyType { | ||
| /// HTTP CONNECT | ||
| Http, | ||
| /// SOCKSv5 | ||
| Socks5, | ||
| } | ||
| #[derive(Debug, Clone)] | ||
| pub struct ProxyEndpoint { | ||
| /// Proxy server host (e.g. 192.168.0.100, localhost, example.com, etc.) | ||
| pub host: String, | ||
| /// Proxy server port (e.g. 1080, 3128, etc.) | ||
| pub port: String, | ||
| } | ||
| #[derive(Debug, Clone)] | ||
| pub enum ProxyConnection { | ||
| /// Connect to proxy server via HTTP CONNECT | ||
| Http(ProxyEndpoint), | ||
| /// Connect to proxy server via SOCKSv5 | ||
| Socks5(ProxyEndpoint), | ||
| } | ||
| #[derive(Debug, Clone)] | ||
| pub struct ProxyConfig { | ||
| pub proxy_type: ProxyType, | ||
| pub proxy_connection: ProxyConnection, | ||
| } | ||
|
dklassic marked this conversation as resolved.
Outdated
|
||
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
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,67 @@ | ||
| // Copyright 2020-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| use cocoa::base::nil; | ||
| use libc::c_char; | ||
|
|
||
| use crate::{webview::proxy::ProxyEndpoint, Error}; | ||
|
|
||
| use super::NSString; | ||
|
|
||
| #[allow(non_camel_case_types)] | ||
| pub type nw_endpoint_t = *mut objc::runtime::Object; | ||
| #[allow(non_camel_case_types)] | ||
| pub type nw_relay_hop_t = *mut objc::runtime::Object; | ||
| #[allow(non_camel_case_types)] | ||
| pub type nw_protocol_options_t = *mut objc::runtime::Object; | ||
| #[allow(non_camel_case_types)] | ||
| pub type nw_proxy_config_t = *mut objc::runtime::Object; | ||
|
|
||
| #[link(name = "Network", kind = "framework")] | ||
| extern "C" { | ||
| #[allow(dead_code)] | ||
| fn nw_endpoint_create_url(url: *const c_char) -> nw_endpoint_t; | ||
| #[allow(dead_code)] | ||
| fn nw_endpoint_get_url(endpoint: nw_endpoint_t) -> *const c_char; | ||
| fn nw_endpoint_create_host(host: *const c_char, port: *const c_char) -> nw_endpoint_t; | ||
| #[allow(dead_code)] | ||
| fn nw_proxy_config_set_username_and_password( | ||
| proxy_config: nw_proxy_config_t, | ||
| username: *const c_char, | ||
| password: *const c_char, | ||
| ); | ||
| #[allow(dead_code)] | ||
| fn nw_relay_hop_create( | ||
| http3_relay_endpoint: nw_endpoint_t, | ||
| http2_relay_endpoint: nw_endpoint_t, | ||
| relay_tls_options: nw_protocol_options_t, | ||
| ) -> nw_relay_hop_t; | ||
| #[allow(dead_code)] | ||
| fn nw_proxy_config_create_relay( | ||
| first_hop: nw_relay_hop_t, | ||
| second_hop: nw_relay_hop_t, | ||
| ) -> nw_proxy_config_t; | ||
| pub fn nw_proxy_config_create_socksv5(proxy_endpoint: nw_endpoint_t) -> nw_proxy_config_t; | ||
| pub fn nw_proxy_config_create_http_connect( | ||
| proxy_endpoint: nw_endpoint_t, | ||
| proxy_tls_options: nw_protocol_options_t, | ||
| ) -> nw_proxy_config_t; | ||
| } | ||
|
pewsheen marked this conversation as resolved.
|
||
|
|
||
| impl TryFrom<ProxyEndpoint> for nw_endpoint_t { | ||
| type Error = Error; | ||
| fn try_from(endpoint: ProxyEndpoint) -> Result<Self, Error> { | ||
| unsafe { | ||
| let endpoint_host = NSString::new(&endpoint.host).to_cstr(); | ||
| let endpoint_port = NSString::new(&endpoint.port).to_cstr(); | ||
| let endpoint = nw_endpoint_create_host(endpoint_host, endpoint_port); | ||
|
|
||
| match endpoint { | ||
| #[allow(non_upper_case_globals)] | ||
| nil => Err(Error::ProxyEndpointCreationFailed), | ||
| _ => Ok(endpoint), | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.