turnout 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 093d5c969fb4f0ea26db9679f85d1eca0319f165
4
- data.tar.gz: 42b2239d5572ec322177e82e321546402e0adf17
3
+ metadata.gz: 8033fc6c8101025a040f77b47beba1f1c709d544
4
+ data.tar.gz: 99ef866a762fa021409acd0fc5cebc55e0906b99
5
5
  SHA512:
6
- metadata.gz: 3706cb1f72548de9f327ceac66c3e207b9820439789f66e338a4d0eaf8a6dfdd3b92acea36cf4dc1101dfbfed70dd2b28657dc976334ebf21c11311e8bf5dfe1
7
- data.tar.gz: bc623d45eecb3f4ee28dfa26c6d28d276ffae6cfb17c662c0ce23e37c922288f9105af2695de9ea6187e4ee3e757fcbdded4a848ce6365b2ef3e5a7e58b6a1e6
6
+ metadata.gz: 904759426bb7b76da10209669cca7c0212819f929103ead32f19dd5c3dee93000f8573b71fa837bfdb3d5a485700706d01eaf2054693568d0760630b6e693080
7
+ data.tar.gz: b2f4de219c7c83a2ca2304354a608533a5b53ae1747a853557ccb398491bf0dce7f264775c6d27793f53f08a349283176070c21e9946d4ee009ae9ee38c9a394
data/README.md CHANGED
@@ -101,7 +101,8 @@ Turnout can be configured in two different ways:
101
101
  named_maintenance_file_paths: {app: 'tmp/app.yml', server: '/tmp/server.yml'},
102
102
  default_maintenance_page: Turnout::MaintenancePage::JSON,
103
103
  default_reason: 'Somebody googled Google!',
104
- default_response_code: 418
104
+ default_response_code: 418,
105
+ default_retry_after: 3600
105
106
  ```
106
107
 
107
108
  2. __Using a config block__
@@ -113,6 +114,7 @@ Turnout can be configured in two different ways:
113
114
  config.default_maintenance_page = Turnout::MaintenancePage::JSON
114
115
  config.default_reason = 'Somebody googled Google!'
115
116
  config.default_response_code = 418
117
+ config.default_retry_after = 3600
116
118
  end
117
119
  ```
118
120
 
@@ -128,6 +130,7 @@ Turnout.configure do |config|
128
130
  config.default_maintenance_page = Turnout::MaintenancePage::HTML
129
131
  config.default_reason = "The site is temporarily down for maintenance.\nPlease check back soon."
130
132
  config.default_response_code = 503
133
+ config.default_retry_after = 7200
131
134
  end
132
135
  ```
133
136
 
@@ -168,4 +171,5 @@ allowed_ips:
168
171
  - 127.0.0.1
169
172
  - 192.168.0.0/24
170
173
  response_code: 503
174
+ retry_after: 3600
171
175
  ```
data/lib/rack/turnout.rb CHANGED
@@ -20,7 +20,7 @@ class Rack::Turnout
20
20
  page_class = Turnout::MaintenancePage.best_for(env)
21
21
  page = page_class.new(settings.reason)
22
22
 
23
- page.rack_response(settings.response_code)
23
+ page.rack_response(settings.response_code, settings.retry_after)
24
24
  else
25
25
  @app.call(env)
26
26
  end
@@ -1,6 +1,7 @@
1
1
  module Turnout
2
2
  class Configuration
3
- SETTINGS = [:app_root, :named_maintenance_file_paths, :default_maintenance_page, :default_reason, :default_response_code]
3
+ SETTINGS = [:app_root, :named_maintenance_file_paths, :default_maintenance_page, :default_reason,
4
+ :default_response_code, :default_retry_after]
4
5
 
5
6
  SETTINGS.each do |setting|
6
7
  attr_accessor setting
@@ -12,6 +13,7 @@ module Turnout
12
13
  @default_maintenance_page = Turnout::MaintenancePage::HTML
13
14
  @default_reason = "The site is temporarily down for maintenance.\nPlease check back soon."
14
15
  @default_response_code = 503
16
+ @default_retry_after = 7200 # 2 hours by default
15
17
  end
16
18
 
17
19
  def app_root
@@ -5,7 +5,7 @@ module Turnout
5
5
  class MaintenanceFile
6
6
  attr_reader :path
7
7
 
8
- SETTINGS = [:reason, :allowed_paths, :allowed_ips, :response_code]
8
+ SETTINGS = [:reason, :allowed_paths, :allowed_ips, :response_code, :retry_after]
9
9
  attr_reader *SETTINGS
10
10
 
11
11
  def initialize(path)
@@ -14,6 +14,7 @@ module Turnout
14
14
  @allowed_paths = []
15
15
  @allowed_ips = []
16
16
  @response_code = Turnout.config.default_response_code
17
+ @retry_after = Turnout.config.default_retry_after
17
18
 
18
19
  import_yaml if exists?
19
20
  end
@@ -72,6 +73,10 @@ module Turnout
72
73
 
73
74
  private
74
75
 
76
+ def retry_after=(value)
77
+ @retry_after = value
78
+ end
79
+
75
80
  def reason=(reason)
76
81
  @reason = reason.to_s
77
82
  end
@@ -7,8 +7,9 @@ module Turnout
7
7
  @reason = reason
8
8
  end
9
9
 
10
- def rack_response(code = Turnout.config.default_response_code)
11
- [code, headers, body]
10
+ def rack_response(code = nil, retry_after = nil)
11
+ code ||= Turnout.config.default_response_code
12
+ [code, headers(retry_after), body]
12
13
  end
13
14
 
14
15
  # Override with an array of media type strings. i.e. text/html
@@ -29,8 +30,11 @@ module Turnout
29
30
  MaintenancePage.all << subclass
30
31
  end
31
32
 
32
- def headers
33
- {'Content-Type' => media_types.first, 'Content-Length' => length}
33
+ def headers(retry_after = nil)
34
+ headers = {'Content-Type' => media_types.first, 'Content-Length' => length}
35
+ # Include the Retry-After header unless it wasn't specified
36
+ headers['Retry-After'] = retry_after.to_s unless retry_after.nil?
37
+ headers
34
38
  end
35
39
 
36
40
  def length
@@ -1,3 +1,3 @@
1
1
  module Turnout
2
- VERSION = '2.0.1'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -129,4 +129,3 @@ signing_key:
129
129
  specification_version: 4
130
130
  summary: A Rack based maintenance mode plugin for Rails
131
131
  test_files: []
132
- has_rdoc: