summaryrefslogtreecommitdiffstats
path: root/tests/http11.test
diff options
context:
space:
mode:
authorkjnash <k.j.nash@usa.net>2020-08-24 14:28:22 (GMT)
committerkjnash <k.j.nash@usa.net>2020-08-24 14:28:22 (GMT)
commit06a30a3a2acfa22ae71c137e7abb28e61748f496 (patch)
treef20b8778d7210b3135666fc503df1caca50da885 /tests/http11.test
parent120f36764644b094ad2b1fa55d66aac6c7cedb28 (diff)
downloadtcl-06a30a3a2acfa22ae71c137e7abb28e61748f496.zip
tcl-06a30a3a2acfa22ae71c137e7abb28e61748f496.tar.gz
tcl-06a30a3a2acfa22ae71c137e7abb28e61748f496.tar.bz2
Fix for http bug c2dc1da315. Add tests. Add detail about -handler to http(n). Bump version to 2.9.5.
Diffstat (limited to 'tests/http11.test')
-rw-r--r--tests/http11.test178
1 files changed, 178 insertions, 0 deletions
diff --git a/tests/http11.test b/tests/http11.test
index 240bfef..989b00f 100644
--- a/tests/http11.test
+++ b/tests/http11.test
@@ -280,6 +280,20 @@ test http11-1.13 "normal, 1.1 and keepalive as server default, no zip" -setup {
# -------------------------------------------------------------------------
+proc progress {var token total current} {
+ upvar #0 $var log
+ set log [list $current $total]
+ return
+}
+
+proc progressPause {var token total current} {
+ upvar #0 $var log
+ set log [list $current $total]
+ after 100 set ::WaitHere 0
+ vwait ::WaitHere
+ return
+}
+
test http11-2.0 "-channel" -setup {
variable httpd [create_httpd]
set chan [open [makeFile {} testfile.tmp] wb+]
@@ -376,6 +390,58 @@ test http11-2.4 "-channel,encoding identity" -setup {
halt_httpd
} -result {ok {HTTP/1.1 200 OK} ok close {} chunked}
+test http11-2.4.1 "-channel,encoding identity with -progress" -setup {
+ variable httpd [create_httpd]
+ set chan [open [makeFile {} testfile.tmp] wb+]
+ set logdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
+ -timeout 5000 -channel $chan \
+ -headers {accept-encoding identity} \
+ -progress [namespace code [list progress logdata]]]
+
+ http::wait $tok
+ seek $chan 0
+ set data [read $chan]
+ list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
+ [meta $tok connection] [meta $tok content-encoding]\
+ [meta $tok transfer-encoding] \
+ [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
+ [expr {[lindex $logdata 0] - [string length $data]}]
+} -cleanup {
+ http::cleanup $tok
+ close $chan
+ removeFile testfile.tmp
+ halt_httpd
+ unset -nocomplain logdata data
+} -result {ok {HTTP/1.1 200 OK} ok close {} chunked 0 0}
+
+test http11-2.4.2 "-channel,encoding identity with -progress progressPause enters event loop" -constraints knownBug -setup {
+ variable httpd [create_httpd]
+ set chan [open [makeFile {} testfile.tmp] wb+]
+ set logdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html \
+ -timeout 5000 -channel $chan \
+ -headers {accept-encoding identity} \
+ -progress [namespace code [list progressPause logdata]]]
+
+ http::wait $tok
+ seek $chan 0
+ set data [read $chan]
+ list [http::status $tok] [http::code $tok] [check_crc $tok $data]\
+ [meta $tok connection] [meta $tok content-encoding]\
+ [meta $tok transfer-encoding] \
+ [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
+ [expr {[lindex $logdata 0] - [string length $data]}]
+} -cleanup {
+ http::cleanup $tok
+ close $chan
+ removeFile testfile.tmp
+ halt_httpd
+ unset -nocomplain logdata data ::WaitHere
+} -result {ok {HTTP/1.1 200 OK} ok close {} chunked 0 0}
+
test http11-2.5 "-channel,encoding unsupported" -setup {
variable httpd [create_httpd]
set chan [open [makeFile {} testfile.tmp] wb+]
@@ -555,6 +621,16 @@ proc handler {var sock token} {
return [string length $chunk]
}
+proc handlerPause {var sock token} {
+ upvar #0 $var data
+ set chunk [read $sock]
+ append data $chunk
+ #::http::Log "handler read [string length $chunk] ([chan configure $sock -buffersize])"
+ after 100 set ::WaitHere 0
+ vwait ::WaitHere
+ return [string length $chunk]
+}
+
test http11-3.0 "-handler,close,identity" -setup {
variable httpd [create_httpd]
set testdata ""
@@ -653,6 +729,108 @@ test http11-3.4 "-handler,close,identity; HTTP/1.0 server does not send Connecti
halt_httpd
} -result {ok {HTTP/1.0 200 OK} ok {} {} {} 0}
+# It is not forbidden for a handler to enter the event loop.
+test http11-3.5 "-handler,close,identity as http11-3.0 but handlerPause enters event loop" -setup {
+ variable httpd [create_httpd]
+ set testdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
+ -timeout 10000 -handler [namespace code [list handlerPause testdata]]]
+ http::wait $tok
+ list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
+ [meta $tok connection] [meta $tok content-encoding] \
+ [meta $tok transfer-encoding] \
+ [expr {[file size testdoc.html]-[string length $testdata]}]
+} -cleanup {
+ http::cleanup $tok
+ unset -nocomplain testdata ::WaitHere
+ halt_httpd
+} -result {ok {HTTP/1.0 200 OK} ok close {} {} 0}
+
+test http11-3.6 "-handler,close,identity as http11-3.0 but with -progress" -setup {
+ variable httpd [create_httpd]
+ set testdata ""
+ set logdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
+ -timeout 10000 -handler [namespace code [list handler testdata]] \
+ -progress [namespace code [list progress logdata]]]
+ http::wait $tok
+ list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
+ [meta $tok connection] [meta $tok content-encoding] \
+ [meta $tok transfer-encoding] \
+ [expr {[file size testdoc.html]-[string length $testdata]}] \
+ [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
+ [expr {[lindex $logdata 0] - [string length $testdata]}]
+} -cleanup {
+ http::cleanup $tok
+ unset -nocomplain testdata logdata ::WaitHere
+ halt_httpd
+} -result {ok {HTTP/1.0 200 OK} ok close {} {} 0 0 0}
+
+test http11-3.7 "-handler,close,identity as http11-3.0 but with -progress progressPause enters event loop" -setup {
+ variable httpd [create_httpd]
+ set testdata ""
+ set logdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
+ -timeout 10000 -handler [namespace code [list handler testdata]] \
+ -progress [namespace code [list progressPause logdata]]]
+ http::wait $tok
+ list [http::status $tok] [http::code $tok] [check_crc $tok $testdata]\
+ [meta $tok connection] [meta $tok content-encoding] \
+ [meta $tok transfer-encoding] \
+ [expr {[file size testdoc.html]-[string length $testdata]}] \
+ [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
+ [expr {[lindex $logdata 0] - [string length $testdata]}]
+} -cleanup {
+ http::cleanup $tok
+ unset -nocomplain testdata logdata ::WaitHere
+ halt_httpd
+} -result {ok {HTTP/1.0 200 OK} ok close {} {} 0 0 0}
+
+test http11-3.8 "close,identity no -handler but with -progress" -setup {
+ variable httpd [create_httpd]
+ set logdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
+ -timeout 10000 \
+ -progress [namespace code [list progress logdata]] \
+ -headers {accept-encoding {}}]
+ http::wait $tok
+ list [http::status $tok] [http::code $tok] [check_crc $tok]\
+ [meta $tok connection] [meta $tok content-encoding] \
+ [meta $tok transfer-encoding] \
+ [expr {[file size testdoc.html]-[string length [http::data $tok]]}] \
+ [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
+ [expr {[lindex $logdata 0] - [string length [http::data $tok]]}]
+} -cleanup {
+ http::cleanup $tok
+ unset -nocomplain logdata ::WaitHere
+ halt_httpd
+} -result {ok {HTTP/1.1 200 OK} ok close {} {} 0 0 0}
+
+test http11-3.9 "close,identity no -handler but with -progress progressPause enters event loop" -setup {
+ variable httpd [create_httpd]
+ set logdata ""
+} -body {
+ set tok [http::geturl http://localhost:$httpd_port/testdoc.html?close=1 \
+ -timeout 10000 \
+ -progress [namespace code [list progressPause logdata]] \
+ -headers {accept-encoding {}}]
+ http::wait $tok
+ list [http::status $tok] [http::code $tok] [check_crc $tok]\
+ [meta $tok connection] [meta $tok content-encoding] \
+ [meta $tok transfer-encoding] \
+ [expr {[file size testdoc.html]-[string length [http::data $tok]]}] \
+ [expr {[lindex $logdata 0] - [lindex $logdata 1]}] \
+ [expr {[lindex $logdata 0] - [string length [http::data $tok]]}]
+} -cleanup {
+ http::cleanup $tok
+ unset -nocomplain logdata ::WaitHere
+ halt_httpd
+} -result {ok {HTTP/1.1 200 OK} ok close {} {} 0 0 0}
+
test http11-4.0 "normal post request" -setup {
variable httpd [create_httpd]
} -body {