servethis 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,14 @@
1
1
  require "servethis/version"
2
2
  require "webrick"
3
3
  require "optparse"
4
+ require "servethis/noncachingfilehandler"
4
5
 
5
6
  options = {
6
7
  :Port => 8000,
7
- :DocumentRoot => "."
8
+ :DocumentRoot => ".",
9
+ :ServerSoftware => "WEBrick/#{WEBrick::VERSION} " +
10
+ "(Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE}) " +
11
+ "servethis/#{Servethis::VERSION}",
8
12
  }
9
13
 
10
14
  OptionParser.new do |opts|
@@ -17,6 +21,10 @@ end.parse!
17
21
 
18
22
  options[:DocumentRoot] = ARGV[0] if ARGV[0]
19
23
 
24
+ document_root = options[:DocumentRoot]
25
+ options.delete(:DocumentRoot)
26
+
20
27
  server = WEBrick::HTTPServer.new( options )
28
+ server.mount("/", NonCachingFileHandler, document_root, server.config[:DocumentRootOptions])
21
29
  trap("INT") { server.shutdown }
22
30
  server.start
@@ -0,0 +1,16 @@
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
@@ -1,3 +1,3 @@
1
1
  module Servethis
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servethis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-18 00:00:00.000000000Z
12
+ date: 2012-01-13 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: A small gem that provides an executable to run a WEBrick with specified
15
15
  document root.
@@ -26,6 +26,7 @@ files:
26
26
  - Rakefile
27
27
  - bin/servethis
28
28
  - lib/servethis.rb
29
+ - lib/servethis/noncachingfilehandler.rb
29
30
  - lib/servethis/version.rb
30
31
  - servethis.gemspec
31
32
  homepage: ''