white_castle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/white_castle +17 -0
  2. data/lib/white_castle.rb +33 -0
  3. metadata +69 -0
data/bin/white_castle ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'white_castle'
3
+
4
+ args = ARGV.compact
5
+
6
+ if args
7
+ options = {}
8
+ if args[0] == "-p"
9
+ WhiteCastle.start(:port => args[1])
10
+ else
11
+ options = {:document_root => args[0]}
12
+ options.merge!(:port => args[2]) if args[1] == "-p"
13
+ WhiteCastle.start(options)
14
+ end
15
+ else
16
+ WhiteCastle.start()
17
+ end
@@ -0,0 +1,33 @@
1
+ require 'webrick'
2
+
3
+ class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
4
+ def prevent_caching(res)
5
+ res['ETag'] = nil
6
+ res['Last-Modified'] = Time.now + 100**4
7
+ res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
8
+ res['Pragma'] = 'no-cache'
9
+ res['Expires'] = Time.now - 100**4
10
+ end
11
+
12
+ def do_GET(req, res)
13
+ super
14
+ prevent_caching(res)
15
+ end
16
+ end
17
+
18
+ class WhiteCastle
19
+ def self.start(options)
20
+
21
+ default_options = {:port => 3000, :document_root => "."}
22
+ options = default_options.merge(options)
23
+
24
+ server = WEBrick::HTTPServer.new(
25
+ :Port => options[:port],
26
+ :DocumentRoot => options[:document_root],
27
+ :FancyIndexing => true
28
+ )
29
+ server.mount '/nocache', NonCachingFileHandler
30
+ trap('INT') { server.stop }
31
+ server.start
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: white_castle
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - nodanaonlyzuul
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-24 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email:
24
+ - beholdthepanda@gmail.com
25
+ executables:
26
+ - white_castle
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - bin/white_castle
33
+ - lib/white_castle.rb
34
+ has_rdoc: true
35
+ homepage: https://github.com/nodanaonlyzuul/white_castle
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: nowarning
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Shamelessly serve anything (from your filesystem)
68
+ test_files: []
69
+