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

View File

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

View File

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