Fix HTTP unit tests

db4
Slava Pestov 2008-04-23 00:53:42 -05:00
parent 57a39f766b
commit 2f2d31a623
3 changed files with 17 additions and 11 deletions

View File

@ -24,6 +24,8 @@ IN: http.tests
[ "/bar" ] [ "http://foo.com/bar" url>path ] unit-test [ "/bar" ] [ "http://foo.com/bar" url>path ] unit-test
[ "/bar" ] [ "/bar" url>path ] unit-test [ "/bar" ] [ "/bar" url>path ] unit-test
: lf>crlf "\n" split "\r\n" join ;
STRING: read-request-test-1 STRING: read-request-test-1
GET http://foo/bar HTTP/1.1 GET http://foo/bar HTTP/1.1
Some-Header: 1 Some-Header: 1
@ -45,7 +47,7 @@ blah
cookies: V{ } cookies: V{ }
} }
] [ ] [
read-request-test-1 [ read-request-test-1 lf>crlf [
read-request read-request
] with-string-reader ] with-string-reader
] unit-test ] unit-test
@ -59,7 +61,7 @@ blah
; ;
read-request-test-1' 1array [ read-request-test-1' 1array [
read-request-test-1 read-request-test-1 lf>crlf
[ read-request ] with-string-reader [ read-request ] with-string-reader
[ write-request ] with-string-writer [ write-request ] with-string-writer
! normalize crlf ! normalize crlf
@ -69,6 +71,7 @@ read-request-test-1' 1array [
STRING: read-request-test-2 STRING: read-request-test-2
HEAD http://foo/bar HTTP/1.1 HEAD http://foo/bar HTTP/1.1
Host: www.sex.com Host: www.sex.com
; ;
[ [
@ -83,7 +86,7 @@ Host: www.sex.com
cookies: V{ } cookies: V{ }
} }
] [ ] [
read-request-test-2 [ read-request-test-2 lf>crlf [
read-request read-request
] with-string-reader ] with-string-reader
] unit-test ] unit-test
@ -104,7 +107,7 @@ blah
cookies: V{ } cookies: V{ }
} }
] [ ] [
read-response-test-1 read-response-test-1 lf>crlf
[ read-response ] with-string-reader [ read-response ] with-string-reader
] unit-test ] unit-test
@ -117,7 +120,7 @@ content-type: text/html
; ;
read-response-test-1' 1array [ read-response-test-1' 1array [
read-response-test-1 read-response-test-1 lf>crlf
[ read-response ] with-string-reader [ read-response ] with-string-reader
[ write-response ] with-string-writer [ write-response ] with-string-writer
! normalize crlf ! normalize crlf
@ -162,7 +165,7 @@ io.encodings.ascii ;
"localhost" 1237 <inet> ascii <client> [ "localhost" 1237 <inet> ascii <client> [
"GET nested HTTP/1.0\r\n" write flush "GET nested HTTP/1.0\r\n" write flush
"\r\n" write flush "\r\n" write flush
readln drop read-crlf drop
read-header read-header
] with-stream "location" swap at "/" head? ] with-stream "location" swap at "/" head?
] unit-test ] unit-test

View File

@ -89,8 +89,7 @@ IN: http
: read-crlf ( -- string ) : read-crlf ( -- string )
"\r" read-until "\r" read-until
CHAR: \r assert= [ CHAR: \r assert= read1 CHAR: \n assert= ] when* ;
read1 CHAR: \n assert= ;
: read-header-line ( -- ) : read-header-line ( -- )
read-crlf dup read-crlf dup

View File

@ -1,7 +1,7 @@
IN: http.server.actions.tests IN: http.server.actions.tests
USING: http.server.actions http.server.validators USING: http.server.actions http.server.validators
tools.test math math.parser multiline namespaces http tools.test math math.parser multiline namespaces http
io.streams.string http.server sequences accessors ; io.streams.string http.server sequences splitting accessors ;
[ [
"a" [ v-number ] { { "a" "123" } } validate-param "a" [ v-number ] { { "a" "123" } } validate-param
@ -13,6 +13,8 @@ io.streams.string http.server sequences accessors ;
{ { "a" [ v-number ] } { "b" [ v-number ] } } >>get-params { { "a" [ v-number ] } { "b" [ v-number ] } } >>get-params
"action-1" set "action-1" set
: lf>crlf "\n" split "\r\n" join ;
STRING: action-request-test-1 STRING: action-request-test-1
GET http://foo/bar?a=12&b=13 HTTP/1.1 GET http://foo/bar?a=12&b=13 HTTP/1.1
@ -20,7 +22,8 @@ blah
; ;
[ 25 ] [ [ 25 ] [
action-request-test-1 [ read-request ] with-string-reader action-request-test-1 lf>crlf
[ read-request ] with-string-reader
request set request set
"/blah" "/blah"
"action-1" get call-responder "action-1" get call-responder
@ -40,7 +43,8 @@ xxx=4
; ;
[ "/blahXXXX" ] [ [ "/blahXXXX" ] [
action-request-test-2 [ read-request ] with-string-reader action-request-test-2 lf>crlf
[ read-request ] with-string-reader
request set request set
"/blah" "/blah"
"action-2" get call-responder "action-2" get call-responder