Artifacts Associated With Ticket 838e99a76dd54f19
Ticket change [09db90cdff] (rid 148860) by gahr on 2016-09-24 19:00:46:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The http package converts the body of the response to the charset specified in the response headers only if content-type matches text*. This patch proposes to treat application/xml in the same way. The rationale is that xml is encoded in utf-8 by default and carries human readable information. Currently, anybody receiving */xml should decode the stream himself, as suggested in [1733261fffffffffffff]. I find this counterintuitive. A real-world use case for this is WebDAV, which has deprecated the use of text/xml in favour of application/xml, see rfc 4918 §8.2 [http://www.webdav.org/specs/rfc4918.html#rfc.section.8.2] I propose the following patch. Index: library/http/http.tcl ================================================================== --- library/http/http.tcl +++ library/http/http.tcl @@ -1045,11 +1045,15 @@ # We have to use binary translation to count bytes properly. fconfigure $sock -translation binary if { - $state(-binary) || ![string match -nocase text* $state(type)] + $state(-binary) || + ( + ![string match -nocase text* $state(type)] && + ![string match -nocase application/xml* $state(type)] + ) } { # Turn off conversions for non-text data set state(binary) 1 } if {[info exists state(-channel)]} { - foundin initialized to: "8.6.6"
- is_private initialized to: "0"
- login: "gahr"
- priority initialized to: "5 Medium"
- private_contact initialized to: "438e59f1f1c891b29d2528ed82d1e629cecc6336"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "gahr"
- subsystem initialized to: "29. http Package"
- title initialized to: "treat application/xml as text"
- type initialized to: "Bug"
Ticket change [1daae07366] (rid 148861) by gahr on 2016-09-25 16:05:00:
- icomment:
Some evidence that the current behaviour is weird, to say the least. Given these two URLs (available for anyone to check out) and the script below: https://www.ptrcrt.ch/838e99a76d/utf8.html https://www.ptrcrt.ch/838e99a76d/utf8.xhtml ================================================== #!/usr/local/bin/tclsh8.6 package require http 2 package require tls ::http::register https 443 ::tls::socket puts "Tcl version : [info patchlevel]" puts "http version: [package present http]" puts {} set tok [::http::geturl [lindex $argv 0]] foreach {k v} [::http::meta $tok] { puts "$k: $v" } puts {} puts [::http::data $tok] ================================================== The two outputs are the following: ================================================== % tclsh8.6 testurl.tcl https://www.ptrcrt.ch/838e99a76d/utf8.html Tcl version : 8.6.6 http version: 2.8.9 Server: nginx Date: Sun, 25 Sep 2016 15:58:52 GMT Content-Type: text/html; charset=utf-8 Last-Modified: Sun, 25 Sep 2016 15:54:18 GMT Transfer-Encoding: chunked Connection: close ETag: W/"57e7f32a-53" Content-Encoding: gzip <!DOCTYPE html> <html><head><title>üäö</title></head><body>üäö</body></html> ================================================== and ================================================== % tclsh8.6 testurl.tcl https://www.ptrcrt.ch/838e99a76d/utf8.xhtml Tcl version : 8.6.6 http version: 2.8.9 Server: nginx Date: Sun, 25 Sep 2016 15:59:10 GMT Content-Type: application/xhtml+xml Content-Length: 289 Last-Modified: Sun, 25 Sep 2016 15:52:43 GMT Connection: close ETag: "57e7f2cb-121" Accept-Ranges: bytes <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>üäö</title></head><body>üäö</body></html> ================================================== There is no reason why the application/xhtml+xml content shouldn't be correctly decoded by the http package. Also, my patch above would need to be modified to match application/xml and application/*+xml. - login: "gahr"
- mimetype: "text/plain"
- username: "gahr"
- icomment:
Ticket change [2f37f5bdbc] (rid 148862) by gahr on 2016-09-25 16:24:19:
- icomment:
My current conclusion is that the http package should default to utf-8 when dealing with XML content. Here's a new version of the patch. Index: library/http/http.tcl ================================================================== --- library/http/http.tcl +++ library/http/http.tcl @@ -1046,7 +1046,9 @@ # We have to use binary translation to count bytes properly. fconfigure $sock -translation binary - if { + if {[regexp {application/(.*\+)?xml} $state(type)]} { + set state(charset) utf-8 + } elseif { $state(-binary) || ![string match -nocase text* $state(type)] } { # Turn off conversions for non-text data - login: "gahr"
- mimetype: "text/plain"
- username: "gahr"
- icomment:
Ticket change [85a248f65c] (rid 148883) by jan.nijtmans on 2016-09-26 14:34:17:
- assignee changed to: "dkf"
- icomment: "Assigning to the http package expert"
- login: "jan.nijtmans"
- mimetype: "text/plain"
Ticket change [9b4eb1a626] (rid 149089) by dkf on 2016-10-08 15:45:01:
- icomment:
Relevant reading: <a href="https://www.ietf.org/rfc/rfc3023.txt">RFC 3023</a>
- login: "dkf"
- mimetype: "text/x-fossil-wiki"
- username: "dkf"
- icomment:
Ticket change [9c0ed57e45] (rid 149090) by dkf on 2016-10-08 15:53:47:
- icomment:
It seems from the RFC that if a format with major type <tt>application</tt> comes through and the minor type is <tt>xml</tt>, <tt>xml-external-parsed-entity</tt>, or <tt>xml-dtd</tt>, <i>or</i> the minor type matches the glob pattern <tt>*+xml</tt>, then the data should be treated as textual despite being not generally deemed human-readable. (I'm totally OK with having the <tt>-binary</tt> switch override. In fact, it probably ought to override <i>both ways</i> so that any other weird cases can be handled by users without patching Tcl.) We probably ought to factor out this bit of decision making into its own procedure. The submitted patch is too simplistic.
- login: "dkf"
- mimetype: "text/x-fossil-wiki"
- username: "dkf"
- icomment:
Ticket change [99901ceea6] (rid 149091) by dkf on 2016-10-08 15:54:33:
- login: "dkf"
- mimetype: "text/plain"
- priority changed to: "7 High"
Ticket change [0ef55940fe] (rid 149102) by dkf on 2016-10-08 16:43:39:
- closedate changed to: "2457670.19698041"
- closer changed to: "dkf"
- icomment:
Fixed this bug (8.5, 8.6 and trunk). Making the <tt>-binary</tt> switch override properly is a larger project, FRQ-sized. Project for another time...
- login: "dkf"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dkf"