Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-03-29
09:58 • Closed ticket [0aea0e0dcf]: http::geturl -headers syntax and compressed content<... artifact: e2897d5e80 user: jan.nijtmans
2015-05-14
08:13 • Closed ticket [b9d0434667]: default settings request unreliable "deflate&qu... artifact: 40d03eedd2 user: dkf
08:05
[b9d0434667] Prefer the gzip encoding for transfers. It's less efficient, but it is far more interop... check-in: 52fd51a4df user: dkf tags: trunk
2015-05-13
23:11 • Ticket [b9d0434667] default settings request unreliable "deflate" comp... artifact: f249362fec user: dgp
22:59 • Ticket [b9d0434667]: 4 changes artifact: de07db7543 user: dkf
22:55 • Ticket [b9d0434667]: 4 changes artifact: 2387b514bc user: dkf
22:48 • Ticket [b9d0434667]: 4 changes artifact: 11e0b85b43 user: dkf
15:28 • Ticket [b9d0434667]: 4 changes artifact: 1c1948f2b4 user: dgp
12:24 • Ticket [b9d0434667]: 3 changes artifact: 2212297bee user: dgp
03:44 • Ticket [b9d0434667]: 3 changes artifact: 1f8ba3cd0b user: aspect
2015-05-11
18:34 • Ticket [b9d0434667]: 4 changes artifact: a9ef0b8c22 user: dgp
2015-05-01
14:44 • Ticket [b9d0434667]: 4 changes artifact: e58ca1af91 user: dgp
2014-12-11
10:33 • Ticket [b9d0434667]: 4 changes artifact: c00cee78ee user: nem
10:11 • New ticket [b9d0434667]. artifact: 871995d7bb user: Malbrouck

default settings request unreliable "deflate" compression

Closed / Fixedb9d0434667d94e5f9737b87ff024e7bc3baea5d5Created 12 years agoUpdated 12 years ago
Descriptionplain2014-12-11 10:11:43
 http::geturl returns "data error" with TCL >8.6 and RIPE's REST API. 

With TCL 8.5 it works: 

% puts $tcl_version 
8.5 
% package require http 
2.7.5 
% http::geturl http://www.hp.com/index.html 
::http::1 
% http::geturl http://rest.db.ripe.net/search 
::http::2 
% 


With 8.6 it doesn't: 

% puts $tcl_version 
8.6 
% info patchlevel 
8.6.1 
% package require http 
2.8.7 
% http::geturl http://www.hp.com/index.html 
::http::1 
% http::geturl http://rest.db.ripe.net/search 
data error 
% 


People reported same problems with TCL 8.6.2 & 8.6.3 in this thread:
https://groups.google.com/forum/#!topic/comp.lang.tcl/NiIKhFgEUBY
Referenced by2
  • e2897d5e80Closed ticket [0aea0e0dcf]: http::geturl -headers syntax and compressed content plus 6 other changes ticket2016-03-29 09:58:52
  • 52fd51a4df[b9d0434667] Prefer the gzip encoding for transfers. It's less efficient, but it is far more interoperable and that's a more important metric. check-in2015-05-14 08:05:37
nem (claiming to be Neil Madden)plain2014-12-11 10:33:05
As described in the linked c.l.t thread, the problem appears to be due to the response being compressed. Tcl appears unable to decompress it correctly. A workaround is to disable the Accept-Encoding header:

% package require http
2.8.8
% http::geturl http://rest.db.ripe.net/search \
    -headers [list Accept-Encoding ""]
::http::1
dgpplain2015-05-01 14:44:43
Is this really a [zlib] bug then?
dgpplain2015-05-11 18:34:00
http://core.tcl.tk/tcl/info/e861cc28b065288e

is the checkin that breaks things.  Still possible
that [zlib] troubles are at the root, but seems more
likely this patch just gets some things wrong.
aspectplain2015-05-13 03:44:48
The error is definitely in zlib inflate:

======

set s [socket rest.db.ripe.net 80]
fconfigure $s -translation crlf -buffering line
puts $s "GET /search HTTP/1.1"
puts $s "Host: rest.db.ripe.net"
puts $s "Accept-Encoding: deflate"
puts $s "Connection: close"
puts $s ""
puts $s ""

fconfigure $s -encoding binary -translation binary

set bits [read $s]


puts "got [string length $bits] bytes"
puts [zlib inflate $bits]
======

got 556 bytes
data error
    while executing
"zlib inflate $bits"
dgpplain2015-05-13 12:24:41
anyone know what the correct inflated result is?
dgp Ticket [b9d0434667]: 4 changes [History diff]2015-05-13 15:28:40
dkfhtml2015-05-13 22:48:20

I vaguely remember seeing somewhere that compressed HTTP transfers should always be done as gzip because of different interpretations of other names in weird ways.

That said, your test is completely bogus. You need to strip the headers first!

If I do that and then use zlib decompress on the rest (not zlib inflate) then I get what appears to be reasonable content. Which agrees with what my first paragraph says; there's breakage in the way that this part of the HTTP specification is interpreted. Interoperable code uses gzip.

dkfhtml2015-05-13 22:55:22

For more details about what's going on, see this Stack Overflow question and its answers.

dkfhtml2015-05-13 22:59:13

BTW, the response you're looking for is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><whois-resources xmlns:xlink="http://www.w3.org/1999/xlink"><link xlink:type="locator" xlink:href="http://rest.db.ripe.net/search/"/><errormessages><errormessage severity="Error" text="Query param 'query-string' cannot be empty"/></errormessages><terms-and-conditions xlink:type="locator" xlink:href="http://www.ripe.net/db/support/db-terms-conditions.pdf"/></whois-resources>

dgp Ticket [b9d0434667]: 3 changes [History diff]2015-05-13 23:11:13
dkfhtml2015-05-14 08:13:57

Fixed; we now prefer the gzip transfer encoding because it's widely known that alternatives are wrong on some servers. It's really not our fault, but we can't help that. The default can be overridden by setting the Accept-Encoding header explicitly (using the normal API mechanism for that); there are examples of what to do in Tcl's test suite (http11.test).

I looked into putting in code that would try to guess from the first few bytes of the stream. We won't be trying to do that! It gets really complicated (in terms of just what to read and when) and just switching to gzip works as well (and it's very widely implemented too). I guess we could have done it with a "do what I mean" decompression method, but that's really horrible.

The fix will ship with the next 8.6 patch release. The workaround is to specify Accept-Encoding to be something like identity, which disables compression and works on 8.5 and 8.6.

Log in (anonymous is fine) to add a comment.