Fix chunked encoding

db4
Slava Pestov 2008-04-22 20:23:49 -05:00
parent 6afa62b57c
commit bfa34122f3
2 changed files with 32 additions and 15 deletions

View File

@ -74,8 +74,8 @@ PRIVATE>
] with-variable ; ] with-variable ;
: read-chunks ( -- ) : read-chunks ( -- )
readln ";" split1 drop hex> read-crlf ";" split1 drop hex> dup { f 0 } member?
dup { f 0 } member? [ drop ] [ read % read-chunks ] if ; [ drop ] [ read % read-crlf "" assert= read-chunks ] if ;
: do-chunked-encoding ( response stream -- response stream/string ) : do-chunked-encoding ( response stream -- response stream/string )
over "transfer-encoding" header "chunked" = [ over "transfer-encoding" header "chunked" = [

View File

@ -1,10 +1,18 @@
! Copyright (C) 2003, 2008 Slava Pestov. ! Copyright (C) 2003, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: fry hashtables io io.streams.string kernel math sets USING: accessors kernel combinators math namespaces
namespaces math.parser assocs sequences strings splitting ascii
io.encodings.utf8 io.encodings.string io.sockets namespaces assocs sequences splitting sorting sets debugger
unicode.case combinators vectors sorting accessors calendar strings vectors hashtables quotations arrays byte-arrays
calendar.format quotations arrays combinators.lib 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 IN: http
: http-port 80 ; inline : http-port 80 ; inline
@ -13,11 +21,12 @@ IN: http
#! In a URL, can this character be used without #! In a URL, can this character be used without
#! URL-encoding? #! URL-encoding?
{ {
[ dup letter? ] { [ dup letter? ] [ t ] }
[ dup LETTER? ] { [ dup LETTER? ] [ t ] }
[ dup digit? ] { [ dup digit? ] [ t ] }
[ dup "/_-.:" member? ] { [ dup "/_-.:" member? ] [ t ] }
} || nip ; foldable [ f ]
} cond nip ; foldable
: push-utf8 ( ch -- ) : push-utf8 ( ch -- )
1string utf8 encode 1string utf8 encode
@ -75,8 +84,16 @@ IN: http
] if ] if
] 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 ( -- ) : read-header-line ( -- )
readln dup read-crlf dup
empty? [ drop ] [ header-line read-header-line ] if ; empty? [ drop ] [ header-line read-header-line ] if ;
: read-header ( -- assoc ) : read-header ( -- assoc )
@ -224,7 +241,7 @@ cookies ;
dup { "1.0" "1.1" } member? [ "Bad version" throw ] unless ; dup { "1.0" "1.1" } member? [ "Bad version" throw ] unless ;
: read-request-version ( request -- request ) : read-request-version ( request -- request )
readln [ CHAR: \s = ] left-trim read-crlf [ CHAR: \s = ] left-trim
parse-version parse-version
>>version ; >>version ;
@ -372,7 +389,7 @@ body ;
>>code ; >>code ;
: read-response-message : read-response-message
readln >>message ; read-crlf >>message ;
: read-response-header : read-response-header
read-header >>header read-header >>header