rack 3.1.6 → 3.1.8

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
  SHA256:
3
- metadata.gz: eaf18cf63641b74f599535734eddaf9886c6ffa7f7b00d9aca768715b25498f9
4
- data.tar.gz: 375ef784b899a1f936505dfffef3d6da3ee0f546e0f90d475a9a4db3264281cc
3
+ metadata.gz: cd9b9438930771f3687ff42be3f3506df2faeea5d947d8ed4fa9e5eec1b5970c
4
+ data.tar.gz: 170b7d3e30e472e5a5403f9bb889f37b60e4e9eced41e94f97a88d848e5c2fb4
5
5
  SHA512:
6
- metadata.gz: 41667c1b8b3e3fe9ac3dd9c22f456a8eb5b756c310c28af98dd7b9ce998eed1a224c39c680019dabb3dedd32cff762d1274a63770f2372a12874f92d026713a6
7
- data.tar.gz: ca3837da3ae9a4bf02cf540661c00755e9db416d6c2b268e92df759f77a882646da3b3cb229668ccc409d0764fccb70fcba34134cbece934927adda5a14e5564
6
+ metadata.gz: 0a5c0c56cda8181c7ec4e87a348b54a22938d4c450a9647fbbf07aaec37282ff89230d3964ba0dfd9f5bc7f7e60d99eaf704636de143704c5e9156120bd04624
7
+ data.tar.gz: eeef987e1c6dc77ff1fc40e5cc0e37bde704d354c62217a834e6a4d36828900a71dac09e591a9743273fc5ea678bf603d36c3e165f9c7dbfa1759301c42f957f
data/CHANGELOG.md CHANGED
@@ -2,8 +2,23 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. For info on how to format all future additions to this file please reference [Keep A Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
+ ## [3.1.8] - 2024-10-14
6
+
7
+ - Resolve deprecation warnings about uri `DEFAULT_PARSER`. ([#2249](https://github.com/rack/rack/pull/2249), [@earlopain])
8
+
9
+ ## [3.1.7] - 2024-07-11
10
+
11
+ ### Fixed
12
+
13
+ - Do not remove escaped opening/closing quotes for content-disposition filenames. ([#2229](https://github.com/rack/rack/pull/2229), [@jeremyevans])
14
+ - Fix encoding setting for non-binary IO-like objects in MockRequest#env_for. ([#2227](https://github.com/rack/rack/pull/2227), [@jeremyevans])
15
+ - `Rack::Response` should not generate invalid `content-length` header. ([#2219](https://github.com/rack/rack/pull/2219), [@ioquatix])
16
+ - Allow empty PATH_INFO. ([#2214](https://github.com/rack/rack/pull/2214), [@ioquatix])
17
+
5
18
  ## [3.1.6] - 2024-07-03
6
19
 
20
+ ### Fixed
21
+
7
22
  - Fix several edge cases in `Rack::Request#parse_http_accept_header`'s implementation. ([#2226](https://github.com/rack/rack/pull/2226), [@ioquatix])
8
23
 
9
24
  ## [3.1.5] - 2024-07-02
@@ -23,47 +38,66 @@ All notable changes to this project will be documented in this file. For info on
23
38
  ### Fixed
24
39
 
25
40
  - Fix passing non-strings to `Rack::Utils.escape_html`. ([#2202](https://github.com/rack/rack/pull/2202), [@earlopain])
26
- - `Rack::MockResponse` gracefully handles empty cookies ([#2203](https://github.com/rack/rack/pull/2203) [@wynksaiddestroy](https://github.com/wynksaiddestroy))
41
+ - `Rack::MockResponse` gracefully handles empty cookies ([#2203](https://github.com/rack/rack/pull/2203) [@wynksaiddestroy])
27
42
 
28
43
  ## [3.1.2] - 2024-06-11
29
44
 
30
- ## Changed
31
-
32
45
  - `Rack::Response` will take in to consideration chunked encoding responses ([#2204](https://github.com/rack/rack/pull/2204), [@tenderlove])
33
46
 
34
47
  ## [3.1.1] - 2024-06-11
35
48
 
36
- - Oops, I shouldn't have shipped this
49
+ - Oops! I shouldn't have shipped that
37
50
 
38
51
  ## [3.1.0] - 2024-06-11
39
52
 
53
+ :warning: **This release includes several breaking changes.** Refer to the **Removed** section below for the list of deprecated methods that have been removed in this release.
54
+
55
+ Rack v3.1 is primarily a maintenance release that removes features deprecated in Rack v3.0. Alongside these removals, there are several improvements to the Rack SPEC, mainly focused on enhancing input and output handling. These changes aim to make Rack more efficient and align better with the requirements of server implementations and relevant HTTP specifications.
56
+
40
57
  ### SPEC Changes
41
58
 
42
- - `rack.input` is now optional. ([#1997](https://github.com/rack/rack/pull/1997), [@ioquatix])
43
- - `PATH_INFO` is now validated according to the HTTP/1.1 specification. ([#2117](https://github.com/rack/rack/pull/2117), [@ioquatix])
44
- - `rack.protocol` is an optional environment key and response header for handling connection upgrades.
59
+ - `rack.input` is now optional. ([#1997](https://github.com/rack/rack/pull/1997), [#2018](https://github.com/rack/rack/pull/2018), [@ioquatix])
60
+ - `PATH_INFO` is now validated according to the HTTP/1.1 specification. ([#2117](https://github.com/rack/rack/pull/2117), [#2181](https://github.com/rack/rack/pull/2181), [@ioquatix])
61
+ - `OPTIONS *` is now accepted. ([#2114](https://github.com/rack/rack/pull/2114), [@doriantaylor](https://github.com/doriantaylor))
62
+ - Introduce optional `rack.protocol` request and response header for handling connection upgrades. ([#1954](https://github.com/rack/rack/pull/1954), [@ioquatix])
45
63
 
46
64
  ### Added
47
65
 
66
+ - Introduce `Rack::Multipart::MissingInputError` for improved handling of missing input in `#parse_multipart`. ([#2018](https://github.com/rack/rack/pull/2018), [@ioquatix])
48
67
  - Introduce `module Rack::BadRequest` which is included in multipart and query parser errors. ([#2019](https://github.com/rack/rack/pull/2019), [@ioquatix])
49
- - Add `.mjs` MIME type ([#2057](https://github.com/rack/rack/pull/2057), [@axilleas])
50
- - `set_cookie_header` utility now supports the `partitioned` cookie attribute. This is required by Chrome in some embedded contexts. ([#2131](https://github.com/rack/rack/pull/2131), [@flavio-b])
51
- - `rack.early_hints` is now officially supported as an optional feature (already implemented by Unicorn, Puma, and Falcon). ([#1831](https://github.com/rack/rack/pull/1831), [@casperisfine, @jeremyevans])
68
+ - Add `.mjs` MIME type ([#2057](https://github.com/rack/rack/pull/2057), [@axilleas](https://github.com/axilleas))
69
+ - `set_cookie_header` utility now supports the `partitioned` cookie attribute. This is required by Chrome in some embedded contexts. ([#2131](https://github.com/rack/rack/pull/2131), [@flavio-b](https://github.com/flavio-b))
70
+ - Introduce `rack.early_hints` for sending `103 Early Hints` informational responses. ([#1831](https://github.com/rack/rack/pull/1831), [@casperisfine](https://github.com/casperisfine), [@jeremyevans])
52
71
 
53
72
  ### Changed
54
73
 
55
- - `rack.input` is now optional, and if missing, will raise an error. Use this to fail on multipart parsing a request without an input body. ([#2018](https://github.com/rack/rack/pull/2018), [@ioquatix])
56
- - MIME type for JavaScript files (`.js`) changed from `application/javascript` to `text/javascript` ([`1bd0f15`](https://github.com/rack/rack/commit/1bd0f1597d8f4a90d47115f3e156a8ce7870c9c8))
74
+ - MIME type for JavaScript files (`.js`) changed from `application/javascript` to `text/javascript` ([`1bd0f15`](https://github.com/rack/rack/commit/1bd0f1597d8f4a90d47115f3e156a8ce7870c9c8), [@ioquatix])
57
75
  - Update MIME types associated to `.ttf`, `.woff`, `.woff2` and `.otf` extensions to use mondern `font/*` types. ([#2065](https://github.com/rack/rack/pull/2065), [@davidstosik])
58
76
  - `Rack::Utils.escape_html` is now delegated to `CGI.escapeHTML`. `'` is escaped to `#39;` instead of `#x27;`. (decimal vs hexadecimal) ([#2099](https://github.com/rack/rack/pull/2099), [@JunichiIto](https://github.com/JunichiIto))
77
+ - Clarify use of `@buffered` and only update `content-length` when `Rack::Response#finish` is invoked. ([#2149](https://github.com/rack/rack/pull/2149), [@ioquatix])
78
+
79
+ ### Deprecated
80
+
81
+ - Deprecate automatic cache invalidation in `Request#{GET,POST}` ([#2073](https://github.com/rack/rack/pull/2073), [@jeremyevans])
59
82
  - Only cookie keys that are not valid according to the HTTP specifications are escaped. We are planning to deprecate this behaviour, so now a deprecation message will be emitted in this case. In the future, invalid cookie keys may not be accepted. ([#2191](https://github.com/rack/rack/pull/2191), [@ioquatix])
83
+ - `Rack::Logger` is deprecated. ([#2197](https://github.com/rack/rack/pull/2197), [@ioquatix])
84
+ - Add fallback lookup and deprecation warning for obsolete status symbols. ([#2137](https://github.com/rack/rack/pull/2137), [@wtn](https://github.com/wtn))
85
+ - Deprecate `Rack::Request#values_at`, use `request.params.values_at` instead ([#2183](https://github.com/rack/rack/pull/2183), [@ioquatix])
60
86
 
61
87
  ### Removed
62
88
 
63
- - Remove non-standard status codes 306, 509, & 510 and update descriptions for 413, 422, & 451. ([#2137](https://github.com/rack/rack/pull/2137), [@wtn])
64
- - Add fallback lookup and deprecation warning for obsolete status symbols. ([#2137](https://github.com/rack/rack/pull/2137), [@wtn])
65
- - Deprecate automatic cache invalidation in `Request#{GET,POST}` ([#2073](https://github.com/rack/rack/pull/2073) ([@jeremyevans])
66
- - `Rack::Logger` is deprecated. ([#2197](https://github.com/rack/rack/pull/2197), [@ioquatix])
89
+ - Remove deprecated `Rack::Auth::Digest` with no replacement. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
90
+ - Remove deprecated `Rack::Cascade::NotFound` with no replacement. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
91
+ - Remove deprecated `Rack::Chunked` with no replacement. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
92
+ - Remove deprecated `Rack::File`, use `Rack::Files` instead. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
93
+ - Remove deprecated `Rack::QueryParser` `key_space_limit` parameter with no replacement. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
94
+ - Remove deprecated `Rack::Response#header`, use `Rack::Response#headers` instead. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
95
+ - Remove deprecated cookie methods from `Rack::Utils`: `add_cookie_to_header`, `make_delete_cookie_header`, `add_remove_cookie_to_header`. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
96
+ - Remove deprecated `Rack::Utils::HeaderHash`. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
97
+ - Remove deprecated `Rack::VERSION`, `Rack::VERSION_STRING`, `Rack.version`, use `Rack.release` instead. ([#1966](https://github.com/rack/rack/pull/1966), [@ioquatix])
98
+ - Remove non-standard status codes 306, 509, & 510 and update descriptions for 413, 422, & 451. ([#2137](https://github.com/rack/rack/pull/2137), [@wtn](https://github.com/wtn))
99
+ - Remove any dependency on `transfer-encoding: chunked`. ([#2195](https://github.com/rack/rack/pull/2195), [@ioquatix])
100
+ - Remove deprecated `Rack::Request#[]`, use `request.params[key]` instead ([#2183](https://github.com/rack/rack/pull/2183), [@ioquatix])
67
101
 
68
102
  ### Fixed
69
103
 
data/SPEC.rdoc CHANGED
@@ -130,7 +130,7 @@ There are the following restrictions:
130
130
  * There may be a valid early hints callback in <tt>rack.early_hints</tt>
131
131
  * The <tt>REQUEST_METHOD</tt> must be a valid token.
132
132
  * The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>
133
- * The <tt>PATH_INFO</tt>, if provided, must be a valid request target.
133
+ * The <tt>PATH_INFO</tt>, if provided, must be a valid request target or an empty string.
134
134
  * Only <tt>OPTIONS</tt> requests may have <tt>PATH_INFO</tt> set to <tt>*</tt> (asterisk-form).
135
135
  * Only <tt>CONNECT</tt> requests may have <tt>PATH_INFO</tt> set to an authority (authority-form). Note that in HTTP/2+, the authority-form is not a valid request target.
136
136
  * <tt>CONNECT</tt> and <tt>OPTIONS</tt> requests must not have <tt>PATH_INFO</tt> set to a URI (absolute-form).
data/lib/rack/lint.rb CHANGED
@@ -12,7 +12,7 @@ module Rack
12
12
 
13
13
  class Lint
14
14
  REQUEST_PATH_ORIGIN_FORM = /\A\/[^#]*\z/
15
- REQUEST_PATH_ABSOLUTE_FORM = /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
15
+ REQUEST_PATH_ABSOLUTE_FORM = /\A#{Utils::URI_PARSER.make_regexp}\z/
16
16
  REQUEST_PATH_AUTHORITY_FORM = /\A[^\/:]+:\d+\z/
17
17
  REQUEST_PATH_ASTERISK_FORM = '*'
18
18
 
@@ -361,7 +361,7 @@ module Rack
361
361
  raise LintError, "SCRIPT_NAME must start with /"
362
362
  end
363
363
 
364
- ## * The <tt>PATH_INFO</tt>, if provided, must be a valid request target.
364
+ ## * The <tt>PATH_INFO</tt>, if provided, must be a valid request target or an empty string.
365
365
  if env.include?(PATH_INFO)
366
366
  case env[PATH_INFO]
367
367
  when REQUEST_PATH_ASTERISK_FORM
@@ -381,6 +381,8 @@ module Rack
381
381
  end
382
382
  when REQUEST_PATH_ORIGIN_FORM
383
383
  ## * Otherwise, <tt>PATH_INFO</tt> must start with a <tt>/</tt> and must not include a fragment part starting with '#' (origin-form).
384
+ when ""
385
+ # Empty string is okay.
384
386
  else
385
387
  raise LintError, "PATH_INFO must start with a '/' and must not include a fragment part starting with '#' (origin-form)"
386
388
  end
@@ -139,23 +139,13 @@ module Rack
139
139
  end
140
140
  end
141
141
 
142
- input = opts[:input]
143
- if String === input
144
- rack_input = StringIO.new(input)
145
- rack_input.set_encoding(Encoding::BINARY)
146
- else
147
- if input.respond_to?(:encoding) && input.encoding != Encoding::BINARY
148
- warn "input encoding not binary", uplevel: 1
149
- if input.respond_to?(:set_encoding)
150
- input.set_encoding(Encoding::BINARY)
151
- else
152
- raise ArgumentError, "could not coerce input to binary encoding"
153
- end
154
- end
155
- rack_input = input
142
+ rack_input = opts[:input]
143
+ if String === rack_input
144
+ rack_input = StringIO.new(rack_input)
156
145
  end
157
146
 
158
147
  if rack_input
148
+ rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
159
149
  env[RACK_INPUT] = rack_input
160
150
 
161
151
  env["CONTENT_LENGTH"] ||= env[RACK_INPUT].size.to_s if env[RACK_INPUT].respond_to?(:size)
@@ -394,7 +394,6 @@ module Rack
394
394
  filename = normalize_filename(filename || '')
395
395
  filename.force_encoding(find_encoding(encoding))
396
396
  elsif filename
397
- filename = $1 if filename =~ /^"(.*)"$/
398
397
  filename = normalize_filename(filename)
399
398
  end
400
399
 
data/lib/rack/response.rb CHANGED
@@ -72,7 +72,8 @@ module Rack
72
72
  if body.nil?
73
73
  @body = []
74
74
  @buffered = true
75
- @length = 0
75
+ # Body is unspecified - it may be a buffered response, or it may be a HEAD response.
76
+ @length = nil
76
77
  elsif body.respond_to?(:to_str)
77
78
  @body = [body]
78
79
  @buffered = true
@@ -80,7 +81,7 @@ module Rack
80
81
  else
81
82
  @body = body
82
83
  @buffered = nil # undetermined as of yet.
83
- @length = 0
84
+ @length = nil
84
85
  end
85
86
 
86
87
  yield self if block_given?
@@ -110,14 +111,15 @@ module Rack
110
111
  close
111
112
  return [@status, @headers, []]
112
113
  else
113
- if @length && @length > 0 && !chunked?
114
- set_header CONTENT_LENGTH, @length.to_s
115
- end
116
-
117
114
  if block_given?
115
+ # We don't add the content-length here as the user has provided a block that can #write additional chunks to the body.
118
116
  @block = block
119
117
  return [@status, @headers, self]
120
118
  else
119
+ # If we know the length of the body, set the content-length header... except if we are chunked? which is a legacy special case where the body might already be encoded and thus the actual encoded body length and the content-length are likely to be different.
120
+ if @length && !chunked?
121
+ @headers[CONTENT_LENGTH] = @length.to_s
122
+ end
121
123
  return [@status, @headers, @body]
122
124
  end
123
125
  end
@@ -135,7 +137,9 @@ module Rack
135
137
  end
136
138
  end
137
139
 
138
- # Append to body and update content-length.
140
+ # Append a chunk to the response body.
141
+ #
142
+ # Converts the response into a buffered response if it wasn't already.
139
143
  #
140
144
  # NOTE: Do not mix #write and direct #body access!
141
145
  #
@@ -336,16 +340,13 @@ module Rack
336
340
  # Turn the user supplied body into a buffered array:
337
341
  body = @body
338
342
  @body = Array.new
339
- @length = 0
343
+ @buffered = true
340
344
 
341
345
  body.each do |part|
342
346
  @writer.call(part.to_s)
343
347
  end
344
348
 
345
349
  body.close if body.respond_to?(:close)
346
-
347
- # We have converted the body into an Array:
348
- @buffered = true
349
350
  else
350
351
  # We don't know how to buffer the user-supplied body:
351
352
  @buffered = false
@@ -359,7 +360,11 @@ module Rack
359
360
  chunk = chunk.dup unless chunk.frozen?
360
361
  @body << chunk
361
362
 
362
- @length += chunk.bytesize
363
+ if @length
364
+ @length += chunk.bytesize
365
+ elsif @buffered
366
+ @length = chunk.bytesize
367
+ end
363
368
 
364
369
  return chunk
365
370
  end
data/lib/rack/utils.rb CHANGED
@@ -24,6 +24,7 @@ module Rack
24
24
  DEFAULT_SEP = QueryParser::DEFAULT_SEP
25
25
  COMMON_SEP = QueryParser::COMMON_SEP
26
26
  KeySpaceConstrainedParams = QueryParser::Params
27
+ URI_PARSER = defined?(::URI::RFC2396_PARSER) ? ::URI::RFC2396_PARSER : ::URI::DEFAULT_PARSER
27
28
 
28
29
  class << self
29
30
  attr_accessor :default_query_parser
@@ -43,13 +44,13 @@ module Rack
43
44
  # Like URI escaping, but with %20 instead of +. Strictly speaking this is
44
45
  # true URI escaping.
45
46
  def escape_path(s)
46
- ::URI::DEFAULT_PARSER.escape s
47
+ URI_PARSER.escape s
47
48
  end
48
49
 
49
50
  # Unescapes the **path** component of a URI. See Rack::Utils.unescape for
50
51
  # unescaping query parameters or form components.
51
52
  def unescape_path(s)
52
- ::URI::DEFAULT_PARSER.unescape s
53
+ URI_PARSER.unescape s
53
54
  end
54
55
 
55
56
  # Unescapes a URI escaped string with +encoding+. +encoding+ will be the
data/lib/rack/version.rb CHANGED
@@ -12,7 +12,7 @@
12
12
  # so it should be enough just to <tt>require 'rack'</tt> in your code.
13
13
 
14
14
  module Rack
15
- RELEASE = "3.1.6"
15
+ RELEASE = "3.1.8"
16
16
 
17
17
  # Return the Rack release as a dotted string.
18
18
  def self.release
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leah Neukirchen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest