Skip to content

Instantly share code, notes, and snippets.

@eriwen
Created September 19, 2012 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eriwen/3750145 to your computer and use it in GitHub Desktop.
Save eriwen/3750145 to your computer and use it in GitHub Desktop.
require "em-http-request"
EM.run {
http = EM::HttpRequest.new("http://localhost:1234/file.gz").get
http.errback { EM.stop }
http.callback { EM.stop }
}
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