diff options
author | Christopher Baines <mail@cbaines.net> | 2023-04-25 16:53:12 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-04-25 16:53:12 +0100 |
commit | 6151b2e0e2c907eb847c5e1d5dc929f89008fdd1 (patch) | |
tree | 56780f52b1acb60eb5817b2dc62e206a66f08a6a /guix-build-coordinator/agent-messaging | |
parent | a36ec507038370c615e9fe9489c2bc920e3a878f (diff) | |
download | build-coordinator-6151b2e0e2c907eb847c5e1d5dc929f89008fdd1.tar build-coordinator-6151b2e0e2c907eb847c5e1d5dc929f89008fdd1.tar.gz |
Revert "Remove read-request-body workaround"
I was mistaken, Guile doesn't handle chunked request bodies.
This reverts commit 07e42953f257b846d44376d998cc7d654214ca17.
Diffstat (limited to 'guix-build-coordinator/agent-messaging')
-rw-r--r-- | guix-build-coordinator/agent-messaging/http/server.scm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm index 736c1db..4c88428 100644 --- a/guix-build-coordinator/agent-messaging/http/server.scm +++ b/guix-build-coordinator/agent-messaging/http/server.scm @@ -49,6 +49,31 @@ #:use-module (guix-build-coordinator coordinator) #:export (http-agent-messaging-start-server)) +(define (bad-request message . args) + (throw 'bad-request message args)) + +(define (fixed/read-request-body r) + "Reads the request body from R, as a bytevector. Return â#fâ +if there was no request body." + (cond + ;; TODO Change Guile to handle chunked request bodies + ((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 build-coordinator chunked-request-channel) |