roda 3.19.0 → 3.20.0
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 +4 -0
- data/doc/release_notes/3.20.0.txt +7 -0
- data/lib/roda.rb +4 -1
- data/lib/roda/plugins/drop_body.rb +12 -3
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/drop_body_spec.rb +5 -1
- data/spec/plugin/sinatra_helpers_spec.rb +0 -1
- data/spec/response_spec.rb +15 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bce3cf55fdec3d303d3d78b6e190046b38619e9ab296b63575962864535339e5
|
4
|
+
data.tar.gz: 874904308a03694809bd777c406ed94e1cefcc11bb9d7e748dd860a22c853d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c08ac192ce7a3609b968404e4a3bf232ad7d12d1e70ed3e0c3306fea13ddf91bbf746bff47ec746acfc3481c5bfbaed3d7916dbf44c88c9b7f4d8855be64358
|
7
|
+
data.tar.gz: c3e6e9d50efc13dcd202379a76fef8ad6305c29f38954c8ed340ce7bd274b0ffe792cecb69a8ec0ea37aebc0d9fe1aeda16ea87d50f0f8892c1d805121f635ee
|
data/CHANGELOG
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
= Improvements
|
2
|
+
|
3
|
+
* For empty responses with status code 205, a Content-Length header
|
4
|
+
is now added with a value of 0, for better conformance to RFC 7232.
|
5
|
+
|
6
|
+
Similarly, when using the drop_body plugin, responses with status
|
7
|
+
code 205 now have a Content-Length header added with a value of 0.
|
data/lib/roda.rb
CHANGED
@@ -1312,8 +1312,11 @@ WARNING
|
|
1312
1312
|
|
1313
1313
|
if b.empty?
|
1314
1314
|
s = @status || 404
|
1315
|
-
if (s == 304 || s == 204 ||
|
1315
|
+
if (s == 304 || s == 204 || (s >= 100 && s <= 199))
|
1316
1316
|
h.delete("Content-Type")
|
1317
|
+
elsif s == 205
|
1318
|
+
h.delete("Content-Type")
|
1319
|
+
h["Content-Length"] = '0'
|
1317
1320
|
else
|
1318
1321
|
h["Content-Length"] ||= '0'
|
1319
1322
|
end
|
@@ -6,22 +6,31 @@ class Roda
|
|
6
6
|
# The drop_body plugin automatically drops the body and
|
7
7
|
# Content-Type/Content-Length headers from the response if
|
8
8
|
# the response status indicates that the response should
|
9
|
-
# not include a body (response statuses 100, 101, 102, 204,
|
10
|
-
# and 304).
|
9
|
+
# not include a body (response statuses 100, 101, 102, 204,
|
10
|
+
# and 304). For response status 205, the body and Content-Type
|
11
|
+
# headers are dropped, but the Content-length header is set to
|
12
|
+
# '0' instead of being dropped.
|
11
13
|
module DropBody
|
12
14
|
module ResponseMethods
|
13
15
|
DROP_BODY_STATUSES = [100, 101, 102, 204, 205, 304].freeze
|
16
|
+
RodaPlugins.deprecate_constant(self, :DROP_BODY_STATUSES)
|
14
17
|
|
15
18
|
# If the response status indicates a body should not be
|
16
19
|
# returned, use an empty body and remove the Content-Length
|
17
20
|
# and Content-Type headers.
|
18
21
|
def finish
|
19
22
|
r = super
|
20
|
-
|
23
|
+
case r[0]
|
24
|
+
when 100, 101, 102, 204, 304
|
21
25
|
r[2] = EMPTY_ARRAY
|
22
26
|
h = r[1]
|
23
27
|
h.delete("Content-Length")
|
24
28
|
h.delete("Content-Type")
|
29
|
+
when 205
|
30
|
+
r[2] = EMPTY_ARRAY
|
31
|
+
h = r[1]
|
32
|
+
h["Content-Length"] = '0'
|
33
|
+
h.delete("Content-Type")
|
25
34
|
end
|
26
35
|
r
|
27
36
|
end
|
data/lib/roda/version.rb
CHANGED
@@ -7,12 +7,16 @@ describe "drop_body plugin" do
|
|
7
7
|
response.write('a')
|
8
8
|
end
|
9
9
|
|
10
|
-
[101, 102, 204,
|
10
|
+
[101, 102, 204, 304].each do |i|
|
11
11
|
body(i.to_s).must_equal ''
|
12
12
|
header('Content-Type', i.to_s).must_be_nil
|
13
13
|
header('Content-Length', i.to_s).must_be_nil
|
14
14
|
end
|
15
15
|
|
16
|
+
body('205').must_equal ''
|
17
|
+
header('Content-Type', '205').must_be_nil
|
18
|
+
header('Content-Length', '205').must_equal '0'
|
19
|
+
|
16
20
|
body('200').must_equal 'a'
|
17
21
|
header('Content-Type', '200').must_equal 'text/html'
|
18
22
|
header('Content-Length', '200').must_equal '1'
|
data/spec/response_spec.rb
CHANGED
@@ -65,14 +65,26 @@ describe "response #finish" do
|
|
65
65
|
header('Content-Length').must_equal '1'
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
[204, 304, 100].each do |status|
|
69
|
+
it "should not set Content-Type or Content-Length header on a #{status} response" do
|
70
|
+
app do |r|
|
71
|
+
response.status = status
|
72
|
+
throw :halt, response.finish
|
73
|
+
end
|
74
|
+
|
75
|
+
header('Content-Type').must_be_nil
|
76
|
+
header('Content-Length').must_be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not set Content-Type header on a 205 response, but should set a Content-Length header" do
|
69
81
|
app do |r|
|
70
|
-
response.status =
|
82
|
+
response.status = 205
|
71
83
|
throw :halt, response.finish
|
72
84
|
end
|
73
85
|
|
74
86
|
header('Content-Type').must_be_nil
|
75
|
-
header('Content-Length').
|
87
|
+
header('Content-Length').must_equal '0'
|
76
88
|
end
|
77
89
|
|
78
90
|
it "should not overwrite existing status" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -216,6 +216,7 @@ extra_rdoc_files:
|
|
216
216
|
- doc/release_notes/3.17.0.txt
|
217
217
|
- doc/release_notes/3.18.0.txt
|
218
218
|
- doc/release_notes/3.19.0.txt
|
219
|
+
- doc/release_notes/3.20.0.txt
|
219
220
|
files:
|
220
221
|
- CHANGELOG
|
221
222
|
- MIT-LICENSE
|
@@ -271,6 +272,7 @@ files:
|
|
271
272
|
- doc/release_notes/3.18.0.txt
|
272
273
|
- doc/release_notes/3.19.0.txt
|
273
274
|
- doc/release_notes/3.2.0.txt
|
275
|
+
- doc/release_notes/3.20.0.txt
|
274
276
|
- doc/release_notes/3.3.0.txt
|
275
277
|
- doc/release_notes/3.4.0.txt
|
276
278
|
- doc/release_notes/3.5.0.txt
|