From bfa34122f3ac2eb429b33dd340dfebfaa4badff1 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 22 Apr 2008 20:23:49 -0500 Subject: [PATCH] Fix chunked encoding --- extra/http/client/client.factor | 4 +-- extra/http/http.factor | 43 +++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/extra/http/client/client.factor b/extra/http/client/client.factor index ac5d220a52..8879a76a5c 100755 --- a/extra/http/client/client.factor +++ b/extra/http/client/client.factor @@ -74,8 +74,8 @@ PRIVATE> ] with-variable ; : read-chunks ( -- ) - readln ";" split1 drop hex> - dup { f 0 } member? [ drop ] [ read % read-chunks ] if ; + read-crlf ";" split1 drop hex> dup { f 0 } member? + [ drop ] [ read % read-crlf "" assert= read-chunks ] if ; : do-chunked-encoding ( response stream -- response stream/string ) over "transfer-encoding" header "chunked" = [ diff --git a/extra/http/http.factor b/extra/http/http.factor index 5e90962b27..4aaab2205e 100755 --- a/extra/http/http.factor +++ b/extra/http/http.factor @@ -1,10 +1,18 @@ ! Copyright (C) 2003, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: fry hashtables io io.streams.string kernel math sets -namespaces math.parser assocs sequences strings splitting ascii -io.encodings.utf8 io.encodings.string io.sockets namespaces -unicode.case combinators vectors sorting accessors calendar -calendar.format quotations arrays combinators.lib byte-arrays ; +USING: accessors kernel combinators math namespaces + +assocs sequences splitting sorting sets debugger +strings vectors hashtables quotations arrays byte-arrays +math.parser calendar calendar.format + +io io.streams.string io.encodings.utf8 io.encodings.string +io.sockets + +unicode.case unicode.categories qualified ; + +EXCLUDE: fry => , ; + IN: http : http-port 80 ; inline @@ -13,11 +21,12 @@ IN: http #! In a URL, can this character be used without #! URL-encoding? { - [ dup letter? ] - [ dup LETTER? ] - [ dup digit? ] - [ dup "/_-.:" member? ] - } || nip ; foldable + { [ dup letter? ] [ t ] } + { [ dup LETTER? ] [ t ] } + { [ dup digit? ] [ t ] } + { [ dup "/_-.:" member? ] [ t ] } + [ f ] + } cond nip ; foldable : push-utf8 ( ch -- ) 1string utf8 encode @@ -75,8 +84,16 @@ IN: http ] if ] if ; +: read-lf ( -- string ) + "\n" read-until CHAR: \n assert= ; + +: read-crlf ( -- string ) + "\r" read-until + CHAR: \r assert= + read1 CHAR: \n assert= ; + : read-header-line ( -- ) - readln dup + read-crlf dup empty? [ drop ] [ header-line read-header-line ] if ; : read-header ( -- assoc ) @@ -224,7 +241,7 @@ cookies ; dup { "1.0" "1.1" } member? [ "Bad version" throw ] unless ; : read-request-version ( request -- request ) - readln [ CHAR: \s = ] left-trim + read-crlf [ CHAR: \s = ] left-trim parse-version >>version ; @@ -372,7 +389,7 @@ body ; >>code ; : read-response-message - readln >>message ; + read-crlf >>message ; : read-response-header read-header >>header