-USING: accessors http.client http.client.private http tools.test
-namespaces urls ;
+USING: accessors http.client http.client.private http
+io.streams.string kernel namespaces sequences tools.test urls ;
IN: http.client.tests
[ "localhost" f ] [ "localhost" parse-host ] unit-test
[ "TRACE" ] [ "http://concatenative.org" <trace-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
drop ;
: read-response-line ( response -- response )
- read-crlf parse-response-line first3
+ read-?crlf parse-response-line first3
[ >>version ] [ >>code ] [ >>message ] tri* ;
: detect-encoding ( response -- encoding )
] [ too-many-redirects ] if ; inline recursive
: read-chunk-size ( -- n )
- read-crlf ";" split1 drop [ blank? ] trim-tail
+ read-?crlf ";" split1 drop [ blank? ] trim-tail
hex> [ "Bad chunk size" throw ] unless* ;
: read-chunked ( quot: ( chunk -- ) -- )
read-chunk-size dup zero?
[ 2drop ] [
read [ swap call ] [ drop ] 2bi
- read-crlf B{ } assert= read-chunked
+ read-?crlf B{ } assert= read-chunked
] if ; inline recursive
: read-response-body ( quot response -- )
CONSTANT: max-redirects 10
: (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' )
H{ } clone [ '[ _ push-at ] assoc-each ] keep ;
-USING: http http.server math sequences continuations tools.test
-io.encodings.utf8 io.encodings.binary accessors ;
+USING: accessors continuations http http.server
+io.encodings.utf8 io.encodings.binary io.streams.string kernel
+math sequences tools.test ;
IN: http.server.tests
[ t ] [ [ \ + first ] [ <500> ] recover response? ] unit-test
[ "application/octet-stream" ] [
<response>
unparse-content-type
-] unit-test
\ No newline at end of file
+] 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
dup path>> "/" head? [ "Bad request: URL" throw ] unless ; inline
: read-request-line ( request -- request )
- read-crlf parse-request-line first3
+ read-?crlf parse-request-line first3
[ >>method ] [ >url check-absolute >>url ] [ >>version ] tri* ;
: read-request-header ( request -- request )