Skip to content

Commit

Permalink
Function to add cors headers
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Mar 26, 2024
1 parent aa35716 commit 8dd8e16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <[email protected]> and the amazing Genie contributors ♥️"]
version = "5.28.0"
version = "5.29.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
23 changes: 23 additions & 0 deletions src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ function config!(; kwargs...)
end


"""
add_cors_header!(key, value)
Adds a new CORS header to the `Genie.config.cors_headers` collection as key => value pair.
# Examples
```julia
Genie.Configuration.add_cors_header!("Access-Control-Allow-Headers", "Genie-Session-Id")
```
"""
function add_cors_header!(key, value; config = Genie.config)
key = string(key)
value = string(value)

if ! haskey(config.cors_headers, key)
@warn "CORS header key $key does not exist. Creating."
config.cors_headers[key] = value
end

config.cors_headers[key] = join(push!([String(strip(h)) for h in split(config.cors_headers[key], ',')], value) |> unique!, ", ")
end


"""
mutable struct Settings
Expand Down

0 comments on commit 8dd8e16

Please sign in to comment.