summaryrefslogtreecommitdiff
path: root/test-suite/tests/web-http.test
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-03-01 23:41:01 +0100
committerAndy Wingo <wingo@pobox.com>2016-05-22 18:43:28 +0200
commit751a55e3552547c84cc3cc0ad69fc6f26bd7251e (patch)
tree9c8447ea2649b47ea2e19c04a274fcf28495d268 /test-suite/tests/web-http.test
parentc6d88d12345a3722bf78b124c69f15d73da23dc0 (diff)
downloadguile-751a55e3552547c84cc3cc0ad69fc6f26bd7251e.tar.gz
http: Do not buffer HTTP chunks.
Fixes <http://bugs.gnu.org/19939>. * module/web/http.scm (read-chunk, read-chunk-body): Remove. (make-chunked-input-port)[next-chunk, buffer-, buffer-size, buffer-pointer]: Remove. [chunk-size, remaining]: New variables. [read!]: Rewrite to write directly to BV. * test-suite/tests/web-http.test ("chunked encoding")["reads chunks without buffering", "reads across chunk boundaries"]: New tests.
Diffstat (limited to 'test-suite/tests/web-http.test')
-rw-r--r--test-suite/tests/web-http.test54
1 files changed, 52 insertions, 2 deletions
diff --git a/test-suite/tests/web-http.test b/test-suite/tests/web-http.test
index 09b029064..8a7a29542 100644
--- a/test-suite/tests/web-http.test
+++ b/test-suite/tests/web-http.test
@@ -1,4 +1,4 @@
-;;;; web-uri.test --- URI library -*- mode: scheme; coding: utf-8; -*-
+;;;; web-http.test --- HTTP library -*- mode: scheme; coding: utf-8; -*-
;;;;
;;;; Copyright (C) 2010-2011, 2014-2016 Free Software Foundation, Inc.
;;;;
@@ -20,6 +20,7 @@
(define-module (test-suite web-http)
#:use-module (web uri)
#:use-module (web http)
+ #:use-module (rnrs bytevectors)
#:use-module (rnrs io ports)
#:use-module (ice-9 regex)
#:use-module (ice-9 control)
@@ -372,7 +373,56 @@
(pass-if-equal
"First line\n Second line"
(get-string-all p))
- (pass-if (port-eof? (make-chunked-input-port (open-input-string "0\r\n")))))
+ (pass-if (port-eof? (make-chunked-input-port (open-input-string "0\r\n"))))
+
+ (pass-if-equal "reads chunks without buffering"
+ ;; Make sure the chunked input port does not read more than what
+ ;; the client asked. See <http://bugs.gnu.org/19939>
+ `("First " "chunk." "Second " "chunk."
+ (1 1 1 6 6 1 1
+ 1 1 1 7 6 1 1))
+ (let* ((str "C\r\nFirst chunk.\r\nD\r\nSecond chunk.\r\n")
+ (requests '())
+ (read! (let ((port (open-input-string str)))
+ (lambda (bv index count)
+ (set! requests (cons count requests))
+ (let ((n (get-bytevector-n! port bv index
+ count)))
+ (if (eof-object? n) 0 n)))))
+ (input (make-custom-binary-input-port "chunky" read!
+ #f #f #f))
+ (port (make-chunked-input-port input)))
+ (setvbuf input _IONBF)
+ (setvbuf port _IONBF)
+ (list (utf8->string (get-bytevector-n port 6))
+ (utf8->string (get-bytevector-n port 6))
+ (utf8->string (get-bytevector-n port 7))
+ (utf8->string (get-bytevector-n port 6))
+ (reverse requests))))
+
+ (pass-if-equal "reads across chunk boundaries"
+ ;; Same, but read across chunk boundaries.
+ `("First " "chunk.Second " "chunk."
+ (1 1 1 6 6 1 1
+ 1 1 1 7 6 1 1))
+ (let* ((str "C\r\nFirst chunk.\r\nD\r\nSecond chunk.\r\n")
+ (requests '())
+ (read! (let ((port (open-input-string str)))
+ (lambda (bv index count)
+ (set! requests (cons count requests))
+ (let ((n (get-bytevector-n! port bv index
+ count)))
+ (if (eof-object? n) 0 n)))))
+ (input (make-custom-binary-input-port "chunky" read!
+ #f #f #f))
+ (port (make-chunked-input-port input)))
+ (setvbuf input _IONBF)
+ (setvbuf port _IONBF)
+ (list (utf8->string (get-bytevector-n port 6))
+ (utf8->string (get-bytevector-n port 13))
+ (utf8->string (get-bytevector-n port 6))
+ (reverse requests)))))
+
(pass-if-equal
(call-with-output-string
(lambda (out-raw)