I am using the PragProg 1.7.3 distro of ruby which includes zlib 0.5.1
I am trying to decode the response.body from an HTTP request.
Like this:
headers[“Accept-encoding”] = "gzip"
uri = URI.parse(source)
h = Net::HTTP.new(uri.host)
resp = h.get(uri.path, headers)
puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
resp.each {|key, val| printf “%-14s = %-40.40s\n”, key, val }
data = resp.body
if resp.fetch(‘content-encoding’, ‘None’) == 'gzip’
begin
pp data[0…2]
data = Zlib::Inflate.inflate(data)
rescue StandardError => err
print "Zlib error: #{err}\n"
end
end
This always results in : Zlib error: unknown compression method
Byte 2 of the string is \010 - which is correct.
Anyone seen this?
Thanks in advance.
-Jeff
See:
http://www.blue.sky.or.jp/atelier/ruby/zlib.en.html
For gzip you have to use Zlib::Gzip and a GzipReader object.
···
On Saturday, December 14, 2002, at 11:35 PM, Jeff Schilling wrote:
I am using the PragProg 1.7.3 distro of ruby which includes zlib 0.5.1
I am trying to decode the response.body from an HTTP request.
Like this:
headers[“Accept-encoding”] = “gzip”
uri = URI.parse(source)
h = Net::HTTP.new(uri.host)
resp = h.get(uri.path, headers)
puts “Code = #{resp.code}”
puts “Message = #{resp.message}”
resp.each {|key, val| printf “%-14s = %-40.40s\n”, key, val }
data = resp.body
if resp.fetch(‘content-encoding’, ‘None’) == ‘gzip’
begin
pp data[0…2]
data = Zlib::Inflate.inflate(data)
rescue StandardError => err
print “Zlib error: #{err}\n”
end
end
This always results in : Zlib error: unknown compression method
Byte 2 of the string is \010 - which is correct.
Anyone seen this?
Thanks in advance.
-Jeff
thanks.
I guess I was under the impression that the inflator would work the same.
In any case, the combo of StringIO and GzipReader did the trick.
-Jeff
Mark Wilson mwilson13@cox.net wrote in message news:89123A4B-0FE9-11D7-8B25-000393876156@cox.net…
···
See:
http://www.blue.sky.or.jp/atelier/ruby/zlib.en.html
For gzip you have to use Zlib::Gzip and a GzipReader object.
On Saturday, December 14, 2002, at 11:35 PM, Jeff Schilling wrote:
I am using the PragProg 1.7.3 distro of ruby which includes zlib 0.5.1
I am trying to decode the response.body from an HTTP request.
Like this:
headers[“Accept-encoding”] = “gzip”
uri = URI.parse(source)
h = Net::HTTP.new(uri.host)
resp = h.get(uri.path, headers)
puts “Code = #{resp.code}”
puts “Message = #{resp.message}”
resp.each {|key, val| printf “%-14s = %-40.40s\n”, key, val }
data = resp.body
if resp.fetch(‘content-encoding’, ‘None’) == ‘gzip’
begin
pp data[0…2]
data = Zlib::Inflate.inflate(data)
rescue StandardError => err
print “Zlib error: #{err}\n”
end
end
This always results in : Zlib error: unknown compression method
Byte 2 of the string is \010 - which is correct.
Anyone seen this?
Thanks in advance.
-Jeff
Hi,
http://www.blue.sky.or.jp/atelier/ruby/zlib.en.html
Sorry, this document is too old. I’ll replace it with new one soon.
For gzip you have to use Zlib::Gzip and a GzipReader object.
Use Zlib::GzipReader instead of GzipReader if you use Ruby/zlib-0.5.1.
Regards,
UENO Katsuhiro unnie@blue.sky.or.jp
···
On Sun, 15 Dec 2002 13:56:17 +0900 Mark Wilson mwilson13@cox.net wrote: