-
-
Save jstarrdewar/3805501 to your computer and use it in GitHub Desktop.
Convenient way to launch WEBrick to serve the current directory and prevent caching.
This file contains 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
#!/usr/bin/env ruby | |
require 'webrick' | |
class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler | |
def prevent_caching(res) | |
res['ETag'] = nil | |
res['Last-Modified'] = Time.now + 100**4 | |
res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0' | |
res['Pragma'] = 'no-cache' | |
res['Expires'] = Time.now - 100**4 | |
end | |
def do_GET(req, res) | |
super | |
prevent_caching(res) | |
end | |
end | |
server = WEBrick::HTTPServer.new :Port => 8989 | |
server.mount '/', NonCachingFileHandler , Dir.pwd | |
trap('INT') { server.stop } | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment