>From ceac1650327396199dc5114a898233584e4d5d3a Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Tue, 26 Aug 2014 13:18:51 +0800 Subject: [PATCH] The built-in http server supports thunk as body to take advantage of sendfile --- module/web/server.scm | 6 ++++++ module/web/server/http.scm | 1 + 2 files changed, 7 insertions(+) diff --git a/module/web/server.scm b/module/web/server.scm index 471bb98..b358fec 100644 --- a/module/web/server.scm +++ b/module/web/server.scm @@ -216,6 +216,12 @@ on the procedure being called at any particular time." (extend-response response 'content-type `(,@type (charset . ,charset)))) (string->bytevector body charset)))) + ((thunk? body) + (values + response + (if (eq? (request-method request) 'HEAD) + #f + body))) ((procedure? body) (let* ((type (response-content-type response '(text/plain))) diff --git a/module/web/server/http.scm b/module/web/server/http.scm index cda44f4..3767c61 100644 --- a/module/web/server/http.scm +++ b/module/web/server/http.scm @@ -154,6 +154,7 @@ (port (response-port response))) (cond ((not body)) ; pass + ((thunk? body) (body)) ((bytevector? body) (write-response-body response body)) (else -- 1.7.10.4