aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/agent-messaging
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-04-13 12:39:34 +0100
committerChristopher Baines <mail@cbaines.net>2020-04-13 12:39:34 +0100
commitc623bcf70471a767ed75b6ae9e8ca1e0406c54c6 (patch)
tree524cc4e435640b457133d80261ad924683673255 /guix-build-coordinator/agent-messaging
parent2d2ae5b6b01081f35ad2fc25affdef8c876b48e6 (diff)
downloadbuild-coordinator-c623bcf70471a767ed75b6ae9e8ca1e0406c54c6.tar
build-coordinator-c623bcf70471a767ed75b6ae9e8ca1e0406c54c6.tar.gz
Hack support for chuncked request bodies in to Guile
There's some support for using the chunked transfer encoding, but only for response bodies. Rather than returning a bytevector, return a port so that the data can be sent to a file, rather than having to store it all in memory first.
Diffstat (limited to 'guix-build-coordinator/agent-messaging')
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index b1b5c72..787c587 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -21,6 +21,7 @@
(define-module (guix-build-coordinator agent-messaging http)
#:use-module (srfi srfi-11)
#:use-module (ice-9 match)
+ #:use-module (ice-9 binary-ports)
#:use-module (system repl error-handling)
#:use-module (web server)
#:use-module (rnrs bytevectors)
@@ -38,6 +39,27 @@
submit-status
fetch-builds-for-agent))
+(define (fixed/read-request-body r)
+ "Reads the request body from R, as a bytevector. Return ‘#f’
+if there was no request body."
+ (cond
+ ((member '(chunked) (request-transfer-encoding r))
+ (make-chunked-input-port (request-port r)
+ ;; closing the port is handled elsewhere
+ #:keep-alive? #t))
+ (else
+ (let ((nbytes (request-content-length r)))
+ (and nbytes
+ (let ((bv (get-bytevector-n (request-port r) nbytes)))
+ (if (= (bytevector-length bv) nbytes)
+ bv
+ (bad-request "EOF while reading request body: ~a bytes of ~a"
+ (bytevector-length bv) nbytes))))))))
+
+(module-set! (resolve-module '(web request))
+ 'read-request-body
+ fixed/read-request-body)
+
(define (http-agent-messaging-start-server port host secret-key-base
datastore)
(call-with-error-handling