make mime parsing return a single hashtable instead of several different ones
parent
6f12877418
commit
43830f5fcc
|
@ -42,7 +42,7 @@ ERROR: no-boundary ;
|
||||||
";" split1 nip
|
";" split1 nip
|
||||||
"=" split1 nip [ no-boundary ] unless* ;
|
"=" split1 nip [ no-boundary ] unless* ;
|
||||||
|
|
||||||
: read-multipart-data ( request -- form-variables uploaded-files )
|
: read-multipart-data ( request -- mime-parts )
|
||||||
[ "content-type" header ]
|
[ "content-type" header ]
|
||||||
[ "content-length" header string>number ] bi
|
[ "content-length" header string>number ] bi
|
||||||
unlimit-input
|
unlimit-input
|
||||||
|
@ -55,7 +55,7 @@ ERROR: no-boundary ;
|
||||||
|
|
||||||
: parse-content ( request content-type -- post-data )
|
: parse-content ( request content-type -- post-data )
|
||||||
[ <post-data> swap ] keep {
|
[ <post-data> swap ] keep {
|
||||||
{ "multipart/form-data" [ read-multipart-data assoc-union >>params ] }
|
{ "multipart/form-data" [ read-multipart-data >>params ] }
|
||||||
{ "application/x-www-form-urlencoded" [ read-content query>assoc >>params ] }
|
{ "application/x-www-form-urlencoded" [ read-content query>assoc >>params ] }
|
||||||
[ drop read-content >>data ]
|
[ drop read-content >>data ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
|
@ -20,11 +20,11 @@ IN: mime.multipart.tests
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
|
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
|
||||||
nip "\"up.txt\"" swap key?
|
"\"up.txt\"" swap key?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
|
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
|
||||||
drop "\"text1\"" swap key?
|
"\"text1\"" swap key?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ header
|
||||||
content-disposition bytes
|
content-disposition bytes
|
||||||
filename temp-file
|
filename temp-file
|
||||||
name name-content
|
name name-content
|
||||||
uploaded-files
|
mime-parts ;
|
||||||
form-variables ;
|
|
||||||
|
|
||||||
TUPLE: mime-file headers filename temporary-path ;
|
TUPLE: mime-file headers filename temporary-path ;
|
||||||
TUPLE: mime-variable headers key value ;
|
TUPLE: mime-variable headers key value ;
|
||||||
|
@ -25,8 +24,7 @@ TUPLE: mime-variable headers key value ;
|
||||||
: <multipart> ( mime-separator -- multipart )
|
: <multipart> ( mime-separator -- multipart )
|
||||||
multipart new
|
multipart new
|
||||||
swap >>mime-separator
|
swap >>mime-separator
|
||||||
H{ } clone >>uploaded-files
|
H{ } clone >>mime-parts ;
|
||||||
H{ } clone >>form-variables ;
|
|
||||||
|
|
||||||
ERROR: bad-header bytes ;
|
ERROR: bad-header bytes ;
|
||||||
|
|
||||||
|
@ -87,16 +85,16 @@ ERROR: end-of-stream multipart ;
|
||||||
] [
|
] [
|
||||||
[ [ header>> ] [ filename>> ] [ temp-file>> ] tri mime-file boa ]
|
[ [ header>> ] [ filename>> ] [ temp-file>> ] tri mime-file boa ]
|
||||||
[ filename>> ]
|
[ filename>> ]
|
||||||
[ uploaded-files>> set-at ] tri
|
[ mime-parts>> set-at ] tri
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: save-form-variable ( multipart -- )
|
: save-mime-part ( multipart -- )
|
||||||
dup name>> empty-name? [
|
dup name>> empty-name? [
|
||||||
drop
|
drop
|
||||||
] [
|
] [
|
||||||
[ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ]
|
[ [ header>> ] [ name>> ] [ name-content>> ] tri mime-variable boa ]
|
||||||
[ name>> ]
|
[ name>> ]
|
||||||
[ form-variables>> set-at ] tri
|
[ mime-parts>> set-at ] tri
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: dump-mime-file ( multipart filename -- multipart )
|
: dump-mime-file ( multipart filename -- multipart )
|
||||||
|
@ -124,7 +122,7 @@ ERROR: unknown-content-disposition multipart ;
|
||||||
] [
|
] [
|
||||||
"name" lookup-disposition [
|
"name" lookup-disposition [
|
||||||
[ dup mime-separator>> dump-string >>name-content ] dip
|
[ dup mime-separator>> dump-string >>name-content ] dip
|
||||||
>>name dup save-form-variable
|
>>name dup save-mime-part
|
||||||
] [
|
] [
|
||||||
unknown-content-disposition
|
unknown-content-disposition
|
||||||
] if*
|
] if*
|
||||||
|
@ -157,6 +155,6 @@ ERROR: no-content-disposition multipart ;
|
||||||
read-header
|
read-header
|
||||||
dup end-of-stream?>> [ process-header parse-multipart-loop ] unless ;
|
dup end-of-stream?>> [ process-header parse-multipart-loop ] unless ;
|
||||||
|
|
||||||
: parse-multipart ( separator -- form-variables uploaded-files )
|
: parse-multipart ( separator -- mime-parts )
|
||||||
<multipart> parse-beginning parse-multipart-loop
|
<multipart> parse-beginning parse-multipart-loop
|
||||||
[ form-variables>> ] [ uploaded-files>> ] bi ;
|
mime-parts>> ;
|
||||||
|
|
Loading…
Reference in New Issue