encoding - How to properly use Ruby CGI module for gzipped output? -


this code doesn't work in firefox 38.0.1 (content encoding error) , google chrome 42.0.2311.152 (err_content_decoding_failed), works opera 12.16 , curl (with --compressed option):

#!/usr/bin/ruby require "cgi" require "zlib"  cgi=cgi.new(:accept_charset => "utf-8")  #header puts "content-type: text/html; charset=\"utf-8\""  puts "content-encoding: gzip" puts  #generating html output  output="" output << "<html><body><style> p {line-height:20%;font-size:9px;font-family:monospace} {text-decoration:none} a[title]:hover:after {font-size:9px;font-family:monospace}</style>" output << "<p style='text-align:center'>#{time.now}</p>" output << "<p>#{"-"*190}</p>" output<<"</body></html>"  z = zlib::deflate.new(9) compressed = z.deflate(output,zlib::finish) z.close puts compressed 

this code works in browser, , curl too:

#!/usr/bin/ruby require "cgi" require "zlib"  cgi=cgi.new(:accept_charset => "utf-8")  puts "content-type: text/html; charset=\"utf-8\""  puts "content-encoding: gzip" puts  output="" output << "<html><body><style> p {line-height:20%;font-size:9px;font-family:monospace} {text-decoration:none} a[title]:hover:after {font-size:9px;font-family:monospace}</style>" output << "<p style='text-align:center'>#{time.now}</p>" output << "<p>#{"-"*190}</p>" output<<"</body></html>"  file.write("gzip.temp",output) compressed=io.popen("cat gzip.temp|gzip -c","r").read puts compressed 

okay, problem solved, 1 have use code section:

z = zlib::deflate.new(9,16+zlib::max_wbits) compressed = z.deflate(output,zlib::finish) z.close puts compressed 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -