Skip to content
Tcl Source Code History Of Ticket 838e99a76dd54f19
Login

History Of Ticket 838e99a76dd54f19

Artifacts Associated With Ticket 838e99a76dd54f19

  1. Ticket change [09db90cdff] (rid 148860) by gahr on 2016-09-24 19:00:46:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. 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)]} {
      
    5. foundin initialized to: "8.6.6"
    6. is_private initialized to: "0"
    7. login: "gahr"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "438e59f1f1c891b29d2528ed82d1e629cecc6336"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "gahr"
    14. subsystem initialized to: "29. http Package"
    15. title initialized to: "treat application/xml as text"
    16. type initialized to: "Bug"
  2. Ticket change [1daae07366] (rid 148861) by gahr on 2016-09-25 16:05:00:

    1. 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.
      
    2. login: "gahr"
    3. mimetype: "text/plain"
    4. username: "gahr"
  3. Ticket change [2f37f5bdbc] (rid 148862) by gahr on 2016-09-25 16:24:19:

    1. 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
      
    2. login: "gahr"
    3. mimetype: "text/plain"
    4. username: "gahr"
  4. Ticket change [85a248f65c] (rid 148883) by jan.nijtmans on 2016-09-26 14:34:17:

    1. assignee changed to: "dkf"
    2. icomment: "Assigning to the http package expert"
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
  5. Ticket change [9b4eb1a626] (rid 149089) by dkf on 2016-10-08 15:45:01:

    1. icomment:
      Relevant reading: <a href="https://www.ietf.org/rfc/rfc3023.txt">RFC 3023</a>
      
    2. login: "dkf"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "dkf"
  6. Ticket change [9c0ed57e45] (rid 149090) by dkf on 2016-10-08 15:53:47:

    1. 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.
      
    2. login: "dkf"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "dkf"
  7. Ticket change [99901ceea6] (rid 149091) by dkf on 2016-10-08 15:54:33:

    1. login: "dkf"
    2. mimetype: "text/plain"
    3. priority changed to: "7 High"
  8. Ticket change [0ef55940fe] (rid 149102) by dkf on 2016-10-08 16:43:39:

    1. closedate changed to: "2457670.19698041"
    2. closer changed to: "dkf"
    3. 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...
      
    4. login: "dkf"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "dkf"