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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 930b16a28e9acd91a802b03248b36f940ee50f22b387e2e6839b34513b181c19
4
- data.tar.gz: ff504ecc1d793e7af9180742204e219e26838f2187c0538241e2c240d57d4ad9
3
+ metadata.gz: bce3cf55fdec3d303d3d78b6e190046b38619e9ab296b63575962864535339e5
4
+ data.tar.gz: 874904308a03694809bd777c406ed94e1cefcc11bb9d7e748dd860a22c853d18
5
5
  SHA512:
6
- metadata.gz: 472f855ac1ea091a973d5396dd5950147cdee2f72fa4692233e0acca033ed989ad3d7c7aa338c053058b070efaa151de4b40ad475a9a14e70a32a21e81fe0f3c
7
- data.tar.gz: bc8c7417ec1922531a2a535b57ca3528fe0de9731df0aaed520d9e3df22263fa96f23eadf2313284a8f03af3e77addafaf45c1fc0061e3795e01b3dd18024922
6
+ metadata.gz: 0c08ac192ce7a3609b968404e4a3bf232ad7d12d1e70ed3e0c3306fea13ddf91bbf746bff47ec746acfc3481c5bfbaed3d7916dbf44c88c9b7f4d8855be64358
7
+ data.tar.gz: c3e6e9d50efc13dcd202379a76fef8ad6305c29f38954c8ed340ce7bd274b0ffe792cecb69a8ec0ea37aebc0d9fe1aeda16ea87d50f0f8892c1d805121f635ee
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 3.20.0 (2019-05-16)
2
+
3
+ * Set Content-Length header to 0 for empty 205 responses (jeremyevans)
4
+
1
5
  = 3.19.0 (2019-04-12)
2
6
 
3
7
  * Allow assets plugin :timestamp_paths option to be a string to specify a custom separator (jeremyevans)
@@ -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 || s == 205 || (s >= 100 && s <= 199))
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, 205,
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
- if DROP_BODY_STATUSES.include?(r[0])
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
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 19
7
+ RodaMinorVersion = 20
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
@@ -7,12 +7,16 @@ describe "drop_body plugin" do
7
7
  response.write('a')
8
8
  end
9
9
 
10
- [101, 102, 204, 205, 304].each do |i|
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'
@@ -8,7 +8,6 @@ describe "sinatra_helpers plugin" do
8
8
  end
9
9
 
10
10
  def status_app(code, &block)
11
- #code += 2 if [204, 205, 304].include? code
12
11
  block ||= proc{}
13
12
  sin_app do |r|
14
13
  status code
@@ -65,14 +65,26 @@ describe "response #finish" do
65
65
  header('Content-Length').must_equal '1'
66
66
  end
67
67
 
68
- it "should not set Content-Type header on a 204 response" do
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 = 204
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').must_be_nil
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.19.0
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-04-12 00:00:00.000000000 Z
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