File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 2
2
* .ez
3
3
/build
4
4
erl_crash.dump
5
+ .DS_Store
6
+ Thumbs.db
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ import gleam/pair
62
62
import gleam/result
63
63
import gleam/set . { type Set }
64
64
import gleam/string
65
+ import gleam/uri
65
66
import mist
66
67
import wisp
67
68
@@ -110,6 +111,15 @@ pub fn allow_all_origins(cors: Cors) {
110
111
Cors ( .. cors , allow_origin : allow_origin )
111
112
}
112
113
114
+ fn invalid_uri ( origin : String ) {
115
+ uri . parse ( origin )
116
+ |> result . is_ok ( )
117
+ |> function . tap ( fn ( value ) {
118
+ use <- bool . guard ( when : value , return : Nil )
119
+ io . println ( "Your provided origin: \" " <> origin <> "\" is not a valid URI." )
120
+ } )
121
+ }
122
+
113
123
/// Allow a specific domain to access your server.
114
124
/// You can specify multiple domains to access your server. In this case, call
115
125
/// the function multiple times on `Cors` data.
@@ -120,6 +130,7 @@ pub fn allow_all_origins(cors: Cors) {
120
130
/// |> cors.allow_origin("domain2")
121
131
/// }
122
132
pub fn allow_origin ( cors : Cors , origin : String ) {
133
+ use <- bool . guard ( when : invalid_uri ( origin ) , return : cors )
123
134
let allow_origin = case cors . allow_origin {
124
135
Some ( Wildcard ) -> Some ( Wildcard )
125
136
Some ( Origin ( content ) ) -> Some ( Origin ( set . insert ( content , origin ) ) )
You can’t perform that action at this time.
0 commit comments