add mime support to http
Closed / Rejected1096703fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 19 years ago
Descriptionplain2005-01-05 20:19:04
Not sure if this belongs here or in tcllib, but since http is part of the core I would think here. It is possible to post a mime message (the primary one of interest would be a multipart/form-data post) using http, but it is more complicated than it should be. Suggested functionality: test the -query argument to http::geturl, if it is determined to be a mime token (produced by the mime package in tcllib) then use that to set the content-type and associated information (such as boundary) and extract the message from that token. Alternately use a -mime argument to unambiguously invoke this functionality. This probably requires additional support from the tcllib mime package, particularly a way to query the boundary string separately from the entire message.
davidwplain2005-01-27 00:00:35
Logged In: YES
user_id=240
I created the following helper functions (change the
namespace if you want to use them), which work with http as
it stands now. It would probably be better to create a
-multipart switch for geturl, as it would be simpler.
proc multipload::multipart-var {var val} {
return "Content-Disposition: form-data;
name=\"$var\";\r\n\r\n${val}\r\n"
}
proc multipload::multipart-file {var filename} {
set fl [open $filename r]
fconfigure $fl -translation binary
set data [read $fl]
close $fl
return "Content-Disposition: form-data; name=\"${var}\";
filename=\"${filename}\"\r\n\r\n$data\n"
}
proc multipload::multipart/form-data {queryvarname
boundvarname parts} {
upvar $queryvarname query
upvar $boundvarname bound
set bound "-----NEXT_PART_[clock seconds].[pid]"
set result [join $parts "--${bound}\r\n"]
set result "--${bound}\r\n${result}--${bound}--"
set query $result
}
You can use them like so:
multipart/form-data query bound [list [multipart-file
fileupload $filename] \
[multipart-var action upload]]
set page [::http::geturl $url -type
"multipart/form-data; boundary=$bound" \
-query $query]
Hope the formatting isn't too bad with SF...
hobbsplain2008-03-12 16:41:58
Logged In: YES user_id=72656 Originator: NO This looks very appropriate for tcllib.
Log in (anonymous is fine) to add a comment.