lotus-controller 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/lotus/action/head.rb +58 -1
- data/lib/lotus/controller/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac7b8bf14852940993b526910f912f4c8a84398
|
4
|
+
data.tar.gz: 0d1987258f25f24b2e3b797441e557d76e704184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ef726ad1e57674ef8215aa9cb1aa4277f8ef29518d89e893f66dc8a631e7f9387f118f77d6dcacfdbc8ff8595e46798455ef6d2175ca12a6a365b33396b2e5
|
7
|
+
data.tar.gz: 4acdfbe61468ee74824894b1c060b8068a612c619acfab62c283284214e17c694a43c3c940ae46d3c17548ffbc2c98d48740a04b6396f1407467afc37ff7c2c7
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Lotus::Controller
|
2
2
|
Complete, fast and testable actions for Rack
|
3
3
|
|
4
|
+
## v0.4.6 - 2015-12-04
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Allow to force custom headers for responses that shouldn't include them (eg 204). Override `#keep_response_header?(header)` in action
|
7
|
+
|
4
8
|
## v0.4.5 - 2015-09-30
|
5
9
|
### Added
|
6
10
|
- [Theo Felippe] Added configuration entries: `#default_request_format` and `default_response_format`.
|
data/lib/lotus/action/head.rb
CHANGED
@@ -50,7 +50,7 @@ module Lotus
|
|
50
50
|
|
51
51
|
if _requires_no_body?
|
52
52
|
@_body = nil
|
53
|
-
@headers.reject! {
|
53
|
+
@headers.reject! {|header,_| !keep_response_header?(header) }
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -60,6 +60,63 @@ module Lotus
|
|
60
60
|
def _requires_no_body?
|
61
61
|
HTTP_STATUSES_WITHOUT_BODY.include?(@_status) || head?
|
62
62
|
end
|
63
|
+
|
64
|
+
private
|
65
|
+
# According to RFC 2616, when a response MUST have an empty body, it only
|
66
|
+
# allows Entity Headers.
|
67
|
+
#
|
68
|
+
# For instance, a <tt>204</tt> doesn't allow <tt>Content-Type</tt> or any
|
69
|
+
# other custom header.
|
70
|
+
#
|
71
|
+
# This restriction is enforced by <tt>Lotus::Action::Head#finish</tt>.
|
72
|
+
#
|
73
|
+
# However, there are cases that demand to bypass this rule to set meta
|
74
|
+
# informations via headers.
|
75
|
+
#
|
76
|
+
# An example is a <tt>DELETE</tt> request for a JSON API application.
|
77
|
+
# It returns a <tt>204</tt> but still wants to specify the rate limit
|
78
|
+
# quota via <tt>X-Rate-Limit</tt>.
|
79
|
+
#
|
80
|
+
# @since x.x.x
|
81
|
+
# @api public
|
82
|
+
#
|
83
|
+
# @see Lotus::Action::HEAD#finish
|
84
|
+
#
|
85
|
+
# @example
|
86
|
+
# require 'lotus/controller'
|
87
|
+
#
|
88
|
+
# module Books
|
89
|
+
# class Destroy
|
90
|
+
# include Lotus::Action
|
91
|
+
#
|
92
|
+
# def call(params)
|
93
|
+
# # ...
|
94
|
+
# self.headers.merge!(
|
95
|
+
# 'Last-Modified' => 'Fri, 27 Nov 2015 13:32:36 GMT',
|
96
|
+
# 'X-Rate-Limit' => '4000',
|
97
|
+
# 'Content-Type' => 'application/json',
|
98
|
+
# 'X-No-Pass' => 'true'
|
99
|
+
# )
|
100
|
+
#
|
101
|
+
# self.status = 204
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# private
|
105
|
+
#
|
106
|
+
# def keep_response_header?(header)
|
107
|
+
# super || header == 'X-Rate-Limit'
|
108
|
+
# end
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# # Only the following headers will be sent:
|
113
|
+
# # * Last-Modified - because we used `super' in the method that respects the HTTP RFC
|
114
|
+
# # * X-Rate-Limit - because we explicitely allow it
|
115
|
+
#
|
116
|
+
# # Both Content-Type and X-No-Pass are removed because they're not allowed
|
117
|
+
def keep_response_header?(header)
|
118
|
+
ENTITY_HEADERS.include?(header)
|
119
|
+
end
|
63
120
|
end
|
64
121
|
end
|
65
122
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|