Skip to content

Commit

Permalink
cors: clean up make-allow-origin-header
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Jan 31, 2025
1 parent dc3b4ff commit 005d90c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions koyo-lib/koyo/cors.rkt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#lang racket/base

(require racket/contract/base
racket/function
racket/string
web-server/http
"contract.rkt"
Expand Down Expand Up @@ -35,15 +34,10 @@
(define (make-allow-origin-header)
(define origin
(string->bytes/utf-8
(cond
[(current-cors-origin)
=> identity]

[else
(format "~a://~a"
(current-application-url-scheme)
(current-application-url-host))])))

(or (current-cors-origin)
(format "~a://~a"
(current-application-url-scheme)
(current-application-url-host)))))
(make-header #"Access-Control-Allow-Origin" origin))

(define (make-options-headers)
Expand All @@ -70,8 +64,9 @@
(response/full 200 #"OK" (current-seconds) #f (make-options-headers) null)]

[else
(define resp (apply handler req args))
(define headers (cons (make-allow-origin-header)
(response-headers resp)))

(define resp
(apply handler req args))
(define headers
(cons (make-allow-origin-header)
(response-headers resp)))
(struct-copy response resp [headers headers])])))

0 comments on commit 005d90c

Please sign in to comment.