Use headers to get the correct scheme and host.

This commit is contained in:
Feufochmar 2021-05-24 20:22:46 +02:00
parent bcb29fc7c4
commit 12a539cd91
1 changed files with 13 additions and 4 deletions

View File

@ -3,7 +3,8 @@
(require
web-server/http
web-server/http/cookie-parse
net/url-structs)
net/url-structs
racket/string)
(provide
make-weblet-parameter
@ -84,9 +85,17 @@
; Get the protocol used for the request, as a symbol
(define (weblet-parameter-protocol wp)
(define scheme (url-scheme (request-uri (weblet-parameter-request wp))))
(and scheme (string->symbol scheme)))
; Check the header: X-Scheme
; As the application is expected to be behind a proxy, the proxy must set the X-Scheme header to indicate which protocol was used.
(define scheme (headers-assq #"X-Scheme" (request-headers/raw (weblet-parameter-request wp))))
(and scheme (string->symbol (bytes->string/utf-8 (header-value scheme)))))
; Get the host used for the request
(define (weblet-parameter-host wp)
(url-host (request-uri (weblet-parameter-request wp))))
; Header: Host (as string)
; As the application is expected to be behind a proxy, the proxy must set the Host header to indicate which address was asked
(define host-header (headers-assq #"Host" (request-headers/raw (weblet-parameter-request wp))))
(define host (or (and host-header (bytes->string/utf-8 (header-value host-header)))
"localhost"))
; Remove the port part
(car (string-split host ":")))