Skip to content

Commit

Permalink
fix(custom-protocol): Make sure custom protocol on Windows is over HT…
Browse files Browse the repository at this point in the history
…TPS. (#179)

I thought we’ll get a SSL error but after my tests I figured out we should use https instead of http.
  • Loading branch information
lemarier authored Apr 21, 2021
1 parent dd0fa46 commit c36db35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-ssl-custom-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": minor
---

Make sure custom protocol on Windows is over HTTPS.
6 changes: 3 additions & 3 deletions src/webview/win32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ impl InnerWebView {
// See https://github.com/MicrosoftEdge/WebView2Feedback/issues/73
custom_protocol_names.insert(name.clone());
w.add_web_resource_requested_filter(
&format!("http://custom-protocol-{}*", name),
&format!("https://custom-protocol-{}*", name),
webview2::WebResourceContext::All,
)?;
let env_clone = env_.clone();
w.add_web_resource_requested(move |_, args| {
let uri = args.get_request()?.get_uri()?;
// Undo the protocol workaround when giving path to resolver
let path = &uri.replace(
&format!("http://custom-protocol-{}", name),
&format!("https://custom-protocol-{}", name),
&format!("{}://", name),
);

Expand Down Expand Up @@ -175,7 +175,7 @@ impl InnerWebView {
// See https://github.com/MicrosoftEdge/WebView2Feedback/issues/73
url_string = url.as_str().replace(
&format!("{}://", name),
&format!("http://custom-protocol-{}", name),
&format!("https://custom-protocol-{}", name),
)
}
w.navigate(&url_string)?;
Expand Down
6 changes: 3 additions & 3 deletions src/webview/winrt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl InnerWebView {
// See https://github.com/MicrosoftEdge/WebView2Feedback/issues/73
custom_protocol_names.insert(name.clone());
w.AddWebResourceRequestedFilter(
format!("http://custom-protocol-{}*", name).as_str(),
format!("https://custom-protocol-{}*", name).as_str(),
webview2::CoreWebView2WebResourceContext::All,
)?;
let env_ = env.clone();
Expand All @@ -154,7 +154,7 @@ impl InnerWebView {
if let Ok(uri) = String::from_utf16(args.Request()?.Uri()?.as_wide()) {
// Undo the protocol workaround when giving path to resolver
let path = uri.replace(
&format!("http://custom-protocol-{}", name),
&format!("https://custom-protocol-{}", name),
&format!("{}://", name),
);

Expand Down Expand Up @@ -208,7 +208,7 @@ impl InnerWebView {
// See https://github.com/MicrosoftEdge/WebView2Feedback/issues/73
url_string = url.as_str().replace(
&format!("{}://", name),
&format!("http://custom-protocol-{}", name),
&format!("https://custom-protocol-{}", name),
)
}
w.Navigate(url_string.as_str())?;
Expand Down

0 comments on commit c36db35

Please sign in to comment.