aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorpaulsnar <paulsnar@paulsnar.lv>2022-02-10 20:00:46 +0200
committerpaulsnar <paulsnar@paulsnar.lv>2022-02-10 20:12:45 +0200
commitb32f9f84e746eb6a216c10d29e4d0340fc5635a7 (patch)
tree06eb11e307f7e1a8fb0de747161cc5a2ddc0427e /test
parentMerge pull request #59 from pyrmont/bugfix.stacktrace-message (diff)
http: Hex-encode chunk length
See RFC 7230 ยง 4.1.
Diffstat (limited to 'test')
-rw-r--r--test/suite0012.janet18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/suite0012.janet b/test/suite0012.janet
index 726c71f..acaea72 100644
--- a/test/suite0012.janet
+++ b/test/suite0012.janet
@@ -62,6 +62,24 @@
(def res (http/request "POST" "http://127.0.0.1:9816" :body (string/repeat "a" 4194304)))
(test-http-item res nil nil 200 {"content-length" "4194304"}))
+(defn- chunk
+ [data]
+ (string/format "%x\r\n%s\r\n" (length data) data))
+(let [[r w] (os/pipe)]
+ (defer (:close r)
+ (http/send-response w {:status 200
+ :body ["a" (string/repeat "a" 16) (string/repeat "a" 256)]})
+ (:close w)
+ (assert
+ (deep= (:read r :all)
+ (buffer
+ "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"
+ (chunk "a")
+ (chunk (string/repeat "a" 16))
+ (chunk (string/repeat "a" 256))
+ (chunk "")))
+ "chunked encoding for write-body")))
+
# Test the query string grammar by itself.
(assert (deep= @[@{"a" " "}] (peg/match http/query-string-grammar "a=%20")) "query string grammar 1")
(assert (deep= @[@{"a" " " "b" true}] (peg/match http/query-string-grammar "a=%20&b")) "query string grammar 2")