Skip to content
Tcl Source Code History Of Ticket fb642c54bc58b31d
Login

History Of Ticket fb642c54bc58b31d

Artifacts Associated With Ticket fb642c54bc58b31d

  1. Ticket change [a9b7cac406] (rid 162071) by gerhardr on 2018-03-25 13:12:25:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      Some compressd files are not completely downloaded.
      Test script (requires wget to compare the http downloaded file):
      ----------------------------------------------------- 
      package require http
      #
      # 1st part from Tcl 8.6 manpage example
      #
      proc httpcopy { url file {chunk 4096} } {
        set out [open $file w]
        set token [::http::geturl $url -channel $out \
            -progress httpCopyProgress -blocksize $chunk]
        close $out
        
        # This ends the line started by httpCopyProgress
        puts stderr ""
        
        upvar #0 $token state
        set max 0
        foreach {name value} $state(meta) {
          if {[string length $name] > $max} {
            set max [string length $name]
          }
          if {[regexp -nocase ^location$ $name]} {
            # Handle URL redirects
            puts stderr "Location:$value"
            return [httpcopy [string trim $value] $file $chunk]
          }
        }
        incr max
        foreach {name value} $state(meta) {
          puts [format "%-*s %s" $max $name: $value]
        }
        
        return $token
      }
      proc httpCopyProgress {args} {
        puts -nonewline stderr .
        flush stderr
      }
      
      #
      # === Here starts my additional testing code ===
      #
      if {[llength $argv]} {
        set url [lindex $argv 0]
      } else {
        set url "http://someonewhocares.org/hosts/hosts"
      }
      set org "outfile1.txt"
      set out "outfile2.txt"
      
      puts "Loading file $org from $url using wget"
      catch {exec wget $url -O $org}
      
      puts "Loading file $out from $url via httpcopy"
      httpcopy $url $out
      puts "HTTP file copy size is [file size $out], wget filesize is [file 
      size $org]"
      ----------------------------------------------------- 
      Output example
      $ tclsh test_download.tcl 
      Loading file outfile1.txt from http://someonewhocares.org/hosts/hosts 
      using wget
      Loading file outfile2.txt from http://someonewhocares.org/hosts/hosts 
      via httpcopy
      .......
      Date:                Fri, 23 Mar 2018 21:23:21 GMT
      Server:              Apache/2.2.31 (Unix) mod_ssl/2.2.31 
      OpenSSL/1.0.1e-fips
      content-disposition: attachment: filename=hosts
      cache-control:       public, max-age=86400
      Last-Modified:       Thu, 22 Mar 2018 08:13:42 GMT
      Vary:                Accept-Encoding
      Content-Encoding:    gzip
      Connection:          close
      Transfer-Encoding:   chunked
      Content-Type:        text/plain
      HTTP file copy size is 342964, wget filesize is 416015
      
    5. foundin initialized to: "8.6.6"
    6. is_private initialized to: "0"
    7. login: "gerhardr"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9b076687903aba8f5254d84cbc9577f25d0fbe8c"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "gerhardr"
    14. subsystem initialized to: "29. http Package"
    15. title initialized to: "Incorrect download of compressed encoded data"
    16. type initialized to: "Bug"
  2. Add attachment "test_download.tcl" [fbdf3b5bd1] (rid 162072) by gerhardr on 2018-03-25 13:52:08.

  3. Ticket change [a2d5d9d6ad] (rid 162073) by bll on 2018-03-25 15:46:53:

    1. icomment:
      Relevant discussion at:
      
      https://groups.google.com/forum/#!topic/comp.lang.tcl/7mNIrCZH2Ks
      
    2. login: "bll"
    3. mimetype: "text/plain"
  4. Ticket change [ada8006fc6] (rid 162085) by sebres on 2018-03-26 12:12:35:

    1. closedate changed to: "2458204.00874109"
    2. closer changed to: "sebres"
    3. icomment:
      You're trying to write file using current system encoding (which is UTF-8, I assume).
      
      So just change:
      <pre>
      - <b style="color:red">set out [open $file w]</b>
      + <b style="color:green">set out [open $file wb]</b>
      </pre>
      And you'll get it correctly.
      
      Note, this server does not provide the charset (just says text/plain in content-type, but it says nothing about what it is).
      So the target encoding is undefined, wget will use binary here (so writes as is).
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
  5. Ticket change [8dc0563eaf] (rid 162094) by sebres on 2018-03-26 16:40:47:

    1. closer changed to: "nobody"
    2. icomment:
      Reopened because of <a href="https://groups.google.com/d/msg/comp.lang.tcl/7mNIrCZH2Ks/dbOyZcYABQAJ">https://groups.google.com/d/msg/comp.lang.tcl/7mNIrCZH2Ks/dbOyZcYABQAJ</a>:
      <pre>
      > ```diff
      > - set out [open $file w]
      > + set out [open $file wb]
      > ```
      
      confirmed, download using: -headers {Accept-Encoding identity} brings
      with "set out [open $file wb]" the same result as wget.
      
      But without the geturl header {Accept-Encoding identity} the download
      file size differs by ca. 70kB.
      ....
      "HTTP file copy size is 342957, wget filesize is 416135"
      
      > Please reopen if I'm wrong.
      
      Don't know if this can be seen as expected behavior.
      The man page also explains the option -binary and even setting this to
      true and using filemode binary does not download the complete file.
      
      From my point of view it is really hard to find out why geturl does
      behave as it does.
      Maybe improving the man pages could also bring more clear picture or
      adding the gzip encoding to the manpage example.
      
      BTW: Nevertheless my problem is solved, many thanks to clt :-) 
      </pre>
      
      Looks like some response headers seem to still not correctly impact, if "Accept-Encoding" is not "identity" (resp. "chunked" in my case).<br/>
      Currently, I've no time to dig deeper.
      
    3. login: "sebres"
    4. mimetype: "text/x-fossil-wiki"
    5. status changed to: "Pending"
    6. username: "[email protected]"
  6. Add attachment "test_download.tcl" [fcbc5c1def] (rid 162102) by gerhardr on 2018-03-27 12:19:16.

  7. Add attachment "test_download.tcl" [e4927d03d2] (rid 162103) by gerhardr on 2018-03-27 12:35:54.

  8. Ticket change [d64d866566] (rid 204126) by kjnash on 2022-09-11 16:43:20:

    1. closedate changed to: "2459834.19676161"
    2. closer changed to: "kjnash"
    3. icomment:
      This ticket raises three separate issues:
      
      1. [open $file wb]
      
      The "b" flag is equivalent to
          fconfigure $file -translation binary
      and in current http this is done automatically if the content-type is non-binary or if the stacked channel includes decompression - using the following code:
      
          if {$state(-binary) || [IsBinaryContentType $state(type)]} {
              # Turn off conversions for non-text data.
              set state(binary) 1
          }
          if {[info exists state(-channel)]} {
              if {$state(binary) || [llength [ContentEncoding $token]]} {
                  fconfigure $state(-channel) -translation binary
              }
              ...
          }
      
      2. "Accept-Encoding identity"
      
      This is necessary to tell the server not to use compression.  The http::geturl option -zip 0 should do this but does not - this bug is unrelated to this ticket (which always used the default -zip 1) and was fixed in commit [3cee774ebf] of branch http-bugfixes-2022H2.
      
      3. using gzip
      
      The response is truncated if gzip is used.
      
      The error is the same as the truncation issue seen in tickets [3610253] for a chunked+gzip response written directly to a -channel.  That bug is now fixed.
      
    4. login: "kjnash"
    5. mimetype: "text/x-fossil-plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"