Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 21d8289c7718b563a6d544d6182191d00f4ec22c @nodanaonlyzuul committed
Showing with 52 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +11 −0 README.textile
  3. +4 −0 bin/white_castle
  4. 0 index.html
  5. +25 −0 lib/white_castle.rb
  6. +11 −0 white_castle.gemspec
1 .gitignore
@@ -0,0 +1 @@
+*.gem
11 README.textile
@@ -0,0 +1,11 @@
+h1. white_castle
+
+h2. Shamelessly serve anything (from your filesystem)
+
+h3. Usage
+
+@> white_castle 3000@
+This starts a webrick server on port 3000, the default port is 1234
+
+h4. Credit
+All credit goes to Toby Ho: http://tobyho.com/
4 bin/white_castle
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+require 'white_castle'
+
+WhiteCastle.start(:port => ARGV[0])
0 index.html
No changes.
25 lib/white_castle.rb
@@ -0,0 +1,25 @@
+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
+
+class WhiteCastle
+ def start(options = {:port => 1234})
+ server = WEBrick::HTTPServer.new :Port => options[:port]
+ server.mount "/", NonCachingFileHandler , Dir.pwd
+ trap('INT') { server.stop }
+ server.start
+ end
+end
11 white_castle.gemspec
@@ -0,0 +1,11 @@
+$spec = Gem::Specification.new do |s|
+ s.name = "white_castle"
+ s.version = '0.1.0'
+ s.summary = "Shamelessly serve anything (from your filesystem)"
+ s.authors = ['nodanaonlyzuul']
+ s.email = ['beholdthepanda@gmail.com']
+ s.homepage = 'https://github.com/nodanaonlyzuul/white_castle'
+ s.executables = ['white_castle']
+ s.files = Dir['bin/*','lib/**/*']
+ s.rubyforge_project = 'nowarning'
+end

0 comments on commit 21d8289

Please sign in to comment.
Something went wrong with that request. Please try again.