Created
          September 19, 2012 15:02 
        
      - 
      
- 
        Save eriwen/3750145 to your computer and use it in GitHub Desktop. 
    Illustration of bug https://github.com/igrigorik/em-http-request/issues/204
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require "em-http-request" | |
| EM.run { | |
| http = EM::HttpRequest.new("http://localhost:1234/file.gz").get | |
| http.errback { EM.stop } | |
| http.callback { EM.stop } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require "webrick" | |
| # Create a random file and gzip it | |
| if !File.exists?("file.gz") | |
| File.open("file", "w") do |f| | |
| 10_000.times do |i| | |
| f.write(rand) | |
| end | |
| end | |
| `gzip file` | |
| end | |
| # Start a webserver serving static files | |
| class FileHandler < WEBrick::HTTPServlet::FileHandler | |
| def do_GET(req, res) | |
| super | |
| res["Content-Encoding"] = "gzip" | |
| end | |
| end | |
| server = WEBrick::HTTPServer.new :Port => 1234 | |
| server.mount "/", FileHandler , "./" | |
| trap("INT") { server.stop } | |
| server.start | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment