diff --git a/src-tauri/gen/schemas/capabilities.json b/src-tauri/gen/schemas/capabilities.json index ef7f5b40..87d4844d 100644 --- a/src-tauri/gen/schemas/capabilities.json +++ b/src-tauri/gen/schemas/capabilities.json @@ -1 +1 @@ -{"main":{"identifier":"main","description":"Main permissions","local":true,"windows":["*"],"permissions":["os:allow-os-type","event:allow-emit","menu:allow-create-default","clipboard-manager:allow-write-text","dialog:allow-open","dialog:allow-save","event:allow-listen","event:allow-unlisten","fs:allow-read-file","fs:allow-read-text-file",{"identifier":"fs:scope","allow":[{"path":"$APPDATA"},{"path":"$APPDATA/**"}]},"shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":true,"name":"protoc","sidecar":true}]},"window:allow-close","window:allow-is-fullscreen","window:allow-maximize","window:allow-minimize","window:allow-set-decorations","window:allow-set-title","window:allow-start-dragging","window:allow-unmaximize","clipboard-manager:default"]}} \ No newline at end of file +{"main":{"identifier":"main","description":"Main permissions","local":true,"windows":["*"],"permissions":["os:allow-os-type","event:allow-emit","clipboard-manager:allow-write-text","dialog:allow-open","dialog:allow-save","event:allow-listen","event:allow-unlisten","fs:allow-read-file","fs:allow-read-text-file",{"identifier":"fs:scope","allow":[{"path":"$APPDATA"},{"path":"$APPDATA/**"}]},"shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":true,"name":"protoc","sidecar":true}]},"window:allow-close","window:allow-is-fullscreen","window:allow-maximize","window:allow-minimize","window:allow-set-decorations","window:allow-set-title","window:allow-start-dragging","window:allow-unmaximize","clipboard-manager:default"]}} \ No newline at end of file diff --git a/src-tauri/src/http.rs b/src-tauri/src/http.rs index 4d4365f3..88976218 100644 --- a/src-tauri/src/http.rs +++ b/src-tauri/src/http.rs @@ -7,11 +7,11 @@ use std::sync::Arc; use std::time::Duration; use base64::Engine; -use http::header::{ACCEPT, USER_AGENT}; use http::{HeaderMap, HeaderName, HeaderValue, Method}; +use http::header::{ACCEPT, USER_AGENT}; use log::{error, info, warn}; -use reqwest::redirect::Policy; use reqwest::{multipart, Url}; +use reqwest::redirect::Policy; use sqlx::types::{Json, JsonValue}; use tauri::{Manager, WebviewWindow}; use tokio::sync::oneshot; @@ -35,6 +35,7 @@ pub async fn send_http_request( let mut url_string = render::render(&request.url, &workspace, environment.as_ref()); + url_string = ensure_proto(&url_string); if !url_string.starts_with("http://") && !url_string.starts_with("https://") { url_string = format!("http://{}", url_string); } @@ -465,3 +466,26 @@ pub async fn send_http_request( Err(e) => response_err(response, e.to_string(), window).await, } } + +fn ensure_proto(url_str: &str) -> String { + if url_str.starts_with("http://") || url_str.starts_with("https://") { + return url_str.to_string(); + } + + // Url::from_str will fail without a proto, so add one + let parseable_url = format!("http://{}", url_str); + if let Ok(u) = Url::from_str(parseable_url.as_str()) { + match u.host() { + Some(host) => { + let h = host.to_string(); + // These TLDs force HTTPS + if h.ends_with(".app") || h.ends_with(".dev") || h.ends_with(".page") { + return format!("https://{url_str}"); + } + } + None => {} + } + } + + format!("http://{url_str}") +}