diff --git a/extra/cgi/cgi-tests.factor b/extra/cgi/cgi-tests.factor index 8c535bd077..287768ff68 100644 --- a/extra/cgi/cgi-tests.factor +++ b/extra/cgi/cgi-tests.factor @@ -3,15 +3,15 @@ USING: cgi cgi.private kernel linked-assocs tools.test ; -{ LH{ } } [ "" (query-string) ] unit-test +{ LH{ } } [ "" query-string ] unit-test { LH{ { "a" { "1" } } { "b" { "2" } } } } -[ "a=1&b=2" (query-string) ] unit-test +[ "a=1&b=2" query-string ] unit-test { LH{ { "a" { "1" } } { "b" { "2" "3" } } } } -[ "a=1&b=2&b=3" (query-string) ] unit-test +[ "a=1&b=2&b=3" query-string ] unit-test -{ LH{ } "text/html" } [ "text/html" (content-type) ] unit-test +{ LH{ } "text/html" } [ "text/html" content-type ] unit-test { LH{ { "charset" { "utf-8" } } } "text/html" } -[ "text/html; charset=utf-8" (content-type) ] unit-test +[ "text/html; charset=utf-8" content-type ] unit-test diff --git a/extra/cgi/cgi.factor b/extra/cgi/cgi.factor index 585051f0fe..5e93827579 100644 --- a/extra/cgi/cgi.factor +++ b/extra/cgi/cgi.factor @@ -9,32 +9,32 @@ IN: cgi assoc [ nip ] assoc-filter [ [ [ CHAR: \s = ] trim ] [ dup string? [ 1array ] when ] bi* ] assoc-map ; : parse-get ( -- assoc ) - "QUERY_STRING" os-env "" or (query-string) ; + "QUERY_STRING" os-env "" or query-string ; -: (content-type) ( string -- params media/type ) +: content-type ( string -- params media/type ) ";" split unclip [ - [ LH{ } clone ] [ first (query-string) ] if-empty + [ LH{ } clone ] [ first query-string ] if-empty ] dip ; -: (multipart) ( -- assoc ) +: multipart ( -- assoc ) "multipart unsupported" throw ; -: (urlencoded) ( -- assoc ) +: urlencoded ( -- assoc ) "CONTENT_LENGTH" os-env [ string>number ] [ 0 ] if* read [ "" ] [ "&" append ] if-empty - "QUERY_STRING" os-env [ append ] when* (query-string) ; + "QUERY_STRING" os-env [ append ] when* query-string ; : parse-post ( -- assoc ) - "CONTENT_TYPE" os-env "" or (content-type) { - { "multipart/form-data" [ (multipart) ] } - { "application/x-www-form-urlencoded" [ (urlencoded) ] } + "CONTENT_TYPE" os-env "" or content-type { + { "multipart/form-data" [ multipart ] } + { "application/x-www-form-urlencoded" [ urlencoded ] } [ drop parse-get ] } case nip ;