From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Baines Newsgroups: gmane.lisp.guile.devel Subject: [PATCH 1/2] web: Handle ending CRLF (\r\n) for chunked input and output ports. Date: Thu, 30 Jun 2022 19:15:53 +0100 Message-ID: <20220630181554.25772-1-mail@cbaines.net> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13660"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Jun 30 20:16:35 2022 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6yiR-0003KC-Hm for guile-devel@m.gmane-mx.org; Thu, 30 Jun 2022 20:16:35 +0200 Original-Received: from localhost ([::1]:36578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6yiP-0003hL-QV for guile-devel@m.gmane-mx.org; Thu, 30 Jun 2022 14:16:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6yhr-0003hA-Uq for guile-devel@gnu.org; Thu, 30 Jun 2022 14:15:59 -0400 Original-Received: from mira.cbaines.net ([212.71.252.8]:36528) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6yhp-0002L8-4L for guile-devel@gnu.org; Thu, 30 Jun 2022 14:15:59 -0400 Original-Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:54d1:d5d4:280e:f699]) by mira.cbaines.net (Postfix) with ESMTPSA id 91EA627BBE9 for ; Thu, 30 Jun 2022 19:15:54 +0100 (BST) Original-Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id cff7a98c for ; Thu, 30 Jun 2022 18:15:54 +0000 (UTC) X-Mailer: git-send-email 2.36.1 Received-SPF: pass client-ip=212.71.252.8; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21247 Archived-At: 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. --- 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 4276e1744..163c52176 100644 --- a/module/web/http.scm +++ b/module/web/http.scm @@ -1977,6 +1977,7 @@ closed it will also close PORT, unless the KEEP-ALIVE? is true." (cond ((zero? size) (set! finished? #t) + (get-bytevector-n port 2) ; \r\n follows the last chunk num-read) (else (loop to-read num-read))))) @@ -2031,7 +2032,7 @@ KEEP-ALIVE? is true." (put-string port "\r\n")))) (define (close) (flush) - (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 63377349c..86fbc0e1a 100644 --- a/test-suite/tests/web-http.test +++ b/test-suite/tests/web-http.test @@ -421,7 +421,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" @@ -497,4 +497,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")) -- 2.36.1