cgi: cleaner looking without parens.
parent
b101f9d61b
commit
c5150307f5
|
@ -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
|
||||
|
|
|
@ -9,32 +9,32 @@ IN: cgi
|
|||
|
||||
<PRIVATE
|
||||
|
||||
: (query-string) ( string -- assoc )
|
||||
: query-string ( string -- assoc )
|
||||
query>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 ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue