Skip to content

Instantly share code, notes, and snippets.

@valk
Last active August 29, 2015 14:10
Show Gist options
  • Save valk/d80ba2512e95ba5f0583 to your computer and use it in GitHub Desktop.
Save valk/d80ba2512e95ba5f0583 to your computer and use it in GitHub Desktop.
Tiny server that allows working with static files or anything else written in Ruby.
#!/usr/bin/env ruby
#
# In order to run:
# > ruby server.rb
#
# Or add execution permissions and run:
# > ./server.rb
#
# Then point your browser to http://localhost:1234/your_file.html
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 => 1234
server.mount "/", NonCachingFileHandler , './'
trap('INT') { server.stop }
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment