Support file uploads in weblet parameter.

This commit is contained in:
Feufochmar 2021-05-11 18:20:24 +02:00
parent 5207337602
commit 5b3c80d2bc
1 changed files with 12 additions and 1 deletions

View File

@ -9,6 +9,7 @@
make-weblet-parameter
weblet-parameter-ref
weblet-parameter-cookie-ref
weblet-parameter-file-port-ref
weblet-parameter-method
weblet-parameter-protocol
weblet-parameter-host
@ -43,7 +44,9 @@
(req (bindings-assq (string->bytes/utf-8 (symbol->string key)) query))
(mat (hash-ref (weblet-parameter-match wp) key default)))
; Priority: from request, from match
(or (and req (bytes->string/utf-8 (binding:form-value req)))
(or (and req (bytes->string/utf-8
(or (and (binding:file/port? req) (binding:file-filename req))
(binding:form-value req))))
mat)))
; Get a cookie from the request. Return the cookie value as a string or #f if the asked value was not passed.
@ -55,6 +58,14 @@
(request-cookies (weblet-parameter-request wp))))
(and cookie (client-cookie-value cookie)))
; Get the file port from the request. Return the port or #f if the asked file was not passed.
; Key is a symbol
(define (weblet-parameter-file-port-ref wp key)
(define query (request-bindings/raw (weblet-parameter-request wp)))
(define req (bindings-assq (string->bytes/utf-8 (symbol->string key)) query))
(and req (binding:file/port? req)
(binding:file/port-in req)))
; Get the method used for the request.
; Method is returned as a symbol
(define (weblet-parameter-method wp)