aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-02-09 11:43:42 +0000
committerChristopher Baines <mail@cbaines.net>2023-02-09 11:49:41 +0000
commit6be113f99d52cc284ecd0ed07fc88df5ea7bf718 (patch)
treee16e64e3e45c843184d936f1894f7ad62a20bd28
parent0ce5af2c59aed43a986aea359afa0c41d5cfca18 (diff)
downloaddata-service-6be113f99d52cc284ecd0ed07fc88df5ea7bf718.tar
data-service-6be113f99d52cc284ecd0ed07fc88df5ea7bf718.tar.gz
Adjust render procedures to not use procedures for responses
The newer Guile Fibers web server will use the chunked transfer encoding when a procedure is used and the content length is unspecified. This is good for large responses, but unnecessary here. Also, there's a bug with the charset so these changes to respond with correctly encoded bytevectors to avoid that.
-rw-r--r--guix-data-service/web/render.scm28
1 files changed, 19 insertions, 9 deletions
diff --git a/guix-data-service/web/render.scm b/guix-data-service/web/render.scm
index 081399a..744c66c 100644
--- a/guix-data-service/web/render.scm
+++ b/guix-data-service/web/render.scm
@@ -24,6 +24,7 @@
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-26)
#:use-module (ice-9 ftw)
+ #:use-module (ice-9 iconv)
#:use-module (ice-9 binary-ports)
#:use-module (web request)
#:use-module (web response)
@@ -142,30 +143,39 @@
(list (build-response
#:code code
#:headers (append extra-headers
- '((content-type . (text/html))
+ '((content-type . (text/html
+ (charset . "utf-8")))
(vary . (accept)))))
- (lambda (port)
- (sxml->html sxml port))))
+ (call-with-encoded-output-string
+ "utf-8"
+ (lambda (port)
+ (sxml->html sxml port)))))
(define* (render-json json #:key (extra-headers '())
(code 200))
(list (build-response
#:code code
#:headers (append extra-headers
- '((content-type . (application/json))
+ '((content-type . (application/json
+ (charset . "utf-8")))
(vary . (accept)))))
- (lambda (port)
- (scm->json json port))))
+ (call-with-encoded-output-string
+ "utf-8"
+ (lambda (port)
+ (scm->json json port)))))
(define* (render-text text #:key (extra-headers '())
(code 200))
(list (build-response
#:code code
#:headers (append extra-headers
- '((content-type . (text/plain))
+ '((content-type . (text/plain
+ (charset . "utf-8")))
(vary . (accept)))))
- (lambda (port)
- (display text port))))
+ (call-with-encoded-output-string
+ "utf-8"
+ (lambda (port)
+ (display text port)))))
(define (not-found uri)
(list (build-response #:code 404)