Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | mime: [header get] now returns one matching value, plus parameters. Documentation updated to reflect new API. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | pooryorick |
Files: | files | file ages | folders |
SHA3-256: |
ebcce7f24e38ff15104e2ce0b5d4acca |
User & Date: | pooryorick 2018-10-26 17:46:12.586 |
Context
2021-05-01
| ||
10:30 | mime: [header get] now returns one matching value, plus parameters. Documentation updated to reflect new API. check-in: 6a0823d6ef user: pooryorick tags: mime | |
2018-10-29
| ||
18:54 | mime: Fix problem with content type handling. ncgi: Add object interface, update documentation. check-in: efdd4f9d20 user: pooryorick tags: pooryorick | |
2018-10-26
| ||
17:46 | mime: [header get] now returns one matching value, plus parameters. Documentation updated to reflect new API. check-in: ebcce7f24e user: pooryorick tags: pooryorick | |
2018-09-28
| ||
14:20 | alphabetize routines migrate tests from ncgi module. check-in: 9eb4b1a47a user: pooryorick tags: pooryorick | |
Changes
Changes to modules/mime/mime.man.
︙ | ︙ | |||
107 108 109 110 111 112 113 | [option -decode] converts the message body from the character set it is encoded in. [call [cmd ::mime::datetime] ([arg time] | [option -now]) [arg property]] | | > | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | [option -decode] converts the message body from the character set it is encoded in. [call [cmd ::mime::datetime] ([arg time] | [option -now]) [arg property]] Returns the [arg property] of [arg time], which is an 822-style date-time value. [para] Available properties and their ranges are: [list_begin definitions] |
︙ | ︙ | |||
187 188 189 190 191 192 193 | Destroys the message corresponding to [arg token] and returns the empty string. [para] | | | < | > > | | | | > > | | < | | < < < | 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | Destroys the message corresponding to [arg token] and returns the empty string. [para] [option -subordinates] specifies which messages comprising the body should also be destroyed. The default value is [const dynamic], indicates all component messages that were created by [cmd ::mime::initialize]. [const all] indicates all component messages. [const none] indicates that no component messages should be destroyed. [call [cmd ::mime::header] [cmd serialize] [arg value] [arg parameters]] Returns the the serialization of a header. [call [cmd ::mime::header] [cmd get] [arg token] [opt "[arg key] | [option -names]"]] Returns the header of a message as a multidict where each value is a list containing the header value and a dictionary of parameters for that header. [para] If [arg name] is provided, returns the value and parameters of the last entry matching that name, without regard to case. [para] If [option -names] is provided, returns a list of all header names. [call [cmd ::mime::header] [cmd set] [arg token] [arg {name value}] [ \ opt "[arg parameters] [opt "[option -mode] [const write] | [\ const append] | [const delete]"]"]] [arg parameters] is a dictionary of parameters for the header. If [const append] is provided, creates a new header named [arg name] with the value of [arg value] and any provided [arg parameters]. If [const write] is provided, first deletes any existing headers matching [arg name]. If [const delete] is provided, deletes any existing header matching [arg name]. Returns a list of strings containing the previous value associated with the key. [para] |
︙ | ︙ | |||
282 283 284 285 286 287 288 | [def [const params]] A list of "Content-Type" parameters [def [const parts]] | | | | | | | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | [def [const params]] A list of "Content-Type" parameters [def [const parts]] A list of tokens for messages that comprise a multipart body. Only exists if there are any such messages. [def [const size]] The approximate size of the unencoded content. [list_end] [call [cmd ::mime::serialize] [arg token] [opt [option -level]] [ opt "[option -chan] [arg channel]"]] Returns the serialization of the message corresponding to [arg token]. If [option -chan] is provided, writes the serialization to [arg channel] and returns the empty string. [option -level], if provided, indicates the level of the part in the message hierarchy. The [const MIME-Version] header is only included at level [const 0]. Yields from the current coroutine as needed to wait for input to become available. [call [cmd ::mime::parseaddress] [arg addresses]] Returns a list describing the comma-separated 822-style [arg addresses]. [para] Each dictionary contains the following keys, whose values may be the empty string: |
︙ | ︙ | |||
376 377 378 379 380 381 382 | [call [cmd ::mime::reversemapencoding] [arg charset_type]] Maps MIME charset types onto tcl encoding names. Those that are unknown return "". [list_end] | < < < < < < < < < < < < < < < < < < < < < < < < | 376 377 378 379 380 381 382 383 384 385 386 | [call [cmd ::mime::reversemapencoding] [arg charset_type]] Maps MIME charset types onto tcl encoding names. Those that are unknown return "". [list_end] [vset CATEGORY mime] [include ../doctools2base/include/feedback.inc] [manpage_end] |
Changes to modules/mime/mime.tcl.
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # # Influenced by Borenstein's/Rose's safe-tcl (circa 1993) and Darren New's # unpublished package of 1999. # # new string features and inline scan are used, requiring 8.3. package require Tcl 8.6 package require tcl::chan::memchan package require tcl::chan::string package require coroutine namespace eval ::mime { namespace path ::coroutine::util {*}[namespace path] } | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # # Influenced by Borenstein's/Rose's safe-tcl (circa 1993) and Darren New's # unpublished package of 1999. # # new string features and inline scan are used, requiring 8.3. package require Tcl 8.6 package require tcl::chan::memchan package require tcl::chan::string package require coroutine namespace eval ::mime { namespace path ::coroutine::util {*}[namespace path] } |
︙ | ︙ | |||
72 73 74 75 76 77 78 | # # state variables: # # canonicalP: input is in its canonical form # encoding: transfer encoding # version: MIME-version | | < < | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | # # state variables: # # canonicalP: input is in its canonical form # encoding: transfer encoding # version: MIME-version # header: dictionary (keys are lower-case) # value: either "file", "parts", or "string" # # file: input file # fd: cached file-descriptor, typically for root # root: token for top-level part, for (distant) subordinates # offset: number of octets from beginning of file/string # count: length in octets of (encoded) content |
︙ | ︙ | |||
1438 1439 1440 1441 1442 1443 1444 | # or quoted-printable). proc ::mime::encoding token { # FRINK: nocheck upvar 0 $token state upvar 0 state(params) params | | | 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 | # or quoted-printable). proc ::mime::encoding token { # FRINK: nocheck upvar 0 $token state upvar 0 state(params) params lassign [header get $token content-type] content switch -glob $content { audio/* - image/* - video/* { |
︙ | ︙ | |||
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | } proc ::mime::header::boundary {} { return [uniqueID] } proc ::mime::header::serialize {token name value params} { variable notattchar_re set lname [string tolower $name] # to do: check key for conformance # to do: properly quote/process $value for interpolation | > > > > > > > > > > > > > | 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 | } proc ::mime::header::boundary {} { return [uniqueID] } # ::mime::dunset -- # # Unset all values for $key, without "normalizing" other redundant keys proc ::mime::header::dunset {dictname key} { upvar 1 $dictname dict join [lmap {key1 val} $dict[set dict {}] { if {$key1 eq $key} continue list $key $val }] } proc ::mime::header::serialize {token name value params} { variable notattchar_re set lname [string tolower $name] # to do: check key for conformance # to do: properly quote/process $value for interpolation |
︙ | ︙ | |||
1867 1868 1869 1870 1871 1872 1873 | return $res } proc ::mime::header::exists {token name} { upvar 0 $token state set lname [string tolower $name] | | > | > | < > | < < | < < < < < < < < < < < < < > | > > | < < < < < < | > > > | | > > < < | 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 | return $res } proc ::mime::header::exists {token name} { upvar 0 $token state set lname [string tolower $name] expr {[dict exists $state(headerlower) $lname] || [dict exists $state(headerinternallower) $lname]} } # ::mime::header get -- # # Returns the header of a message as a multidict where each value is a list # containing the header value and a dictionary parameters for that header. # If $key is provided, returns only the value and paramemters of the last # maching header, without regard for case. # # If -names is specified, a list of all header names is returned. # proc ::mime::header::get {token {key {}}} { # FRINK: nocheck upvar 0 $token state parse $token set headerlower $state(headerlower) set header $state(header) set headerinternallower $state(headerinternallower) set headerinternal $state(headerinternal) switch $key { {} { set result [dict merge $headerinternal $header] set tencoding [getTransferEncoding $token] if {$tencoding ne {}} { lappend result Content-Transfer-Encoding [list $tencoding {}] } return $result } -names { return [dict keys $header] } default { set lower [string tolower $key] switch $lower { content-transfer-encoding { return [list [getTransferEncoding $token] {}] } mime-version { return [list $state(version) {}] } default { set res {} if {[dict exists $headerinternallower $lower]} { return [dict get $headerinternallower $lower] } elseif {[dict exists headerlower $lower]} { return [dict get $headerlower $lower] } else { error [list {no such header} $key] } } } } } } |
︙ | ︙ | |||
2332 2333 2334 2335 2336 2337 2338 | # Results: # Returns previous value associated with the specified key. proc ::mime::header::set_ {token key value args} { variable internal # FRINK: nocheck upvar 0 $token state | < | > > > > | > > > > > > > | > | > | | < < < < | < < | 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 | # Results: # Returns previous value associated with the specified key. proc ::mime::header::set_ {token key value args} { variable internal # FRINK: nocheck upvar 0 $token state parse $token set params {} switch [llength $args] { 1 - 3 { set args [lassign $args[set args {}] params] } 0 - 2 { # carry on } default { error [list {wrong # args}] } } array set options [list -mode write] array set options {} dict for {opt val} $args { switch $opt { -mode { set options($opt) $val } default { error [list {unknon option} $opt] } } } set lower [string tolower $key] set headerlower $state(headerlower) set header $state(header) set headerinternallower $state(headerinternallower) set headerinternal $state(headerinternal) if {[catch {header get $lower} result]} { #TODO: this code path is not tested if {$options(-mode) eq {delete}} { error [list {key not in header} $key] } set result {} } switch $options(-mode) { append - write { switch $lower { content-md5 - content-transfer-encoding |
︙ | ︙ | |||
2400 2401 2402 2403 2404 2405 2406 | } default { #carry on } } } } | | | | > > | | > | > > > > | | > > > > > > > | | | | | > > > > > > > > > | 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 | } default { #carry on } } } } if {$options(-mode) eq {write}} { if {[dict exists $header $key]} { dunset header $key } if {[dict exists $headerlower $lower]} { dunset headerlower $lower } if {[dict exists headerinternal $key]} { dunset headerinternal $key } if {[dict exists $headerinternallower $lower]} { dunset headerinternallower $lower } } set newval [list $value $params] if {$internal} { lappend headerinternal $key $newval lappend headerinternallower $lower $newval } else { lappend header $key $newval lappend headerlower $lower $newval } } delete { unset headerlower($lower) unset headerinternallower($lower) unset header($key) unset headerinternal($key) } default { error "unknown value for -mode $options(-mode)" } } set state(header) $header set state(headerlower) $headerlower set state(headerinternal) $headerinternal set state(headerinternallower) $headerinternallower return $result } proc ::mime::header::setinternal args { variable internal 1 try { set_ {*}$args } finally { set internal 0 } } proc ::mime::header::dset {name key val} { if {[dict exists $name]} { set name [lsearch } } # ::mime::initialize -- # # the public interface for initializeaux proc ::mime::initialize args { |
︙ | ︙ | |||
2505 2506 2507 2508 2509 2510 2511 | # FRINK: nocheck upvar 0 $token state upvar 0 state(canonicalP) canonicalP upvar 0 state(params) params set params {} | < | > | | | 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 | # FRINK: nocheck upvar 0 $token state upvar 0 state(canonicalP) canonicalP upvar 0 state(params) params set params {} set state(encoding) {} set state(version) 1.0 set state(bodyparsed) 0 set canonicalP 0 set state(header) {} set state(headerinternal) {} set state(headerinternallower) {} set state(headerlower) {} set state(headerparsed) 0 set state(cid) 0 set state(closechan) 1 set state(root) $token set userparams 0 |
︙ | ︙ | |||
2691 2692 2693 2694 2695 2696 2697 | if {$lname in {content-md5 mime-version}} { error [list {don't go there...}] } header::setinternal $token $name $hvalue } } | | | 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 | if {$lname in {content-md5 mime-version}} { error [list {don't go there...}] } header::setinternal $token $name $hvalue } } lassign [header get $token content-type] content dummy switch $state(value) { file { set state(offset) 0 } parts { |
︙ | ︙ | |||
2837 2838 2839 2840 2841 2842 2843 | mime::initializeaux $child -root $state(root) -string $strng } else { mime::initializeaux $child -root $state(root) -lineslist [ lrange $state(lines) $state(lines.current) end] } } } | < | 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 | mime::initializeaux $child -root $state(root) -string $strng } else { mime::initializeaux $child -root $state(root) -lineslist [ lrange $state(lines) $state(lines.current) end] } } } return } set state(value) parts dict update params boundary boundary {} if {![info exists boundary]} { |
︙ | ︙ | |||
3701 3702 3703 3704 3705 3706 3707 | upvar 0 state(fd) fd parsepart $token set result {} if {!$level} { puts $channel [header serialize $token MIME-Version $state(version) {}] } | | | | 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 | upvar 0 state(fd) fd parsepart $token set result {} if {!$level} { puts $channel [header serialize $token MIME-Version $state(version) {}] } foreach {name value} [header get $token] { puts $channel [header serialize $token $name {*}$value] } set converter {} set encoding {} if {$state(value) ne "parts"} { if {$state(canonicalP)} { if {[set encoding $state(encoding)] eq {}} { |
︙ | ︙ |
Changes to modules/mime/mime.test.
︙ | ︙ | |||
752 753 754 755 756 757 758 | fconfigure $ofh -translation binary mime::serialize $attachment -chan $ofh -level 1 close $ofh set data [viewFile $out] file delete $in $out set data | | | | | | 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | fconfigure $ofh -translation binary mime::serialize $attachment -chan $ofh -level 1 close $ofh set data [viewFile $out] file delete $in $out set data }} {Content-Type: application/octet-stream ; name=a0036.dss Content-Disposition: attachment ; filename=a0036.dss Content-Transfer-Encoding: base64 BGRzcwEAAQABAAAAYQAAAAAAAAAAAAAAAAAAACQAAAD+//7/+/8wNzA2MTYwODE1MjQwNzA2 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZ} # ------------------------------------------------------------------------- |
︙ | ︙ | |||
777 778 779 780 781 782 783 | Content-Transfer-Encoding: base64 T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt b3RlLU1UQTogNTMuMjQuMjgyLjE1MA== }] set parts [mime::property $token parts] | | | | 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | Content-Transfer-Encoding: base64 T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt b3RlLU1UQTogNTMuMjQuMjgyLjE1MA== }] set parts [mime::property $token parts] set result [mime::header get [lindex $parts end] Remote-MTA] return $result }} {53.24.282.150 {}} # ------------------------------------------------------------------------- test mime-13.0 {cleanly { issue a16b1095974e071d }} { |
︙ | ︙ | |||
894 895 896 897 898 899 900 901 902 903 904 905 906 907 | dawg one" \ [list Content-ID {<> {}} Content-Type {text/plain {}} \ Content-Disposition [list attachment [list param1 $char]]] ] test mime-13.1 {header parsing} {cleanly { set mime [mime::initialize -string {Content-Type: text/html}] mime::header get $mime Content-Type }} {text/html {}} | > | 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | dawg one" \ [list Content-ID {<> {}} Content-Type {text/plain {}} \ Content-Disposition [list attachment [list param1 $char]]] ] # ------------------------------------------------------------------------- test mime-13.1 {header parsing} {cleanly { set mime [mime::initialize -string {Content-Type: text/html}] mime::header get $mime Content-Type }} {text/html {}} |
︙ | ︙ |
Changes to modules/ncgi/ncgi.man.
︙ | ︙ | |||
20 21 22 23 24 25 26 | [package ncgi] package to query these values, set and get cookies, and encode and decode www-url-encoded values. [para] In the simplest case, a CGI script first calls [cmd ::ncgi::parse] and then calls [cmd ::ncgi::value] to get different form values. If a CGI | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | [package ncgi] package to query these values, set and get cookies, and encode and decode www-url-encoded values. [para] In the simplest case, a CGI script first calls [cmd ::ncgi::parse] and then calls [cmd ::ncgi::value] to get different form values. If a CGI value is repeated, you should use [cmd ::ncgi::all] to get back the complete list of values. [para] An alternative to [cmd ::ncgi::parse] is [cmd ::ncgi::input], which has semantics similar to Don Libes' [cmd cgi_input] procedure. |
︙ | ︙ | |||
77 78 79 80 81 82 83 | [call [cmd ::ncgi::header] [opt [arg type]] [arg args]] Output the CGI header to standard output. This emits a Content-Type: header and additional headers based on [arg args], which is a list of header names and header values. The [arg type] defaults to "text/html". | < < < < < < < < < < < | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | [call [cmd ::ncgi::header] [opt [arg type]] [arg args]] Output the CGI header to standard output. This emits a Content-Type: header and additional headers based on [arg args], which is a list of header names and header values. The [arg type] defaults to "text/html". [call [cmd ::ncgi::importFile] [arg cmd] [arg cginame] [opt [arg filename]]] This provides information about an uploaded file from a form input field of type [const file] with name [arg cginame]. [arg cmd] can be one of [option -server] [option -client], [option -type] or [option -data]. |
︙ | ︙ | |||
118 119 120 121 122 123 124 | writes the file contents to a local temporary file (or [arg filename] if supplied) and returns the name of the file. The caller is responsible for deleting this file after use. [list_end] | > > > > > > > > > > | > | | > | > | > > > > > > > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | < < < < | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | writes the file contents to a local temporary file (or [arg filename] if supplied) and returns the name of the file. The caller is responsible for deleting this file after use. [list_end] [call [cmd ::ncgi::all] [arg key] [opt [arg default]]] Like [cmd ::ncgi::value], but this always returns a list of values (even if there is only one value). In the case of multipart/form-data, this procedure returns a list of two elements. The first element is meta-data in the form of a parameter, value list. The second element is the form value. [call [cmd ::ncgi::body]] Returns the raw body. [call [cmd ::ncgi::form]] Returns the parsed form data as a multidict. [call [cmd ::ncgi::get] [arg key] [opt [arg default]]] Given [arg key], returns the value corresponding argument. If there is no such key , the [arg default] value, which by default is the empty string, is returned instead. [call [cmd ::ncgi::multipart] [arg {type query}]] This procedure parses a multipart/form-data [arg query]. This is used by [cmd ::ncgi::nvlist] and not normally called directly. It returns an alternating list of names and structured values. Each structure value is in turn a list of two elements. The first element is meta-data from the multipart/form-data structure. The second element is the form value. If you use [cmd ::ncgi::value] you just get the form value. If you use [cmd ::ncgi::all] you get the structured value with meta data and the value. [para] The [arg type] is the whole Content-Type, including the parameters like [arg boundary]. This returns a list of names and values that describe the multipart data. The values are a nested list structure that has some descriptive information first, and the actual form value second. The descriptive information is list of header names and values that describe the content. [call [cmd ::ncgi::query] [cmd parse]] Returns the parsed query data as a multidict. [call [cmd ::ncgi::query] [cmd set] [arg {key value}]] Set a query value. [call [cmd ::ncgi::query] [cmd string]] Returns the raw query data. [call [cmd ::ncgi::redirect] [arg url]] Generate a response that causes a 302 redirect by the Web server. The |
︙ | ︙ | |||
231 232 233 234 235 236 237 | [def "[option -name] [arg name]"] [def "[option -value] [arg value]"] [def "[option -expires] [arg date]"] [def "[option -path] [arg {path restriction}]"] [def "[option -domain] [arg {domain restriction}]"] [list_end] | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | [def "[option -name] [arg name]"] [def "[option -value] [arg value]"] [def "[option -expires] [arg date]"] [def "[option -path] [arg {path restriction}]"] [def "[option -domain] [arg {domain restriction}]"] [list_end] [call [cmd ::ncgi::type]] Returns the Content-Type of the current CGI values. [call [cmd ::ncgi::urlStub] [opt [arg url]]] Returns the current URL, but without the protocol, server, and port. If [arg url] is specified, then it defines the URL for the current session. That value will be returned by future calls to [cmd ::ncgi::urlStub] [list_end] [section EXAMPLES] Uploading a file [example { HTML: |
︙ | ︙ |
Changes to modules/ncgi/ncgi.tcl.
︙ | ︙ | |||
14 15 16 17 18 19 20 | # Please note that Don Libes' has a "cgi.tcl" that implements version 1.0 # of the cgi package. That implementation provides a bunch of cgi_ procedures # (it doesn't use the ::cgi:: namespace) and has a wealth of procedures for # generating HTML. In contrast, the package provided here is primarly # concerned with processing input to CGI programs. I have tried to mirror his # API's where possible. So, ncgi::input is equivalent to cgi_input, and so # on. There are also some different APIs for accessing values (ncgi::list, | | > < < < > > > > < < < < < < < < < < < | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # Please note that Don Libes' has a "cgi.tcl" that implements version 1.0 # of the cgi package. That implementation provides a bunch of cgi_ procedures # (it doesn't use the ::cgi:: namespace) and has a wealth of procedures for # generating HTML. In contrast, the package provided here is primarly # concerned with processing input to CGI programs. I have tried to mirror his # API's where possible. So, ncgi::input is equivalent to cgi_input, and so # on. There are also some different APIs for accessing values (ncgi::list, # and ncgi::get come to mind) # Note, I use the term "query data" to refer to the data that is passed in # to a CGI program. Typically this comes from a Form in an HTML browser. # The query data is composed of names and values, and the names can be # repeated. The names and values are encoded, and this module takes care # of decoding them. # We use newer string routines package require Tcl 8.4 package require fileutil ; # Required by importFile. package require mime package require uri package provide ncgi 1.5.0 namespace eval ::ncgi { # "query" holds the raw query (i.e., form) data # This is treated as a cache, too, so you can call ncgi::query more than # once variable query if {[info exists env(CONTENT_LENGTH)] && [ string length $env(CONTENT_LENGTH)] != 0} { variable content_length [expr {$env(CONTENT_LENGTH)}] } # This is the content-type which affects how the query is parsed variable contenttype if {[info exists ::env(REQUEST_METHOD)]} { variable method [string tolower $::env(REQUEST_METHOD)] } # This holds the URL coresponding to the current request # This does not include the server name. variable urlStub # This flags compatibility with Don Libes cgi.tcl when dealing with # form values that appear more than once. This bit gets flipped when |
︙ | ︙ | |||
103 104 105 106 107 108 109 | variable _tmpfiles array set _tmpfiles {} # I don't like importing, but this makes everything show up in # pkgIndex.tcl | | | | | | > > > > | | > > | > > | > | < < < < | > > > > > > > > > > | > | > > > > > > | | < > > > > > > > | | | > > > > | | | | | | > | < | < < < | < < < > > > < | | < < | < < < < < < < < < | > | > > > | | < < | < < < < | < | | < < < < < < < < | < < < < < < < < | | < < > > | < > > > > < > | < | < | > | < < | | < < < | | > > > > | > > > | < < < < < < < < < | < | < | < | < | < | < < > | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | variable _tmpfiles array set _tmpfiles {} # I don't like importing, but this makes everything show up in # pkgIndex.tcl namespace export all body get merge method reset urlStub query type decode encode namespace export input namespace export setDefaultValue setDefaultValueList namespace export empty import importAll importFile redirect header namespace export multipart cookie setCookie namespace ensemble create namespace ensemble create -command [namespace current]::form -map { exists form_exists get form_get } namespace ensemble create -command [namespace current]::query -map { parse query_parse set query_set string query_string } } # ::ncgi::all # # Return all the values of a named query element as a list, or # the empty list if it was not not specified. This always returns # lists - if you do not want the extra level of listification, use # ncgi::get instead. # # Arguments: # key The name of the query element # # Results: # The first value of the named element, or "" proc ::ncgi::all key { variable query variable form query parse if {[form exists]} { form get } set result {} foreach {qkey val} $query { if {$qkey eq $key} { lappend result $val } } if {[form exists]} { foreach {fkey val} $form { if {$fkey eq $key} { lappend result [lindex $val 0] } } } return $result } proc ::ncgi::body {} { global env variable content_length variable method variable body if {![info exists body]} { if {([info exists method] && $method eq {post}) && [info exist content_length] } { chan configure stdin -translation binary set body [read stdin $env(CONTENT_LENGTH)] } else { set body {} } } chan configure stdout -translation binary return $body } # ::ncgi::cookie # # Return a *list* of cookie values, if present, else "" # It is possible for multiple cookies with the same key # to be present, so we return a list. # # Arguments: # cookie The name of the cookie (the key) # # Results: # A list of values for the cookie proc ::ncgi::cookie cookie { global env set result {} if {[info exists env(HTTP_COOKIE)]} { foreach pair [split $env(HTTP_COOKIE) \;] { foreach {key value} [split [string trim $pair] =] { break ;# lassign } if {[string compare $cookie $key] == 0} { lappend result $value } } } return $result } # ::ncgi::setCookie # # Set a return cookie. You must call this before you call # ncgi::header or ncgi::redirect # # Arguments: # args Name value pairs, where the names are: # -name Cookie name # -value Cookie value # -path Path restriction # -domain domain restriction # -expires Time restriction # # Side Effects: # Formats and stores the Set-Cookie header for the reply. proc ::ncgi::setCookie {args} { variable cookieOutput array set opt $args set line "$opt(-name)=$opt(-value) ;" foreach extra {path domain} { if {[info exists opt(-$extra)]} { append line " $extra=$opt(-$extra) ;" } } if {[info exists opt(-expires)]} { switch -glob -- $opt(-expires) { *GMT { set expires $opt(-expires) } default { set expires [clock format [clock scan $opt(-expires)] \ -format "%A, %d-%b-%Y %H:%M:%S GMT" -gmt 1] } } append line " expires=$expires ;" } if {[info exists opt(-secure)]} { append line " secure " } lappend cookieOutput $line } # ::ncgi::decode # # This decodes data in www-url-encoded format. # # Arguments: |
︙ | ︙ | |||
301 302 303 304 305 306 307 308 309 310 311 312 313 314 | regsub -all -- {%([CDcd][A-Fa-f0-9])%([89ABab][A-Fa-f0-9])} \ $str {[encoding convertfrom utf-8 [DecodeHex \1\2]]} str regsub -all -- {%([0-7][A-Fa-f0-9])} $str {\\u00\1} str # process \u unicode mapped chars return [subst -novar $str] } # ::ncgi::encode # # This encodes data in www-url-encoded format. # # Arguments: # A string | > | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | regsub -all -- {%([CDcd][A-Fa-f0-9])%([89ABab][A-Fa-f0-9])} \ $str {[encoding convertfrom utf-8 [DecodeHex \1\2]]} str regsub -all -- {%([0-7][A-Fa-f0-9])} $str {\\u00\1} str # process \u unicode mapped chars return [subst -novar $str] } # ::ncgi::encode # # This encodes data in www-url-encoded format. # # Arguments: # A string |
︙ | ︙ | |||
326 327 328 329 330 331 332 | regsub -all -- \[^a-zA-Z0-9\] $string {$map(&)} string # This quotes cases like $map([) or $map($) => $map(\[) ... regsub -all -- {[][{})\\]\)} $string {\\&} string return [subst -nocommand $string] } | < | > > > > > > > > > > | < > > > > > > | < < > > > > > > > > > | > > | > > > | | > | > > > > > > > | > > > > | | > > > > > > > | | > > | > | > > > > > > > | > > > > > > > > | > > > | | | | < | > > > > > | > > > > > > > > > > > > > > | > > > > > > > > > < > > > > > > | > | > | > | | > > > > > > > | > > > | > > > > | | > > > > > > > > > | > > > > > > > | < | > > | < | > > > > > > > > | < < | | < < < > > > > > > | < < < < > | | > | > | > > > > | | | | | < | > | < < < | > | | < > > | < < < | < > < < | > | > | > | > | > > > > > | < < | < < < < < < < | > | > | | | | < | | < < < < < < < | < < < < | < < | < < < < < | | > > > | | < | > > | | | < < | | < < < < < < < | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < | < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < | < < | < < | < | < < < < < < < < < | < < < | < < < < < < < < < < | < < < < < | < < < < < < < < < < < < < < < < < < < < < < | 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | regsub -all -- \[^a-zA-Z0-9\] $string {$map(&)} string # This quotes cases like $map([) or $map($) => $map(\[) ... regsub -all -- {[][{})\\]\)} $string {\\&} string return [subst -nocommand $string] } proc ::ncgi::form_get args { set type [type] variable form if {![info exists form]} { set form {} switch -glob $type { {} - text/xml* - application/x-www-form-urlencoded* - application/x-www-urlencoded* { foreach {key val} [urlquery [body]] { lappend form $key [list $val {}] } } multipart/* { set form [multipart $type [body]] } default { return -code error "Unknown Content-Type: $type" } } } if {[llength $args] == 1} { lindex [dict get $form {*}$args] 0 } elseif {[llength $args] == 2} { set args [lassign $args[set args {}] key] lassign [dict get $form $key] value params dict get $params {*}$args } elseif {[llength $args]} { error [list wrong # args] } else { return $form } } proc ::ncgi::form_exists {} { variable content_length if {[info exists content_length]} { switch -glob [type] { {} - text/xml* - application/x-www-form-urlencoded* - application/x-www-urlencoded* - multipart/* { return 1 } } } return 0 } # ::ncgi::get # # Return the value of a named query element, or the empty string if # it was not not specified. This only returns the first value of # associated with the name. If you want them all (like all values # of a checkbox), use ncgi::all # # Arguments: # key The name of the query element # default The value to return if the value is not present # # Results: # The first value of the named element, or the default proc ::ncgi::get args { variable form variable query query parse if {[form exists]} { form get } if {![llength $args]} { return [merge] } elseif {[llength $args] <= 2} { lassign $args key default if {[form exists] && [dict exists $form $key]} { return [lindex [dict get $form $key] 0] } elseif {[dict exists $query $key]} { return [dict get $query $key] } else { return $default } } else { error [list {wrong # args}] } } # ncgi:header # # Output the Content-Type header. # # Arguments: # type The MIME content type # args Additional name, value pairs to specifiy output headers # # Side Effects: # Outputs a normal header proc ::ncgi::header {{type text/html} args} { variable cookieOutput puts "Content-Type: $type" foreach {n v} $args { puts "$n: $v" } if {[info exists cookieOutput]} { foreach line $cookieOutput { puts "Set-Cookie: $line" } } puts "" flush stdout } # ::ncgi::importFile -- # # get information about a file upload field # # Arguments: # cmd one of '-server' '-client' '-type' '-data' # var cgi variable name for the file field # filename filename to write to for -server # Results: # -server returns the name of the file on the server: side effect # is that the file gets stored on the server and the # script is responsible for deleting/moving the file # -client returns the name of the file sent from the client # -type returns the mime type of the file # -data returns the contents of the file proc ::ncgi::importFile {cmd var {filename {}}} { if {[form exists]} { set form [form get] } lassign [dict get $form $var] content params switch -exact -- $cmd { -server { ## take care not to write it out more than once variable _tmpfiles if {![info exists _tmpfiles($var)]} { if {$filename eq {}} { ## create a tmp file set _tmpfiles($var) [::fileutil::tempfile ncgi] } else { ## use supplied filename set _tmpfiles($var) $filename } # write out the data only if it's not been done already if {[catch {open $_tmpfiles($var) w} h]} { error "Can't open temporary file in ncgi::importFile ($h)" } fconfigure $h -translation binary -encoding binary puts -nonewline $h $content close $h } return $_tmpfiles($var) } -client { if {[dict exists $params filename]} { return [dict get $params filename] } return {} } -type { if {![info exists fileinfo(content-type)]} {return {}} return $fileinfo(content-type) } -data { return $contents } default { error "Unknown subcommand to ncgi::import_file: $cmd" } } } proc ::ncgi::merge {} { variable form variable query query parse if {[form exists]} { list {*}$query {*}[join [lmap {fkey val} $form { list $fkey [lindex $val 0] }]] } else { return $query } } # ::ncgi::multipart # # Parses $data into a multidict using the boundary provided in $type, # which is a complete Content-type value. Each value in the resulting # multi dict is a list where the first item is the value and the the # second item is a multidict where each key is the name of a header and # each value is a list containing the header value and a dictionary of # parameters for that header. proc ::ncgi::multipart {type data} { set token [mime::initialize -string "Content-Type: $type\n\n$data"] set parts [mime::property $token parts] set results [list] foreach part $parts { set header [::mime::header get $part] set value [::mime::body $part -decode] lassign [::mime::header get $part content-disposition] hvalue params if {$hvalue eq {form-data} && [dict exists $params name]} { set name [dict get $params name] } else { set name {} } lappend results $name [list $value $header] } return $results } # ::ncgi::parseMimeValue # # Parse a MIME header value, which has the form # value; param=value; param2="value2"; param3='value3' # # Arguments: # value The mime header value. This does not include the mime # header field name, but everything after it. # # Results: # A two-element list, the first is the primary value, # the second is in turn a name-value list corresponding to the # parameters. Given the above example, the return value is # { # value # {param value param2 value2 param3 value3} # } proc ::ncgi::parseMimeValue {value} { set parts [split $value \;] set results [list [string trim [lindex $parts 0]]] set paramList [list] foreach sub [lrange $parts 1 end] { if {[regexp -- {([^=]+)=(.+)} $sub match key val]} { set key [string trim [string tolower $key]] set val [string trim $val] # Allow single as well as double quotes if {[regexp -- {^(['"])(.*)\1} $val x quote val2]} { ; # need a " for balance # Trim quotes and any extra crap after close quote # remove quoted quotation marks set val [string map {\\" "\"" \\' "\'"} $val2] } lappend paramList $key $val } } if {[llength $paramList]} { lappend results $paramList } return $results } # ::ncgi::query parse # # Parses the query part of the URI # proc ::ncgi::query_parse {} { variable query if {![info exists query]} { set query [urlquery [query_string]] } return $query } # ::ncgi::query_set # # set the value of $key in the query dictionary to $value # proc ::ncgi::query_set {key value} { variable query query parse set idx [lindex [lmap idx [lsearch -exact -all $key $query] { if {[$idx % 2]} continue set idx }] end] if {$idx >= 0} { set query [lreplace $query[set query {}] $idx $idx $value] } else { lappend query $key $value } return $value } # ::ncgi::query_string # # This reads the query data from the appropriate location, which depends # on if it is a POST or GET request. # # Arguments: # none # # Results: # The raw query data. proc ::ncgi::query_string {} { global env variable querystring if {[info exists querystring]} { # This ensures you can call ncgi::query more than once, # and that you can use it with ncgi::reset return $querystring } set querystring {} if {[info exists env(QUERY_STRING)]} { set querystring $env(QUERY_STRING) } return $querystring } # ::ncgi::redirect # # Generate a redirect by returning a header that has a Location: field. # If the URL is not absolute, this automatically qualifies it to # the current server # |
︙ | ︙ | |||
843 844 845 846 847 848 849 | set url $proto://$server$port$dirname$url } } ncgi::header text/html Location $url puts "Please go to <a href=\"$url\">$url</a>" } | > | > > > | > | < < | < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < | | < | < < < < | < < | | < > > > | | > > | > | < < < < | < < < < < < < < < | < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < | < < < < < | < < | | < < < | < < < < < < | < | < < < < | < | | < < < > | < < | > > | | | > | | | | > | < | < < < | > | | < | < > > > | | | < < < < < < < < | < < | < < < < < | < > | < > | < < | | < < < | | | > | < > > > > < < < < < < < < < < < < | < > > > > > > | | < | < < < > | > | | | < < < | < < < < | < < < < < < | < < | > > > > | < < > > | | | < | < | > > | < | < < < < < < < | < | < < < < < < < < < < < | < < < < < < < < < < < > > < > | | > | > | < | | < < < > | < < | > | | < < | | < | < < | < < > | 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | set url $proto://$server$port$dirname$url } } ncgi::header text/html Location $url puts "Please go to <a href=\"$url\">$url</a>" } # ::ncgi::reset # # This resets the state of the CGI input processor. This is primarily # used for tests, although it is also designed so that TclHttpd can # call this with the current query data # so the ncgi package can be shared among TclHttpd and CGI scripts. # # Arguments: # newquery The query data to be used instead of external CGI. # newtype The raw content type. # # Side Effects: # Resets the cached query data and wipes any environment variables # associated with CGI inputs (like QUERY_STRING) proc ::ncgi::reset args { global env variable _tmpfiles variable body variable query variable querystring variable contenttype variable content_length variable cookieOutput variable form # array unset _tmpfiles -- Not a Tcl 8.2 idiom unset _tmpfiles ; array set _tmpfiles {} set cookieOutput {} if {[llength $args] == 0} { # We use and test args here so we can detect the # difference between empty query data and a full reset. foreach name {body contenttype form query querystring} { if {[info exists $name]} { unset $name } } } else { set contenttype {} if {[info exists body]} { unset body unset content_length } catch {unset form} catch {unset query} dict for {opt val} $args { switch $opt { body { set $opt $val set content_length [string length $body] } contenttype - form - querystring { set $opt $val } default { error [list {unknown reset option} $opt] } } } } } # ::ncgi::type # # This returns the content type of the query data. # # Arguments: # none # # Results: # The content type of the query data. proc ::ncgi::type {} { global env variable contenttype if {![info exists contenttype]} { if {[info exists env(CONTENT_TYPE)]} { set contenttype $env(CONTENT_TYPE) } else { return "" } } return $contenttype } # ::ncgi::parsequery # # Parses $data as a url-encoded query and returns a multidict containing # the query. # proc ::ncgi::urlquery data { set result {} # Any whitespace at the beginning or end of urlquery data is not # considered to be part of that data, so we trim it off. One special # case in which post data is preceded by a \n occurs when posting # with HTTPS in Netscape. foreach x [split [string trim $data] &] { # Turns out you might not get an = sign, # especially with <isindex> forms. set pos [string first = $x] set len [string length $x] if {$pos>=0} { if {$pos == 0} { # if the = is at the beginning ... if {$len>1} { # ... and there is something to the right ... set varname [string range $x 1 end] set val {} } else { # ... otherwise, all we have is an = set varname {} set val {} } } elseif {$pos==[expr {$len-1}]} { # if the = is at the end ... set varname [string range $x 0 [expr {$pos-1}]] set val "" } else { set varname [string range $x 0 [expr {$pos-1}]] set val [string range $x [expr {$pos+1}] end] } } else { # no = was found ... set varname $x set val {} } lappend result [decode $varname] [decode $val] } return $result } # ::ncgi::urlStub # # Set or return the URL associated with the current page. # This is for use by TclHttpd to override the default value # that otherwise comes from the CGI environment # # Arguments: # url (option) The url of the page, not counting the server name. # If not specified, the current urlStub is returned # # Side Effects: # May affects future calls to ncgi::urlStub # proc ::ncgi::urlStub {{url {}}} { global env variable urlStub if {[string length $url]} { set urlStub $url return "" } elseif {[info exists urlStub]} { return $urlStub } elseif {[info exists env(SCRIPT_NAME)]} { set urlStub $env(SCRIPT_NAME) return $urlStub } else { return "" } } namespace eval ::ncgi reset |
Changes to modules/ncgi/ncgi.test.
︙ | ︙ | |||
18 19 20 21 22 23 24 | testsNeedTcl 8.4 testsNeedTcltest 2 testing { useLocal ncgi.tcl ncgi } | | > > | | | | | < | | | | > | | | | > | | | | > | | | | | > | | | | | | | > | | | | | | | > | | | | | | | | | | | | < | | | | | | | | | > | | | | | > | | | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | > | | | | < < < < | | | | < < < < < < < < < < < < < | > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > | > | | | | | > | | | < | > | | | | < < < < < | < < < < < < | < < < < | < < < | | < < < < < | | < < | | | < | | | | | < | | | > | | | | > | | | > | | | | | < < | | | < | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | | | | > | | | | | | | | | | | | | | | > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | | | | > | | | < < < | < < < < < < < < < | < < < < < < < < < < | | < | | | | | < | | | | | | | | | | > > | < | | < < | | | | | < < < < < < < < | < < < < | < | | < < < > | < | < | < | | > < < < < < < < < < < < < < < < < < | < | < | < | < < | < | > | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | > | | | | > | | | | | > | | | | | | | > > > > > > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | testsNeedTcl 8.4 testsNeedTcltest 2 testing { useLocal ncgi.tcl ncgi } proc main {} { global env global auto_path set sub_ap $auto_path lappend sub_ap $::tcltest::testsDirectory set ncgiFile [localPath ncgi.tcl] set futlFile [tcllibPath fileutil/fileutil.tcl] set cmdlFile [tcllibPath cmdline/cmdline.tcl] test ncgi-1.1 {[ncgi reset]} { ncgi::reset list [info exist ncgi::query] [info exist ncgi::contenttype] } {0 0} test ncgi-1.2 {[ncgi reset]} { ncgi reset querystring query=reset list $ncgi::querystring $ncgi::contenttype } {query=reset {}} test ncgi-1.3 {[ncgi reset]} { ncgi reset querystring query=reset contenttype text/plain list $ncgi::querystring $ncgi::contenttype } {query=reset text/plain} test ncgi-2.1 {[ncgi query] fake query data} { ncgi reset querystring fake=query ncgi query parse list $ncgi::querystring $ncgi::query } {fake=query {fake query}} test ncgi-2.2 {[ncgi query] GET} { ncgi reset set env(REQUEST_METHOD) GET set env(QUERY_STRING) name=value ncgi query parse list $ncgi::querystring $ncgi::query } {name=value {name value}} test ncgi-2.3 {[ncgi query] HEAD} { ncgi reset set env(REQUEST_METHOD) HEAD catch {unset env(QUERY_STRING)} ncgi query parse set ncgi::query } {} test ncgi-2.4 {[ncgi query] POST} { ncgi reset catch {unset env(QUERY_STRING)} set env(REQUEST_METHOD) POST set env(CONTENT_LENGTH) 10 makeFile [format { set auto_path {%s} source {%s} source {%s} source {%s} ncgi body puts $::ncgi::body } $sub_ap $cmdlFile $futlFile $ncgiFile] test1 ; # {} set f [open "|[list $::tcltest::tcltest test1]" r+] puts $f "name=value" flush $f gets $f line close $f removeFile test1 set line } name=value test ncgi-2.5 {ncgi::test} { ncgi reset set env(CONTENT_TYPE) text/html ncgi type } text/html test ncgi-2.6 {ncgi::test} { ncgi reset querystring foo=bar contenttype text/plain set env(CONTENT_TYPE) text/html ncgi type } text/plain test ncgi-3.1 {ncgi::decode} { ncgi decode abcdef0123 } abcdef0123 test ncgi-3.2 {ncgi::decode} { ncgi decode {[abc]def$0123\x} } {[abc]def$0123\x} test ncgi-3.3 {ncgi::decode} { ncgi decode {[a%25c]def$01%7E3\x%3D} } {[a%c]def$01~3\x=} test ncgi-3.4 {ncgi::decode} { ncgi decode {hello+world} } {hello world} test ncgi-3.5 {ncgi::decode} { ncgi decode {aik%C5%ABloa} } "aik\u016Bloa" ; # u+macron test ncgi-3.6 {ncgi::decode} { ncgi decode {paran%C3%A1} } "paran\u00E1" ; # a+acute test ncgi-3.7 {ncgi::decode, bug 3601995} { ncgi decode {%C4%85} } "\u0105" ; # a+ogonek test ncgi-3.8 {ncgi::decode, bug 3601995} { ncgi decode {%E2%80%A0} } "\u2020" ; # dagger test ncgi-3.9 {ncgi::decode, bug 3601995} { ncgi decode {%E2%A0%90} } "\u2810" ; # a braille pattern test ncgi-3.10 {ncgi::decode, bug 3601995} { ncgi decode {%E2%B1} } "%E2%B1" ; # missing byte trailing %A0, do not accept/decode, pass through. test ncgi-4.1 {ncgi::encode} { ncgi encode abcdef0123 } abcdef0123 test ncgi-4.2 {ncgi::encode} { ncgi encode "\[abc\]def\$0123\\x" } {%5Babc%5Ddef%240123%5Cx} test ncgi-4.3 {ncgi::encode} { ncgi encode {hello world} } {hello+world} test ncgi-4.4 {ncgi::encode} { ncgi encode "hello\nworld\r\tbar" } {hello%0D%0Aworld%0D%09bar} test ncgi-5.1 {ncgi::query parse} { ncgi reset querystring name=hello+world&name2=%7ewelch ncgi query parse } {name {hello world} name2 ~welch} test ncgi-5.2 {ncgi::merge} { ncgi reset querystring name=&name2 contenttype application/x-www-urlencoded ncgi merge } {name {} name2 {}} test ncgi-5.3 {ncgi::merge} { ncgi reset querystring name=&name2 contenttype application/x-www-form-urlencoded ncgi merge } {name {} name2 {}} test ncgi-5.4.1 {ncgi::merge} { ncgi reset querystring name=&name2 contenttype application/xyzzy set code [catch ncgi::merge err] list $code $err } {0 {name {} name2 {}}} test ncgi-5.4.2 {ncgi::merge} { ncgi reset body name=&name2 contenttype application/xyzzy set code [catch ncgi::merge err] list $code $err } {0 {name {} name2 {}}} test ncgi-5.4.3 {ncgi::merge} { ncgi reset body name=&name2 contenttype application/xyzzy set code [catch {ncgi::form get} err] list $code $err } {1 {Unknown Content-Type: application/xyzzy}} # multipart tests at the end because I'm too lazy to renumber the tests test ncgi-6.1 {ncgi::parse, anonymous values, redundant keys} { ncgi reset querystring name=&name2 ncgi query parse } {name {} name2 {}} test ncgi-7.1 {ncgi::get} { ncgi reset querystring name=value&name2=value2 catch {unset env(REQUEST_METHOD)} ncgi get } {name value name2 value2} test ncgi-7.2 {ncgi::get} { ncgi reset querystring nameList=value1+stuff&nameList=value2+more ncgi all nameList } {{value1 stuff} {value2 more}} test ncgi-7.3 {ncgi::get} { ncgi reset querystring name=value&name=value2 catch {ncgi get} err set err } {name value name value2} test ncgi-8.1.1 {ncgi::value} { ncgi reset querystring nameList=val+ue&nameList=value2 ncgi get nameList } value2 test ncgi-8.1.2 {ncgi::value} { ncgi reset querystring nameList=val+ue&nameList=value2 ncgi all nameList } {{val ue} value2} test ncgi-8.2.1 {ncgi::value} { ncgi reset querystring name=val+ue&name=value2 ncgi get name } value2 test ncgi-8.2.2 {ncgi::value} { ncgi reset querystring name=val+ue&name=value2 ncgi all name } {{val ue} value2} test ncgi-8.3 {ncgi::get default} { ncgi reset querystring name=val+ue&name=value2 ncgi get noname } {} test ncgi-9.1 {ncgi::valueList} { ncgi reset querystring name=val+ue&name=value2 ncgi all name } {{val ue} value2} test ncgi-9.2 {ncgi::valueList} { ncgi reset querystring name=val+ue&name=value2 ncgi all noname } {} set URL http://www.tcltk.com/index.html test ncgi-11.1 {ncgi::redirect} { set env(REQUEST_URI) http://www.scriptics.com/cgi-bin/test.cgi set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) www.scriptics.com set env(SERVER_PORT) 80 makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL\n\nPlease go to <a href=\"$URL\">$URL</a>\n" set URL /elsewhere/foo.html set URL2 http://www/elsewhere/foo.html test ncgi-11.2 {ncgi::redirect} { set env(REQUEST_URI) http://www/cgi-bin/test.cgi set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) www.scriptics.com set env(SERVER_PORT) 80 makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::setCookie -name CookieName -value 12345 ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL2\nSet-Cookie: CookieName=12345 ;\n\nPlease go to <a href=\"$URL2\">$URL2</a>\n" set URL foo.html set URL2 http://www.scriptics.com/cgi-bin/foo.html test ncgi-11.3 {ncgi::redirect} { set env(REQUEST_URI) http://www.scriptics.com/cgi-bin/test.cgi set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) www.scriptics.com set env(SERVER_PORT) 80 makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL2\n\nPlease go to <a href=\"$URL2\">$URL2</a>\n" set URL foo.html set URL2 http://www.scriptics.com/cgi-bin/foo.html test ncgi-11.4 {ncgi::redirect} { set env(REQUEST_URI) /cgi-bin/test.cgi set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) www.scriptics.com set env(SERVER_PORT) 80 makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL2\n\nPlease go to <a href=\"$URL2\">$URL2</a>\n" set URL foo.html set URL2 http://www.scriptics.com:8000/cgi-bin/foo.html test ncgi-11.5 {ncgi::redirect} { set env(REQUEST_URI) /cgi-bin/test.cgi set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) www.scriptics.com set env(SERVER_PORT) 8000 makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL2\n\nPlease go to <a href=\"$URL2\">$URL2</a>\n" set URL foo.html set URL2 https://www.scriptics.com/cgi-bin/foo.html test ncgi-11.6 {ncgi::redirect} { set env(REQUEST_URI) /cgi-bin/test.cgi set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) www.scriptics.com set env(SERVER_PORT) 443 set env(HTTPS) "on" makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL2\n\nPlease go to <a href=\"$URL2\">$URL2</a>\n" set URL login.tcl set URL2 https://foo.com/cgi-bin/login.tcl test ncgi-11.7 {ncgi::redirect} { set env(REQUEST_URI) https://foo.com/cgi-bin/view.tcl?path=/a/b/c set env(REQUEST_METHOD) GET set env(QUERY_STRING) {} set env(SERVER_NAME) foo.com set env(SERVER_PORT) 443 set env(HTTPS) "on" makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::redirect %s } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile $URL] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nLocation: $URL2\n\nPlease go to <a href=\"$URL2\">$URL2</a>\n" test ncgi-12.1 {ncgi::header} { makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::header } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\n\n" test ncgi-12.2 {ncgi::header} { makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::header text/plain } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/plain\n\n" test ncgi-12.3 {ncgi::header} { makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::header text/html X-Comment "This is a test" } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nX-Comment: This is a test\n\n" test ncgi-12.4 {ncgi::header} { makeFile [format { set auto_path {%s} if {[catch { source %s source %s source %s ncgi::setCookie -name Name -value {The+Value} ncgi::header } err]} { puts $err } exit } $sub_ap $cmdlFile $futlFile $ncgiFile] test1 set f [open "|[list $::tcltest::tcltest test1]" r+] set res [read $f] close $f removeFile test1 set res } "Content-Type: text/html\nSet-Cookie: Name=The+Value ;\n\n" test ncgi-14.1 {ncgi::multipart} { catch {ncgi::multipart "application/x-www-urlencoded" name=val+ue} err set err } {not a multipart message} test ncgi-14.2 {ncgi::multipart} { catch {ncgi::multipart "multipart/form-data" {}} err set err } {end-of-string encountered while parsing multipart/form-data} test ncgi-14.3 {ncgi::multipart} { set in [open [file join [file dirname [info script]] formdata.txt]] set X [read $in] close $in foreach line [split $X \n] { if {[string length $line] == 0} { break } if {[regexp {^Content-Type: (.*)$} $line x type]} { break } } regsub ".*?\n\n" $X {} X ncgi::multipart $type $X } [list \ field1 [list value [list \ Content-Disposition {form-data {name field1}} \ Content-Type {text/plain {charset us-ascii}} ]] \ field2 [list {another value} [list \ Content-Disposition {form-data {name field2}} ]] \ the_file_name [list { <center><h1> Netscape Address Book Sync for Palm Pilot User Guide </h1></center> } \ [list \ filename {C:Program FilesNetscapeCommunicatorProgramnareadme.htm} \ name the_file_name ]]] test ncgi-14.4 {ncgi::multipart} { set in [open [file join [file dirname [info script]] formdata.txt]] set X [read $in] close $in foreach line [split $X \n] { if {[string length $line] == 0} { break } if {[regexp {^Content-Type: (.*)$} $line x type]} { break } } regsub ".*?\n\n" $X {} X ncgi::reset body $X contenttype $type list [ncgi::get field1] [ncgi::get field2] [ncgi::get the_file_name] } {value {another value} { <center><h1> Netscape Address Book Sync for Palm Pilot User Guide </h1></center> }} variable binary_content "\r \r <center><h1>\r Netscape Address Book Sync for Palm Pilot\r User Guide\r </h1></center>\r \r " test ncgi-14.5 {ncgi::multipart--check binary file} { set X [genformdata $binary_content] ncgi::reset body $X contenttype [genformcontent_type] set content [ncgi::get the_file_name] list [ncgi::get field1] [ncgi::get field2] $content } [list value {another value} [string map [list \r {}] $binary_content]] test ncgi-14.6 {ncgi::multipart [query set]} { set in [open [file join [file dirname [info script]] formdata.txt]] set X [read $in] close $in foreach line [split $X \n] { if {[string length $line] == 0} { break } if {[regexp {^Content-Type: (.*)$} $line x type]} { break } } regsub ".*?\n\n" $X {} X ncgi reset body $X contenttype $type ncgi query set userval1 foo ncgi query set userval2 {a b} list [ncgi get field1] [ncgi get field2] [ncgi get userval1] [ncgi get userval2] [ncgi get the_file_name] } {value {another value} foo {a b} { <center><h1> Netscape Address Book Sync for Palm Pilot User Guide </h1></center> }} test ncgi-15.1.1 {ncgi query set} { ncgi reset querystring nameList=val+ue&nameList=value2 ncgi query set foo 1 ncgi query set bar {a b} list [ncgi get nameList] [ncgi get foo] [ncgi get bar] } {value2 1 {a b}} test ncgi-15.1.2 {ncgi query set} { ncgi reset querystring nameList=val+ue&nameList=value2 ncgi query set foo 1 ncgi query set bar {a b} list [ncgi all nameList] [ncgi get foo] [ncgi get bar] } {{{val ue} value2} 1 {a b}} ## ------------ tests for binary content and file upload ---------------- ## some utility procedures to generate content variable form_boundary {17661509020136} proc genformcontent_type {} { variable form_boundary return "multipart/form-data; boundary=\"$form_boundary\"" } proc genformdatapart {name cd value} { variable form_boundary return "--$form_boundary\nContent-Disposition: form-data; name=\"$name\"$cd\n\n$value\n" } proc genformdata {bcontent} { variable form_boundary set a [genformdatapart field1 "" {value}] set b [genformdatapart field2 "" {another value}] set c [genformdatapart the_file_name "; filename=\"C:\\Program Files\\Netscape\\Communicator\\Program\\nareadme.htm\"\nContent-Type: text/html" $bcontent] return "$a$b$c--$form_boundary--\n" } test ncgi-16.1 {ncgi::importFile} { set X [genformdata $binary_content] ncgi::reset body $X contenttype [genformcontent_type] ncgi::importFile -client the_file_name } {C:Program FilesNetscapeCommunicatorProgramnareadme.htm} test ncgi-16.2 {ncgi::importFile - content type} { global binary_content set X [genformdata $binary_content] ncgi::reset post $X contenttype [genformcontent_type] ncgi::importFile -type the_file_name } text/html test ncgi-16.3 {ncgi::importFile -- file contents} { global binary_content set X [genformdata $binary_content] ncgi::reset post $X contenttype [genformcontent_type] ncgi::importFile -data the_file_name } $binary_content test ncgi-16.4 {ncgi::importFile -- save file} { global binary_content set X [genformdata $binary_content] ncgi::reset post $X contenttype [genformcontent_type] ncgi::parse set localfile [ncgi::importFile -server the_file_name] # get the contents of the local file to verify set in [open $localfile] fconfigure $in -translation binary set content [read $in] close $in file delete $localfile set content } $binary_content test ncgi-16.5 {ncgi::importFile -- save file, given name} { global binary_content set X [genformdata $binary_content] ncgi::reset post $X contenttype [genformcontent_type] ncgi::parse set localfile [ncgi::importFile -server the_file_name fofo] # get the contents of the local file to verify set in [open $localfile] fconfigure $in -translation binary set content [read $in] close $in file delete $localfile set content } $binary_content test ncgi-16.6 {ncgi::importFile -- bad input} { set X "bad multipart data" ncgi::reset post $X contenttype [genformcontent_type] ncgi::parse ncgi::importFile -client the_file_name } {} test ncgi-17.1 {ncgi::names} { ncgi::reset querystring name=hello+world&name2=%7ewelch ncgi::names } {name name2} test ncgi-17.2 {ncgi::names} { ncgi::reset querystring name=&name2 contenttype application/x-www-urlencoded ncgi::names } {name} test ncgi-17.3 {ncgi::names} { ncgi::reset querystring name=&name2 \ contenttype application/x-www-form-urlencoded ncgi::names } {name} test ncgi-17.4 {ncgi::names} { ncgi::reset querystring name=&name2 contenttype application/xyzzy set code [catch ncgi::names err] list $code $err } {1 {Unknown Content-Type: application/xyzzy}} # ------------------------------------------------------------------------- testsuiteCleanup set [namespace current]::done 1 return } after 0 [list ::coroutine [info cmdcount]_main [namespace current]::main] vwait [namespace current]::done return |