1 # http11.test -- -*- tcl-*-
3 # Test HTTP/1.1 features.
5 # Copyright (C) 2009 Pat Thoyts <patthoyts@users.sourceforge.net>
7 # See the file "license.terms" for information on usage and redistribution
8 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 if {"::tcltest" ni [namespace children]} {
11 package require tcltest 2.5
12 namespace import -force ::tcltest::*
15 package require http 2.9
19 proc create_httpd {} {
20 proc httpd_read {chan} {
22 if {[gets $chan line] >= 0} {
23 #puts stderr "read '$line'"
24 set httpd_output $line
27 puts stderr "eof from httpd"
28 fileevent $chan readable {}
33 set httpd_script [file join [pwd] [file dirname [info script]] httpd11.tcl]
34 set httpd [open "|[list [interpreter] -encoding utf-8 $httpd_script]" r+]
35 fconfigure $httpd -buffering line -blocking 0
36 fileevent $httpd readable [list httpd_read $httpd]
38 variable httpd_port [lindex $httpd_output 2]
45 if {[info exists httpd]} {
50 unset -nocomplain httpd_output httpd
53 proc meta {tok {key ""}} {
54 set meta [http::meta $tok]
56 if {[dict exists $meta $key]} {
57 return [dict get $meta $key]
65 proc state {tok {key ""}} {
68 if {[array names state -exact $key] ne {}} {
74 set res [array get state]
75 dict set res body <elided>
79 proc check_crc {tok args} {
80 set crc [meta $tok x-crc32]
81 set data [expr {[llength $args] ? [lindex $args 0] : [http::data $tok]}]
82 set chk [format %x [zlib crc32 $data]]
84 return "crc32 mismatch: $crc ne $chk"
89 makeFile "<html><head><title>test</title></head><body><p>this is a test</p>\n[string repeat {<p>This is a tcl test file.</p>} 4192]\n</body></html>" testdoc.html
91 # -------------------------------------------------------------------------
93 test http11-1.0 "normal request for document " -setup {
94 variable httpd [create_httpd]
96 set tok [http::geturl http://localhost:$httpd_port/testdoc.html -timeout 10000]
98 list [http::status $tok] [http::code $tok] [check_crc $tok] [meta $tok connection]
102 } -result {ok {HTTP/1.1 200 OK} ok close}
104 test http11-1.1 "normal,gzip,non-chunked" -setup {
105 variable httpd [create_httpd]
107 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
108 -timeout 10000 -headers {accept-encoding gzip}]
110 list [http::status $tok] [http::code $tok] [check_crc $tok] \
111 [meta $tok content-encoding] [meta $tok transfer-encoding]
115 } -result {ok {HTTP/1.1 200 OK} ok gzip {}}
117 test http11-1.2 "normal,deflated,non-chunked" -setup {
118 variable httpd [create_httpd]
120 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
121 -timeout 10000 -headers {accept-encoding deflate}]
123 list [http::status $tok] [http::code $tok] [check_crc $tok] \
124 [meta $tok content-encoding] [meta $tok transfer-encoding]
128 } -result {ok {HTTP/1.1 200 OK} ok deflate {}}
130 test http11-1.3 "normal,compressed,non-chunked" -setup {
131 variable httpd [create_httpd]
133 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
134 -timeout 10000 -headers {accept-encoding compress}]
136 list [http::status $tok] [http::code $tok] [check_crc $tok] \
137 [meta $tok content-encoding] [meta $tok transfer-encoding]
141 } -result {ok {HTTP/1.1 200 OK} ok compress {}}
143 test http11-1.4 "normal,identity,non-chunked" -setup {
144 variable httpd [create_httpd]
146 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
147 -timeout 10000 -headers {accept-encoding identity}]
149 list [http::status $tok] [http::code $tok] [check_crc $tok] \
150 [meta $tok content-encoding] [meta $tok transfer-encoding]
154 } -result {ok {HTTP/1.1 200 OK} ok {} {}}
156 test http11-1.5 "normal request for document, unsupported coding" -setup {
157 variable httpd [create_httpd]
159 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
160 -timeout 10000 -headers {accept-encoding unsupported}]
162 list [http::status $tok] [http::code $tok] [check_crc $tok] \
163 [meta $tok content-encoding]
167 } -result {ok {HTTP/1.1 200 OK} ok {}}
169 test http11-1.6 "normal, specify 1.1 " -setup {
170 variable httpd [create_httpd]
172 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
173 -protocol 1.1 -timeout 10000]
175 list [http::status $tok] [http::code $tok] [check_crc $tok] \
176 [meta $tok connection] [meta $tok transfer-encoding]
180 } -result {ok {HTTP/1.1 200 OK} ok close chunked}
182 test http11-1.7 "normal, 1.1 and keepalive " -setup {
183 variable httpd [create_httpd]
185 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
186 -protocol 1.1 -keepalive 1 -timeout 10000]
188 list [http::status $tok] [http::code $tok] [check_crc $tok] \
189 [meta $tok connection] [meta $tok transfer-encoding]
193 } -result {ok {HTTP/1.1 200 OK} ok {} chunked}
195 test http11-1.8 "normal, 1.1 and keepalive, server close" -setup {
196 variable httpd [create_httpd]
198 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
199 -protocol 1.1 -keepalive 1 -timeout 10000]
201 list [http::status $tok] [http::code $tok] [check_crc $tok] \
202 [meta $tok connection] [meta $tok transfer-encoding]
206 } -result {ok {HTTP/1.1 200 OK} ok close {}}
208 test http11-1.9 "normal,gzip,chunked" -setup {
209 variable httpd [create_httpd]
211 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
212 -timeout 10000 -headers {accept-encoding gzip}]
214 list [http::status $tok] [http::code $tok] [check_crc $tok] \
215 [meta $tok content-encoding] [meta $tok transfer-encoding]
219 } -result {ok {HTTP/1.1 200 OK} ok gzip chunked}
221 test http11-1.10 "normal,deflate,chunked" -setup {
222 variable httpd [create_httpd]
224 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
225 -timeout 10000 -headers {accept-encoding deflate}]
227 list [http::status $tok] [http::code $tok] [check_crc $tok] \
228 [meta $tok content-encoding] [meta $tok transfer-encoding]
232 } -result {ok {HTTP/1.1 200 OK} ok deflate chunked}
234 test http11-1.11 "normal,compress,chunked" -setup {
235 variable httpd [create_httpd]
237 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
238 -timeout 10000 -headers {accept-encoding compress}]
240 list [http::status $tok] [http::code $tok] [check_crc $tok] \
241 [meta $tok content-encoding] [meta $tok transfer-encoding]
245 } -result {ok {HTTP/1.1 200 OK} ok compress chunked}
247 test http11-1.12 "normal,identity,chunked" -setup {
248 variable httpd [create_httpd]
250 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
251 -timeout 10000 -headers {accept-encoding identity}]
253 list [http::status $tok] [http::code $tok] [check_crc $tok] \
254 [meta $tok content-encoding] [meta $tok transfer-encoding]
258 } -result {ok {HTTP/1.1 200 OK} ok {} chunked}
260 test http11-1.13 "normal, 1.1 and keepalive as server default, no zip" -setup {
261 variable httpd [create_httpd]
262 set zipTmp [http::config -zip]
265 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?transfer= \
266 -protocol 1.1 -keepalive 1 -timeout 10000]
268 set res1 [list [http::status $tok] [http::code $tok] [check_crc $tok] \
269 [meta $tok connection] [meta $tok transfer-encoding] [state $tok reusing] [state $tok connection]]
270 set toj [http::geturl http://localhost:$httpd_port/testdoc.html?transfer= \
271 -protocol 1.1 -keepalive 1 -timeout 10000]
273 set res2 [list [http::status $toj] [http::code $toj] [check_crc $toj] \
274 [meta $toj connection] [meta $toj transfer-encoding] [state $toj reusing] [state $toj connection]]
275 concat $res1 -- $res2
280 http::config -zip $zipTmp
281 } -result {ok {HTTP/1.1 200 OK} ok {} {} 0 keep-alive -- ok {HTTP/1.1 200 OK} ok {} {} 1 keep-alive}
283 # -------------------------------------------------------------------------
285 proc progress {var token total current} {
287 set log [list $current $total]
291 proc progressPause {var token total current} {
293 set log [list $current $total]
294 after 100 set ::WaitHere 0
299 test http11-2.0 "-channel" -setup {
300 variable httpd [create_httpd]
301 set chan [open [makeFile {} testfile.tmp] wb+]
303 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
304 -timeout 5000 -channel $chan]
307 set data [read $chan]
308 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
309 [meta $tok connection] [meta $tok transfer-encoding]
313 removeFile testfile.tmp
315 } -result {ok {HTTP/1.1 200 OK} ok close chunked}
317 test http11-2.1 "-channel, encoding gzip" -setup {
318 variable httpd [create_httpd]
319 set chan [open [makeFile {} testfile.tmp] wb+]
321 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
322 -timeout 5000 -channel $chan -headers {accept-encoding gzip}]
325 set data [read $chan]
326 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
327 [meta $tok connection] [meta $tok content-encoding]\
328 [meta $tok transfer-encoding]
332 removeFile testfile.tmp
334 } -result {ok {HTTP/1.1 200 OK} ok close gzip chunked}
336 test http11-2.2 "-channel, encoding deflate" -setup {
337 variable httpd [create_httpd]
338 set chan [open [makeFile {} testfile.tmp] wb+]
340 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
341 -timeout 5000 -channel $chan -headers {accept-encoding deflate}]
344 set data [read $chan]
345 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
346 [meta $tok connection] [meta $tok content-encoding]\
347 [meta $tok transfer-encoding]
351 removeFile testfile.tmp
353 } -result {ok {HTTP/1.1 200 OK} ok close deflate chunked}
355 test http11-2.3 "-channel,encoding compress" -setup {
356 variable httpd [create_httpd]
357 set chan [open [makeFile {} testfile.tmp] wb+]
359 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
360 -timeout 5000 -channel $chan \
361 -headers {accept-encoding compress}]
364 set data [read $chan]
365 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
366 [meta $tok connection] [meta $tok content-encoding]\
367 [meta $tok transfer-encoding]
371 removeFile testfile.tmp
373 } -result {ok {HTTP/1.1 200 OK} ok close compress chunked}
375 test http11-2.4 "-channel,encoding identity" -setup {
376 variable httpd [create_httpd]
377 set chan [open [makeFile {} testfile.tmp] wb+]
379 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
380 -timeout 5000 -channel $chan \
381 -headers {accept-encoding identity}]
384 set data [read $chan]
385 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
386 [meta $tok connection] [meta $tok content-encoding]\
387 [meta $tok transfer-encoding]
391 removeFile testfile.tmp
393 } -result {ok {HTTP/1.1 200 OK} ok close {} chunked}
395 test http11-2.4.1 "-channel,encoding identity with -progress" -setup {
396 variable httpd [create_httpd]
397 set chan [open [makeFile {} testfile.tmp] wb+]
400 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
401 -timeout 5000 -channel $chan \
402 -headers {accept-encoding identity} \
403 -progress [namespace code [list progress logdata]]]
407 set data [read $chan]
408 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
409 [meta $tok connection] [meta $tok content-encoding]\
410 [meta $tok transfer-encoding] \
411 [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
412 [expr {[lindex $logdata 0] - [string length $data]}]
416 removeFile testfile.tmp
418 unset -nocomplain logdata data
419 } -result {ok {HTTP/1.1 200 OK} ok close {} chunked 0 0}
421 test http11-2.4.2 "-channel,encoding identity with -progress progressPause enters event loop" -constraints knownBug -setup {
422 variable httpd [create_httpd]
423 set chan [open [makeFile {} testfile.tmp] wb+]
426 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
427 -timeout 5000 -channel $chan \
428 -headers {accept-encoding identity} \
429 -progress [namespace code [list progressPause logdata]]]
433 set data [read $chan]
434 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
435 [meta $tok connection] [meta $tok content-encoding]\
436 [meta $tok transfer-encoding] \
437 [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
438 [expr {[lindex $logdata 0] - [string length $data]}]
442 removeFile testfile.tmp
444 unset -nocomplain logdata data ::WaitHere
445 } -result {ok {HTTP/1.1 200 OK} ok close {} chunked 0 0}
447 test http11-2.5 "-channel,encoding unsupported" -setup {
448 variable httpd [create_httpd]
449 set chan [open [makeFile {} testfile.tmp] wb+]
451 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
452 -timeout 5000 -channel $chan \
453 -headers {accept-encoding unsupported}]
456 set data [read $chan]
457 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
458 [meta $tok connection] [meta $tok content-encoding]\
459 [meta $tok transfer-encoding]
463 removeFile testfile.tmp
465 } -result {ok {HTTP/1.1 200 OK} ok close {} chunked}
467 test http11-2.6 "-channel,encoding gzip,non-chunked" -setup {
468 variable httpd [create_httpd]
469 set chan [open [makeFile {} testfile.tmp] wb+]
471 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
472 -timeout 5000 -channel $chan -headers {accept-encoding gzip}]
475 set data [read $chan]
476 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
477 [meta $tok connection] [meta $tok content-encoding]\
478 [meta $tok transfer-encoding]\
479 [expr {[file size testdoc.html]-[file size testfile.tmp]}]
483 removeFile testfile.tmp
485 } -result {ok {HTTP/1.1 200 OK} ok close gzip {} 0}
487 test http11-2.7 "-channel,encoding deflate,non-chunked" -setup {
488 variable httpd [create_httpd]
489 set chan [open [makeFile {} testfile.tmp] wb+]
491 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
492 -timeout 5000 -channel $chan -headers {accept-encoding deflate}]
495 set data [read $chan]
496 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
497 [meta $tok connection] [meta $tok content-encoding]\
498 [meta $tok transfer-encoding]\
499 [expr {[file size testdoc.html]-[file size testfile.tmp]}]
503 removeFile testfile.tmp
505 } -result {ok {HTTP/1.1 200 OK} ok close deflate {} 0}
507 test http11-2.8 "-channel,encoding compress,non-chunked" -setup {
508 variable httpd [create_httpd]
509 set chan [open [makeFile {} testfile.tmp] wb+]
511 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
512 -timeout 5000 -channel $chan -headers {accept-encoding compress}]
515 set data [read $chan]
516 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
517 [meta $tok connection] [meta $tok content-encoding]\
518 [meta $tok transfer-encoding]\
519 [expr {[file size testdoc.html]-[file size testfile.tmp]}]
523 removeFile testfile.tmp
525 } -result {ok {HTTP/1.1 200 OK} ok close compress {} 0}
527 test http11-2.9 "-channel,encoding identity,non-chunked" -setup {
528 variable httpd [create_httpd]
529 set chan [open [makeFile {} testfile.tmp] wb+]
531 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
532 -timeout 5000 -channel $chan -headers {accept-encoding identity}]
535 set data [read $chan]
536 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
537 [meta $tok connection] [meta $tok content-encoding]\
538 [meta $tok transfer-encoding]\
539 [expr {[file size testdoc.html]-[file size testfile.tmp]}]
543 removeFile testfile.tmp
545 } -result {ok {HTTP/1.1 200 OK} ok close {} {} 0}
547 test http11-2.10 "-channel,deflate,keepalive" -setup {
548 variable httpd [create_httpd]
549 set chan [open [makeFile {} testfile.tmp] wb+]
551 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
552 -timeout 5000 -channel $chan -keepalive 1 \
553 -headers {accept-encoding deflate}]
556 set data [read $chan]
557 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
558 [meta $tok connection] [meta $tok content-encoding]\
559 [meta $tok transfer-encoding]\
560 [expr {[file size testdoc.html]-[file size testfile.tmp]}]
564 removeFile testfile.tmp
566 } -result {ok {HTTP/1.1 200 OK} ok {} deflate chunked 0}
568 test http11-2.11 "-channel,identity,keepalive" -setup {
569 variable httpd [create_httpd]
570 set chan [open [makeFile {} testfile.tmp] wb+]
572 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
573 -headers {accept-encoding identity} \
574 -timeout 5000 -channel $chan -keepalive 1]
577 set data [read $chan]
578 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
579 [meta $tok connection] [meta $tok content-encoding]\
580 [meta $tok transfer-encoding]
584 removeFile testfile.tmp
586 } -result {ok {HTTP/1.1 200 OK} ok {} {} chunked}
588 test http11-2.12 "-channel,negotiate,keepalive" -setup {
589 variable httpd [create_httpd]
590 set chan [open [makeFile {} testfile.tmp] wb+]
592 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
593 -timeout 5000 -channel $chan -keepalive 1]
596 set data [read $chan]
597 list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
598 [meta $tok connection] [meta $tok content-encoding]\
599 [meta $tok transfer-encoding] [meta $tok x-requested-encodings]\
600 [expr {[file size testdoc.html]-[file size testfile.tmp]}]
604 removeFile testfile.tmp
606 } -result {ok {HTTP/1.1 200 OK} ok {} gzip chunked gzip,deflate,compress 0}
609 # -------------------------------------------------------------------------
611 # The following tests for the -handler option will require changes in
612 # the future. At the moment we cannot handler chunked data with this
613 # option. Therefore we currently force HTTP/1.0 protocol version.
615 # Once this is solved, these tests should be fixed to assume chunked
616 # returns in 3.2 and 3.3 and HTTP/1.1 in all but test 3.1
618 proc handler {var sock token} {
620 set chunk [read $sock]
622 #::http::Log "handler read [string length $chunk] ([chan configure $sock -buffersize])"
623 return [string length $chunk]
626 proc handlerPause {var sock token} {
628 set chunk [read $sock]
630 #::http::Log "handler read [string length $chunk] ([chan configure $sock -buffersize])"
631 after 100 set ::WaitHere 0
633 return [string length $chunk]
636 test http11-3.0 "-handler,close,identity" -setup {
637 variable httpd [create_httpd]
640 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
641 -timeout 10000 -handler [namespace code [list handler testdata]]]
643 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
644 [meta $tok connection] [meta $tok content-encoding] \
645 [meta $tok transfer-encoding] \
646 [expr {[file size testdoc.html]-[string length $testdata]}]
649 unset -nocomplain testdata
651 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0}
653 test http11-3.1 "-handler,protocol1.0" -setup {
654 variable httpd [create_httpd]
657 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
658 -timeout 10000 -protocol 1.0 \
659 -handler [namespace code [list handler testdata]]]
661 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
662 [meta $tok connection] [meta $tok content-encoding] \
663 [meta $tok transfer-encoding] \
664 [expr {[file size testdoc.html]-[string length $testdata]}]
667 unset -nocomplain testdata
669 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0}
671 test http11-3.2 "-handler,close,chunked" -setup {
672 variable httpd [create_httpd]
675 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
676 -timeout 10000 -keepalive 0 -binary 1\
677 -handler [namespace code [list handler testdata]]]
679 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
680 [meta $tok connection] [meta $tok content-encoding] \
681 [meta $tok transfer-encoding] \
682 [expr {[file size testdoc.html]-[string length $testdata]}]
685 unset -nocomplain testdata
687 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0}
689 test http11-3.3 "-handler,keepalive,chunked" -setup {
690 variable httpd [create_httpd]
693 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
694 -timeout 10000 -keepalive 1 -binary 1\
695 -handler [namespace code [list handler testdata]]]
697 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
698 [meta $tok connection] [meta $tok content-encoding] \
699 [meta $tok transfer-encoding] \
700 [expr {[file size testdoc.html]-[string length $testdata]}]
703 unset -nocomplain testdata
705 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0}
708 # This test is a blatant attempt to confuse the client by instructing the server
709 # to send neither "Connection: close" nor "Content-Length" when in non-chunked
711 # The client has no way to know the response-body is complete unless the
712 # server signals this by closing the connection.
713 # In an HTTP/1.1 response the absence of "Connection: close" means
714 # "Connection: keep-alive", i.e. the server will keep the connection
715 # open. In HTTP/1.0 this is not the case, and this is a test that
716 # the Tcl client assumes "Connection: close" by default in HTTP/1.0.
717 test http11-3.4 "-handler,close,identity; HTTP/1.0 server does not send Connection: close header or Content-Length" -setup {
718 variable httpd [create_httpd]
721 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1&nosendclose=any \
722 -timeout 10000 -handler [namespace code [list handler testdata]]]
724 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
725 [meta $tok connection] [meta $tok content-encoding] \
726 [meta $tok transfer-encoding] \
727 [expr {[file size testdoc.html]-[string length $testdata]}]
730 unset -nocomplain testdata
732 } -result {ok {HTTP/1.0 200 OK} ok {} {} {} 0}
734 # It is not forbidden for a handler to enter the event loop.
735 test http11-3.5 "-handler,close,identity as http11-3.0 but handlerPause enters event loop" -setup {
736 variable httpd [create_httpd]
739 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
740 -timeout 10000 -handler [namespace code [list handlerPause testdata]]]
742 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
743 [meta $tok connection] [meta $tok content-encoding] \
744 [meta $tok transfer-encoding] \
745 [expr {[file size testdoc.html]-[string length $testdata]}]
748 unset -nocomplain testdata ::WaitHere
750 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0}
752 test http11-3.6 "-handler,close,identity as http11-3.0 but with -progress" -setup {
753 variable httpd [create_httpd]
757 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
758 -timeout 10000 -handler [namespace code [list handler testdata]] \
759 -progress [namespace code [list progress logdata]]]
761 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
762 [meta $tok connection] [meta $tok content-encoding] \
763 [meta $tok transfer-encoding] \
764 [expr {[file size testdoc.html]-[string length $testdata]}] \
765 [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
766 [expr {[lindex $logdata 0] - [string length $testdata]}]
769 unset -nocomplain testdata logdata ::WaitHere
771 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0 0 0}
773 test http11-3.7 "-handler,close,identity as http11-3.0 but with -progress progressPause enters event loop" -setup {
774 variable httpd [create_httpd]
778 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
779 -timeout 10000 -handler [namespace code [list handler testdata]] \
780 -progress [namespace code [list progressPause logdata]]]
782 list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
783 [meta $tok connection] [meta $tok content-encoding] \
784 [meta $tok transfer-encoding] \
785 [expr {[file size testdoc.html]-[string length $testdata]}] \
786 [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
787 [expr {[lindex $logdata 0] - [string length $testdata]}]
790 unset -nocomplain testdata logdata ::WaitHere
792 } -result {ok {HTTP/1.0 200 OK} ok close {} {} 0 0 0}
794 test http11-3.8 "close,identity no -handler but with -progress" -setup {
795 variable httpd [create_httpd]
798 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
800 -progress [namespace code [list progress logdata]] \
801 -headers {accept-encoding {}}]
803 list [http::status $tok] [http::code $tok] [check_crc $tok]\
804 [meta $tok connection] [meta $tok content-encoding] \
805 [meta $tok transfer-encoding] \
806 [expr {[file size testdoc.html]-[string length [http::data $tok]]}] \
807 [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
808 [expr {[lindex $logdata 0] - [string length [http::data $tok]]}]
811 unset -nocomplain logdata ::WaitHere
813 } -result {ok {HTTP/1.1 200 OK} ok close {} {} 0 0 0}
815 test http11-3.9 "close,identity no -handler but with -progress progressPause enters event loop" -setup {
816 variable httpd [create_httpd]
819 set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
821 -progress [namespace code [list progressPause logdata]] \
822 -headers {accept-encoding {}}]
824 list [http::status $tok] [http::code $tok] [check_crc $tok]\
825 [meta $tok connection] [meta $tok content-encoding] \
826 [meta $tok transfer-encoding] \
827 [expr {[file size testdoc.html]-[string length [http::data $tok]]}] \
828 [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
829 [expr {[lindex $logdata 0] - [string length [http::data $tok]]}]
832 unset -nocomplain logdata ::WaitHere
834 } -result {ok {HTTP/1.1 200 OK} ok close {} {} 0 0 0}
836 test http11-4.0 "normal post request" -setup {
837 variable httpd [create_httpd]
839 set query [http::formatQuery q 1 z 2]
840 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
841 -query $query -timeout 10000]
843 list status [http::status $tok] code [http::code $tok]\
844 crc [check_crc $tok]\
845 connection [meta $tok connection]\
846 query-length [meta $tok x-query-length]
850 } -result {status ok code {HTTP/1.1 200 OK} crc ok connection close query-length 7}
852 test http11-4.1 "normal post request, check query length" -setup {
853 variable httpd [create_httpd]
855 set query [http::formatQuery q 1 z 2]
856 set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
857 -headers [list x-check-query yes] \
858 -query $query -timeout 10000]
860 list status [http::status $tok] code [http::code $tok]\
861 crc [check_crc $tok]\
862 connection [meta $tok connection]\
863 query-length [meta $tok x-query-length]
867 } -result {status ok code {HTTP/1.1 200 OK} crc ok connection close query-length 7}
869 test http11-4.2 "normal post request, check long query length" -setup {
870 variable httpd [create_httpd]
872 set query [string repeat a 24576]
873 set tok [http::geturl http://localhost:$httpd_port/testdoc.html\
874 -headers [list x-check-query yes]\
875 -query $query -timeout 10000]
877 list status [http::status $tok] code [http::code $tok]\
878 crc [check_crc $tok]\
879 connection [meta $tok connection]\
880 query-length [meta $tok x-query-length]
884 } -result {status ok code {HTTP/1.1 200 OK} crc ok connection close query-length 24576}
886 test http11-4.3 "normal post request, check channel query length" -setup {
887 variable httpd [create_httpd]
888 set chan [open [makeFile {} testfile.tmp] wb+]
889 puts -nonewline $chan [string repeat [encoding convertto utf-8 "This is a test\n"] 8192]
893 set tok [http::geturl http://localhost:$httpd_port/testdoc.html\
894 -headers [list x-check-query yes]\
895 -querychannel $chan -timeout 10000]
897 list status [http::status $tok] code [http::code $tok]\
898 crc [check_crc $tok]\
899 connection [meta $tok connection]\
900 query-length [meta $tok x-query-length]
904 removeFile testfile.tmp
906 } -result {status ok code {HTTP/1.1 200 OK} crc ok connection close query-length 122880}
908 # -------------------------------------------------------------------------
910 # Eliminate valgrind "still reachable" reports on outstanding "Detached"
911 # structures in the detached list which stem from PipeClose2Proc not waiting
912 # around for background processes to complete, meaning that previous calls to
913 # Tcl_ReapDetachedProcs might not have had a chance to reap all processes.
915 exec [info nameofexecutable] << {}
917 foreach p {create_httpd httpd_read halt_httpd meta check_crc} {
918 if {[llength [info proc $p]]} {rename $p {}}
920 removeFile testdoc.html
921 unset -nocomplain httpd_port httpd p
923 ::tcltest::cleanupTests