lotus-controller 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/lotus/action/cookie_jar.rb +15 -1
- data/lib/lotus/action/glue.rb +12 -2
- data/lib/lotus/action/mime.rb +2 -2
- data/lib/lotus/action/rack.rb +32 -0
- data/lib/lotus/action/rack/file.rb +33 -0
- data/lib/lotus/controller/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b4c85e67bcae87918653c05af57ec2961d41900
|
4
|
+
data.tar.gz: e2fb00ab919ee2fbfda7de1785bd9ff38e75df9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b96f037a068a7a653579991b853c586eb2b39687bde6236832c03973007adfb8f4c33966cd69511f7b498e52ee0b0f6ce5e7715c0de8ce9d4d30729cec0553
|
7
|
+
data.tar.gz: 18753964833666f3cca7a8091bb35425960a18fce40ce0c876c705ac57797a4ae46d360e591b4475e369047aea688a00d93adacdfb616fa2cbf165f6d5c0fe61
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Lotus::Controller
|
2
2
|
Complete, fast and testable actions for Rack
|
3
3
|
|
4
|
+
## v0.4.3 - 2015-05-22
|
5
|
+
### Added
|
6
|
+
- [Alfonso Uceda Pompa & Luca Guidi] Introduced `Lotus::Action#send_file`
|
7
|
+
- [Alfonso Uceda Pompa] Set automatically `Expires` option for cookies when it's missing but `Max-Age` is present. Compatibility with old browsers.
|
8
|
+
|
4
9
|
## v0.4.2 - 2015-05-15
|
5
10
|
### Fixed
|
6
11
|
- [Luca Guidi] Ensure `Lotus::Action::Params#to_h` to return `::Hash` at the top level
|
@@ -98,13 +98,25 @@ module Lotus
|
|
98
98
|
# @api private
|
99
99
|
def _merge_default_values(value)
|
100
100
|
cookies_options = if value.is_a? Hash
|
101
|
-
value
|
101
|
+
value.merge! _add_expires_option(value)
|
102
102
|
else
|
103
103
|
{ value: value }
|
104
104
|
end
|
105
105
|
@default_options.merge cookies_options
|
106
106
|
end
|
107
107
|
|
108
|
+
# Add expires option to cookies if :max_age presents
|
109
|
+
#
|
110
|
+
# @since 0.4.3
|
111
|
+
# @api private
|
112
|
+
def _add_expires_option(value)
|
113
|
+
if value.has_key?(:max_age) && !value.has_key?(:expires)
|
114
|
+
{ expires: (Time.now + value[:max_age]) }
|
115
|
+
else
|
116
|
+
{}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
108
120
|
# Extract the cookies from the raw Rack env.
|
109
121
|
#
|
110
122
|
# This implementation is borrowed from Rack::Request#cookies.
|
@@ -116,6 +128,8 @@ module Lotus
|
|
116
128
|
string = env[HTTP_HEADER]
|
117
129
|
|
118
130
|
return hash if string == env[COOKIE_STRING_KEY]
|
131
|
+
# TODO Next Rack 1.6.x version will have ::Rack::Utils.parse_cookies
|
132
|
+
# We can then replace the following lines.
|
119
133
|
hash.clear
|
120
134
|
|
121
135
|
# According to RFC 2109:
|
data/lib/lotus/action/glue.rb
CHANGED
@@ -28,8 +28,8 @@ module Lotus
|
|
28
28
|
|
29
29
|
# Check if the current HTTP request is renderable.
|
30
30
|
#
|
31
|
-
# It verifies if the verb isn't HEAD
|
32
|
-
# the body.
|
31
|
+
# It verifies if the verb isn't HEAD, if the status demands to omit
|
32
|
+
# the body and if it isn't sending a file.
|
33
33
|
#
|
34
34
|
# @return [TrueClass,FalseClass] the result of the check
|
35
35
|
#
|
@@ -37,6 +37,7 @@ module Lotus
|
|
37
37
|
# @since 0.3.2
|
38
38
|
def renderable?
|
39
39
|
!_requires_no_body? &&
|
40
|
+
!sending_file? &&
|
40
41
|
!ADDITIONAL_HTTP_STATUSES_WITHOUT_BODY.include?(@_status)
|
41
42
|
end
|
42
43
|
|
@@ -51,6 +52,15 @@ module Lotus
|
|
51
52
|
super
|
52
53
|
@_env[ENV_KEY] = self
|
53
54
|
end
|
55
|
+
|
56
|
+
# Check if the request's body is a file
|
57
|
+
#
|
58
|
+
# @return [TrueClass,FalseClass] the result of the check
|
59
|
+
#
|
60
|
+
# @since 0.4.3
|
61
|
+
def sending_file?
|
62
|
+
@_body.is_a?(::Rack::File)
|
63
|
+
end
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
data/lib/lotus/action/mime.rb
CHANGED
@@ -252,7 +252,7 @@ module Lotus
|
|
252
252
|
# @see Lotus::Action#finish
|
253
253
|
def finish
|
254
254
|
super
|
255
|
-
headers[CONTENT_TYPE]
|
255
|
+
headers[CONTENT_TYPE] ||= content_type_with_charset
|
256
256
|
end
|
257
257
|
|
258
258
|
# Sets the given format and corresponding content type.
|
@@ -450,7 +450,7 @@ module Lotus
|
|
450
450
|
|
451
451
|
# Patched version of <tt>Rack::Utils.best_q_match</tt>.
|
452
452
|
#
|
453
|
-
# @since
|
453
|
+
# @since 0.4.1
|
454
454
|
# @api private
|
455
455
|
#
|
456
456
|
# @see http://www.rubydoc.info/gems/rack/Rack/Utils#best_q_match-class_method
|
data/lib/lotus/action/rack.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'lotus/action/request'
|
3
3
|
require 'lotus/action/rack/callable'
|
4
|
+
require 'lotus/action/rack/file'
|
4
5
|
|
5
6
|
module Lotus
|
6
7
|
module Action
|
@@ -217,6 +218,37 @@ module Lotus
|
|
217
218
|
@_body = body
|
218
219
|
end
|
219
220
|
|
221
|
+
# Send a file as response.
|
222
|
+
#
|
223
|
+
# It automatically handle the following cases:
|
224
|
+
#
|
225
|
+
# * <tt>Content-Type</tt> and <tt>Content-Length</tt>
|
226
|
+
# * File Not found (returns a 404)
|
227
|
+
# * Conditional GET (via <tt>If-Modified-Since</tt> header)
|
228
|
+
# * Range requests (via <tt>Range</tt> header)
|
229
|
+
#
|
230
|
+
# @param path [String, Pathname] the body of the response
|
231
|
+
# @return [void]
|
232
|
+
#
|
233
|
+
# @since 0.4.3
|
234
|
+
#
|
235
|
+
# @example
|
236
|
+
# require 'lotus/controller'
|
237
|
+
#
|
238
|
+
# class Show
|
239
|
+
# include Lotus::Action
|
240
|
+
#
|
241
|
+
# def call(params)
|
242
|
+
# # ...
|
243
|
+
# send_file Pathname.new('path/to/file')
|
244
|
+
# end
|
245
|
+
# end
|
246
|
+
def send_file(path)
|
247
|
+
result = File.new(path).call(@_env)
|
248
|
+
headers.merge!(result[1])
|
249
|
+
halt result[0], result[2]
|
250
|
+
end
|
251
|
+
|
220
252
|
# Check if the current request is a HEAD
|
221
253
|
#
|
222
254
|
# @return [TrueClass,FalseClass] the result of the check
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rack/file'
|
2
|
+
|
3
|
+
module Lotus
|
4
|
+
module Action
|
5
|
+
module Rack
|
6
|
+
# File to be sent
|
7
|
+
#
|
8
|
+
# @since 0.4.3
|
9
|
+
# @api private
|
10
|
+
#
|
11
|
+
# @see Lotus::Action::Rack#send_file
|
12
|
+
class File
|
13
|
+
# @param path [String,Pathname] file path
|
14
|
+
#
|
15
|
+
# @since 0.4.3
|
16
|
+
# @api private
|
17
|
+
def initialize(path)
|
18
|
+
@file = ::Rack::File.new(nil)
|
19
|
+
@path = path
|
20
|
+
end
|
21
|
+
|
22
|
+
# @since 0.4.3
|
23
|
+
# @api private
|
24
|
+
def call(env)
|
25
|
+
@file.path = @path.to_s
|
26
|
+
@file.serving(env)
|
27
|
+
rescue Errno::ENOENT
|
28
|
+
[404, {}, nil]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/lotus/action/params.rb
|
147
147
|
- lib/lotus/action/rack.rb
|
148
148
|
- lib/lotus/action/rack/callable.rb
|
149
|
+
- lib/lotus/action/rack/file.rb
|
149
150
|
- lib/lotus/action/redirect.rb
|
150
151
|
- lib/lotus/action/request.rb
|
151
152
|
- lib/lotus/action/session.rb
|