From 9a3353a993e8b73312a0005278f12c67cffa9854 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 30 Jun 2022 19:15:53 +0100 Subject: web: Handle ending CRLF (\r\n) for chunked input and output ports. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://datatracker.ietf.org/doc/html/rfc2616#section-3.6.1 * 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 port. * test-suite/tests/web-http.test (chunked encoding): Add missing \r\n to test data. Signed-off-by: Ludovic Courtès --- test-suite/tests/web-http.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test-suite') 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)))) (pass-if-equal "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 chunk\r\n0\r\n\r\n")) -- cgit v1.2.1