diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-09-30 14:49:15 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-09-30 14:49:15 (GMT) |
commit | 1f4f47ccf50b4d6518c3dbfd9fd09c7bbb785929 (patch) | |
tree | 922d6c60574bcbfc72a4ed59cfe3f8a18ac40334 | |
parent | accd2800ecceb527ff9315ec011511b30f32a980 (diff) | |
download | tcl-1f4f47ccf50b4d6518c3dbfd9fd09c7bbb785929.zip tcl-1f4f47ccf50b4d6518c3dbfd9fd09c7bbb785929.tar.gz tcl-1f4f47ccf50b4d6518c3dbfd9fd09c7bbb785929.tar.bz2 |
(slightly) better error-message for invalid http -headers option. This works for plain 8.6 too
-rw-r--r-- | library/http/http.tcl | 8 | ||||
-rw-r--r-- | tests/http.test | 2 |
2 files changed, 4 insertions, 6 deletions
diff --git a/library/http/http.tcl b/library/http/http.tcl index abef596..b0f87de 100644 --- a/library/http/http.tcl +++ b/library/http/http.tcl @@ -733,7 +733,7 @@ proc http::geturl {url args} { -strict boolean -timeout integer -validate boolean - -headers list + -headers dict } set state(charset) $defaultCharset set options { @@ -747,10 +747,8 @@ proc http::geturl {url args} { foreach {flag value} $args { if {[regexp -- $pat $flag]} { # Validate numbers - if { - ([info exists type($flag)] && - ![string is $type($flag) -strict $value]) || - $flag eq "-headers" && [llength $value] %2 != 0 + if {($flag eq "-headers") ? [catch {dict size $value}] : + ([info exists type($flag)] && ![string is $type($flag) -strict $value]) } { unset $token return -code error \ diff --git a/tests/http.test b/tests/http.test index 15bc37f..97e6cfa 100644 --- a/tests/http.test +++ b/tests/http.test @@ -450,7 +450,7 @@ test http-3.33 {http::geturl application/xml is text} -body { } -result {test 4660 /test} test http-3.34 {http::geturl -headers not a dict} -returnCodes error -body { http::geturl http://test/t -headers NoDict -} -result {Bad value for -headers (NoDict), must be list} +} -result {Bad value for -headers (NoDict), must be dict} test http-4.1 {http::Event} -body { set token [http::geturl $url -keepalive 0] |