From 2f2d31a623785b936e7fc7b18fc72af34ab0792e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 23 Apr 2008 00:53:42 -0500 Subject: [PATCH] Fix HTTP unit tests --- extra/http/http-tests.factor | 15 +++++++++------ extra/http/http.factor | 3 +-- extra/http/server/actions/actions-tests.factor | 10 +++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/extra/http/http-tests.factor b/extra/http/http-tests.factor index 9302045624..3a50630335 100755 --- a/extra/http/http-tests.factor +++ b/extra/http/http-tests.factor @@ -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 ascii [ "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 diff --git a/extra/http/http.factor b/extra/http/http.factor index 4aaab2205e..3e81fccd24 100755 --- a/extra/http/http.factor +++ b/extra/http/http.factor @@ -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 diff --git a/extra/http/server/actions/actions-tests.factor b/extra/http/server/actions/actions-tests.factor index ebf8e8770b..90e632d7f5 100755 --- a/extra/http/server/actions/actions-tests.factor +++ b/extra/http/server/actions/actions-tests.factor @@ -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