http: change client/server to support LF and CRLF delimited headers.
parent
24232cb095
commit
46f8225f7a
|
@ -1,5 +1,5 @@
|
||||||
USING: accessors http.client http.client.private http tools.test
|
USING: accessors http.client http.client.private http
|
||||||
namespaces urls ;
|
io.streams.string kernel namespaces sequences tools.test urls ;
|
||||||
IN: http.client.tests
|
IN: http.client.tests
|
||||||
|
|
||||||
[ "localhost" f ] [ "localhost" parse-host ] unit-test
|
[ "localhost" f ] [ "localhost" parse-host ] unit-test
|
||||||
|
@ -43,3 +43,13 @@ IN: http.client.tests
|
||||||
[ "TRACE" ] [ "http://concatenative.org" <trace-request> method>> ] unit-test
|
[ "TRACE" ] [ "http://concatenative.org" <trace-request> method>> ] unit-test
|
||||||
[ "OPTIONS" ] [ "http://factorcode.org" <options-request> method>> ] unit-test
|
[ "OPTIONS" ] [ "http://factorcode.org" <options-request> method>> ] unit-test
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
{
|
||||||
|
"HTTP/1.1 200 Document follows"
|
||||||
|
"connection: close"
|
||||||
|
"content-type: text/html; charset=UTF-8"
|
||||||
|
"date: Wed, 12 Oct 2011 18:57:49 GMT"
|
||||||
|
"server: Factor http.server"
|
||||||
|
} [ "\n" join ] [ "\r\n" join ] bi
|
||||||
|
[ [ read-response ] with-string-reader ] bi@ =
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -56,7 +56,7 @@ ERROR: too-many-redirects ;
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
: read-response-line ( response -- response )
|
: read-response-line ( response -- response )
|
||||||
read-crlf parse-response-line first3
|
read-?crlf parse-response-line first3
|
||||||
[ >>version ] [ >>code ] [ >>message ] tri* ;
|
[ >>version ] [ >>code ] [ >>message ] tri* ;
|
||||||
|
|
||||||
: detect-encoding ( response -- encoding )
|
: detect-encoding ( response -- encoding )
|
||||||
|
@ -98,14 +98,14 @@ SYMBOL: redirects
|
||||||
] [ too-many-redirects ] if ; inline recursive
|
] [ too-many-redirects ] if ; inline recursive
|
||||||
|
|
||||||
: read-chunk-size ( -- n )
|
: read-chunk-size ( -- n )
|
||||||
read-crlf ";" split1 drop [ blank? ] trim-tail
|
read-?crlf ";" split1 drop [ blank? ] trim-tail
|
||||||
hex> [ "Bad chunk size" throw ] unless* ;
|
hex> [ "Bad chunk size" throw ] unless* ;
|
||||||
|
|
||||||
: read-chunked ( quot: ( chunk -- ) -- )
|
: read-chunked ( quot: ( chunk -- ) -- )
|
||||||
read-chunk-size dup zero?
|
read-chunk-size dup zero?
|
||||||
[ 2drop ] [
|
[ 2drop ] [
|
||||||
read [ swap call ] [ drop ] 2bi
|
read [ swap call ] [ drop ] 2bi
|
||||||
read-crlf B{ } assert= read-chunked
|
read-?crlf B{ } assert= read-chunked
|
||||||
] if ; inline recursive
|
] if ; inline recursive
|
||||||
|
|
||||||
: read-response-body ( quot response -- )
|
: read-response-body ( quot response -- )
|
||||||
|
|
|
@ -11,7 +11,7 @@ IN: http
|
||||||
CONSTANT: max-redirects 10
|
CONSTANT: max-redirects 10
|
||||||
|
|
||||||
: (read-header) ( -- alist )
|
: (read-header) ( -- alist )
|
||||||
[ read-crlf dup f like ] [ parse-header-line ] produce nip ;
|
[ read-?crlf dup f like ] [ parse-header-line ] produce nip ;
|
||||||
|
|
||||||
: collect-headers ( assoc -- assoc' )
|
: collect-headers ( assoc -- assoc' )
|
||||||
H{ } clone [ '[ _ push-at ] assoc-each ] keep ;
|
H{ } clone [ '[ _ push-at ] assoc-each ] keep ;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
USING: http http.server math sequences continuations tools.test
|
USING: accessors continuations http http.server
|
||||||
io.encodings.utf8 io.encodings.binary accessors ;
|
io.encodings.utf8 io.encodings.binary io.streams.string kernel
|
||||||
|
math sequences tools.test ;
|
||||||
IN: http.server.tests
|
IN: http.server.tests
|
||||||
|
|
||||||
[ t ] [ [ \ + first ] [ <500> ] recover response? ] unit-test
|
[ t ] [ [ \ + first ] [ <500> ] recover response? ] unit-test
|
||||||
|
@ -27,3 +28,13 @@ IN: http.server.tests
|
||||||
<response>
|
<response>
|
||||||
unparse-content-type
|
unparse-content-type
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ t ] [
|
||||||
|
{
|
||||||
|
"GET / HTTP/1.1"
|
||||||
|
"connection: close"
|
||||||
|
"host: 127.0.0.1:55532"
|
||||||
|
"user-agent: Factor http.client"
|
||||||
|
} [ "\n" join ] [ "\r\n" join ] bi
|
||||||
|
[ [ read-request ] with-string-reader ] bi@ =
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -37,7 +37,7 @@ IN: http.server
|
||||||
dup path>> "/" head? [ "Bad request: URL" throw ] unless ; inline
|
dup path>> "/" head? [ "Bad request: URL" throw ] unless ; inline
|
||||||
|
|
||||||
: read-request-line ( request -- request )
|
: read-request-line ( request -- request )
|
||||||
read-crlf parse-request-line first3
|
read-?crlf parse-request-line first3
|
||||||
[ >>method ] [ >url check-absolute >>url ] [ >>version ] tri* ;
|
[ >>method ] [ >url check-absolute >>url ] [ >>version ] tri* ;
|
||||||
|
|
||||||
: read-request-header ( request -- request )
|
: read-request-header ( request -- request )
|
||||||
|
|
Loading…
Reference in New Issue