diff options
author | Christopher Baines <mail@cbaines.net> | 2023-02-09 10:39:24 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-02-09 10:39:24 +0000 |
commit | 0ce5af2c59aed43a986aea359afa0c41d5cfca18 (patch) | |
tree | e7c17688b5083a6e3c5d5b1b8dda86653bcc97f2 | |
parent | 3ba841865663429392f869aedcd8f1fb63f278db (diff) | |
download | data-service-0ce5af2c59aed43a986aea359afa0c41d5cfca18.tar data-service-0ce5af2c59aed43a986aea359afa0c41d5cfca18.tar.gz |
Tweak behaviour when the response body is a procedure
Newer versions of Guile Fibers will now use chunked encoding when a procedure
is used (and no content length is set). This is good, but not always what is
wanted, and there's also an issue with the port encoding.
This commit switches to responding with a string/bytevector when more
appropriate, plus explicitly setting the port encoding where that's needed.
-rw-r--r-- | guix-data-service/web/controller.scm | 5 | ||||
-rw-r--r-- | guix-data-service/web/nar/controller.scm | 52 |
2 files changed, 29 insertions, 28 deletions
diff --git a/guix-data-service/web/controller.scm b/guix-data-service/web/controller.scm index ceef532..34a7893 100644 --- a/guix-data-service/web/controller.scm +++ b/guix-data-service/web/controller.scm @@ -278,8 +278,9 @@ (list (build-response #:code 200 #:headers '((content-type . (text/plain)))) - (lambda (port) - (write-metrics registry port))))))) + (call-with-output-string + (lambda (port) + (write-metrics registry port)))))))) (define (render-derivation derivation-file-name) (letpar& ((derivation diff --git a/guix-data-service/web/nar/controller.scm b/guix-data-service/web/nar/controller.scm index ba8b890..2164860 100644 --- a/guix-data-service/web/nar/controller.scm +++ b/guix-data-service/web/nar/controller.scm @@ -112,17 +112,18 @@ #:code 200 #:headers '((content-type . (application/x-nix-archive (charset . "ISO-8859-1"))))) - (lambda (port) - (write-file-tree - file-name - port - #:file-type+size - (lambda (file) - (values 'regular - (bytevector-length derivation-bytevector))) - #:file-port - (lambda (file) - (open-bytevector-input-port derivation-bytevector)))))))) + (call-with-output-bytevector + (lambda (port) + (write-file-tree + file-name + port + #:file-type+size + (lambda (file) + (values 'regular + (bytevector-length derivation-bytevector))) + #:file-port + (lambda (file) + (open-bytevector-input-port derivation-bytevector))))))))) (not-found (request-uri request)))) (define (render-lzip-nar request @@ -137,9 +138,12 @@ (lambda (data) (list (build-response #:code 200 - #:headers '((content-type . (application/x-nix-archive - (charset . "ISO-8859-1"))))) + #:headers `((content-type . (application/x-nix-archive + (charset . "ISO-8859-1"))) + (content-length . ,(bytevector-length data)))) (lambda (port) + ;; TODO: This should probably be handled by guile-fibers + (set-port-encoding! port "ISO-8859-1") (put-bytevector port data))))) (not-found (request-uri request)))) @@ -188,11 +192,9 @@ (lambda (file) (open-bytevector-input-port derivation-bytevector))) (get-bytevector))))) - (lambda (port) - (display (narinfo-string derivation-file-name - nar-bytevector - derivation-references) - port)))))))) + (narinfo-string derivation-file-name + nar-bytevector + derivation-references))))))) (and=> (parallel-via-thread-pool-channel (with-thread-postgresql-connection (lambda (conn) @@ -204,14 +206,12 @@ (list (build-response #:code 200 #:headers '((content-type . (application/x-narinfo)))) - (lambda (port) - (display (derivation-source-file-narinfo-string store-path - compression - compressed-size - hash-algorithm - hash - uncompressed-size) - port)))))) + (derivation-source-file-narinfo-string store-path + compression + compressed-size + hash-algorithm + hash + uncompressed-size))))) (not-found (request-uri request)))) |