util::http::append_to_payload (private)
util::http::append_to_payload [ -content content ] [ -file file ] \ [ -base64 ] encoding max_size payload spool_file wfd
Defined in packages/acs-tcl/tcl/http-client-procs.tcl
Appends content to a POST payload making sure this doesn't exceed given max size. When this happens, proc creates a spool file and writes there the content.
- Switches:
- -content (optional)
- -file (optional)
- -base64 (optional, boolean)
- Parameters:
- encoding (required)
- max_size (required)
- payload (required)
- spool_file (required)
- wfd (required)
- Returns:
- a list in the format {total_payload spooling_file spooling_file_handle}
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: set encode_p [expr {$encoding ni [list "binary" [encoding system]]}] set payload_size [string length $payload] # Get content size if {$file eq ""} { set content_size [string length $content] } else { set content_size [ad_file size $file] } # Content size seems ok. Now try applying encoding if {$spool_file eq "" && $payload_size + $content_size <= $max_size} { if {$file ne ""} { set rfd [open $file r] fconfigure $rfd -translation binary set content [read $rfd] close $rfd } if {$base64_p} { set content [ns_base64encode $content] } if {$encode_p} { set content [encoding convertto $encoding $content] } set content_size [string length $content] } if {$spool_file eq "" && $payload_size + $content_size <= $max_size} { ## Payload small enough: # just append new content return [list ${payload}${content} {} {}] } ## Payload is too big: if {$spool_file eq ""} { # create the spool file set wfd [ad_opentmpfile spool_file] fconfigure $wfd -translation binary # flush currently collected payload puts -nonewline $wfd $payload # set required encoding for next content if {$encode_p} { fconfigure $wfd -encoding $encoding } } # output content to spool file if {$file ne ""} { if {$base64_p} { # TODO: it's tricky to base64 encode without slurping # the whole file (exec + pipes?) error "Base64 encoding currently supported only for in-memory file POSTing" } set rfd [open $file r] fconfigure $rfd -translation binary fconfigure $wfd -translation binary fcopy $rfd $wfd fconfigure $wfd -translation auto close $rfd } else { puts -nonewline $wfd $content } return [list {} $spool_file $wfd]XQL Not present: Generic, PostgreSQL, Oracle