[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 02/06: web: Handle ending CRLF (\r\n) for chunked input

From: Ludovic Courtès
Subject: [Guile-commits] 02/06: web: Handle ending CRLF (\r\n) for chunked input and output ports.
Date: Mon, 4 Jul 2022 05:52:40 -0400 (EDT)

civodul pushed a commit to branch main
in repository guile.

commit 9a3353a993e8b73312a0005278f12c67cffa9854
Author: Christopher Baines <>
AuthorDate: Thu Jun 30 19:15:53 2022 +0100

    web: Handle ending CRLF (\r\n) for chunked input and output ports.
    The chunked transfer encoding specifies the chunked body ends with
    CRLF. This is in addition to the CRLF at the end of the last chunk, so
    there should be CRLF twice at the end of the chunked body:
    * module/web/http.scm (make-chunked-input-port): Read two extra bytes at
    the end of the chunked input.
    (make-chunked-output-port): Write the missing \r\n when closing the
    * test-suite/tests/web-http.test (chunked encoding): Add missing \r\n to
    test data.
    Signed-off-by: Ludovic Courtès <>
 module/web/http.scm            | 3 ++-
 test-suite/tests/web-http.test | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/module/web/http.scm b/module/web/http.scm
index 6af790384..827adad3e 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1987,6 +1987,7 @@ closed it will also close PORT, unless the KEEP-ALIVE? is 
                 ((zero? size)
                  (set! finished? #t)
+                 (get-bytevector-n port 2) ; \r\n follows the last chunk
                  (loop to-read num-read)))))
@@ -2041,7 +2042,7 @@ KEEP-ALIVE? is true."
         (put-string port "\r\n"))))
   (define (close)
-    (put-string port "0\r\n")
+    (put-string port "0\r\n\r\n")
     (force-output port)
     (unless keep-alive?
       (close-port port)))
diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test
index 5c6a954b9..3c2acf11c 100644
--- a/test-suite/tests/web-http.test
+++ b/test-suite/tests/web-http.test
@@ -426,7 +426,7 @@
                  '((basic (realm . "guile")))))
 (with-test-prefix "chunked encoding"
-  (let* ((s "5\r\nFirst\r\nA\r\n line\n Sec\r\n8\r\nond line\r\n0\r\n")
+  (let* ((s "5\r\nFirst\r\nA\r\n line\n Sec\r\n8\r\nond line\r\n0\r\n\r\n")
          (p (make-chunked-input-port (open-input-string s))))
         "First line\n Second line"
@@ -502,4 +502,4 @@
            (force-output out-chunked)
            (display "Third chunk" out-chunked)
            (close-port out-chunked))))
-      "b\r\nFirst chunk\r\nc\r\nSecond chunk\r\nb\r\nThird chunk\r\n0\r\n"))
+      "b\r\nFirst chunk\r\nc\r\nSecond chunk\r\nb\r\nThird 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]