Skip to content

Commit

Permalink
feat: Explicitly handle * in allowed_origins as "allow all" (#17)
Browse files Browse the repository at this point in the history
* feat: Explicitly handle `*` in allowed_origins as "allow all"

* fix
  • Loading branch information
FabianLars authored Nov 16, 2023
1 parent fbd45f4 commit ab1fb56
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use tauri::{
use tiny_http::{Header, Method, Request, Response};

fn cors<R: std::io::Read>(request: &Request, r: &mut Response<R>, allowed_origins: &[String]) {
if let Some(origin) = request.headers().iter().find(|h| h.field.equiv("Origin")) {
if allowed_origins.iter().any(|s| s == "*") {
r.add_header(Header::from_str("Access-Control-Allow-Origin: *").unwrap());
} else if let Some(origin) = request.headers().iter().find(|h| h.field.equiv("Origin")) {
if allowed_origins.iter().any(|o| o == &origin.value) {
r.add_header(
Header::from_str(&format!("Access-Control-Allow-Origin: {}", origin.value)).unwrap(),
Expand Down Expand Up @@ -119,7 +121,7 @@ impl Invoke {
let success = this.status === 200
try {{
arg = JSON.parse(this.response)
}} catch (e) {{
}} catch (e) {{
arg = e
success = false
}}
Expand Down

0 comments on commit ab1fb56

Please sign in to comment.