Skip to content

Commit ddbd79b

Browse files
committed
Merge pull request #758 from lsylvester/rack-3-support
Rack 3 support
1 parent 893a4d7 commit ddbd79b

File tree

5 files changed

+68
-66
lines changed

5 files changed

+68
-66
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Add support for Rack 3.0. Headers set by sprockets will now be lower case. [#758](https://github.com/rails/sprockets/pull/758)
2+
13
**3.7.5** (Sept 19, 2024)
24

35
* Fix `Sprockets::Base#unescape` #808.

lib/sprockets/server.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,30 @@ def not_modified_response(env, etag)
139139
# Returns a 403 Forbidden response tuple
140140
def forbidden_response(env)
141141
if head_request?(env)
142-
[ 403, { "Content-Type" => "text/plain", "Content-Length" => "0" }, [] ]
142+
[ 403, { "content-type" => "text/plain", "content-length" => "0" }, [] ]
143143
else
144-
[ 403, { "Content-Type" => "text/plain", "Content-Length" => "9" }, [ "Forbidden" ] ]
144+
[ 403, { "content-type" => "text/plain", "content-length" => "9" }, [ "Forbidden" ] ]
145145
end
146146
end
147147

148148
# Returns a 404 Not Found response tuple
149149
def not_found_response(env)
150150
if head_request?(env)
151-
[ 404, { "Content-Type" => "text/plain", "Content-Length" => "0", "X-Cascade" => "pass" }, [] ]
151+
[ 404, { "content-type" => "text/plain", "content-length" => "0", "x-cascade" => "pass" }, [] ]
152152
else
153-
[ 404, { "Content-Type" => "text/plain", "Content-Length" => "9", "X-Cascade" => "pass" }, [ "Not found" ] ]
153+
[ 404, { "content-type" => "text/plain", "content-length" => "9", "x-cascade" => "pass" }, [ "Not found" ] ]
154154
end
155155
end
156156

157157
def method_not_allowed_response
158-
[ 405, { "Content-Type" => "text/plain", "Content-Length" => "18" }, [ "Method Not Allowed" ] ]
158+
[ 405, { "content-type" => "text/plain", "content-length" => "18" }, [ "Method Not Allowed" ] ]
159159
end
160160

161161
def precondition_failed_response(env)
162162
if head_request?(env)
163-
[ 412, { "Content-Type" => "text/plain", "Content-Length" => "0", "X-Cascade" => "pass" }, [] ]
163+
[ 412, { "content-type" => "text/plain", "content-length" => "0", "x-cascade" => "pass" }, [] ]
164164
else
165-
[ 412, { "Content-Type" => "text/plain", "Content-Length" => "19", "X-Cascade" => "pass" }, [ "Precondition Failed" ] ]
165+
[ 412, { "content-type" => "text/plain", "content-length" => "19", "x-cascade" => "pass" }, [ "Precondition Failed" ] ]
166166
end
167167
end
168168

@@ -171,7 +171,7 @@ def precondition_failed_response(env)
171171
def javascript_exception_response(exception)
172172
err = "#{exception.class.name}: #{exception.message}\n (in #{exception.backtrace[0]})"
173173
body = "throw Error(#{err.inspect})"
174-
[ 200, { "Content-Type" => "application/javascript", "Content-Length" => body.bytesize.to_s }, [ body ] ]
174+
[ 200, { "content-type" => "application/javascript", "content-length" => body.bytesize.to_s }, [ body ] ]
175175
end
176176

177177
# Returns a CSS response that hides all elements on the page and
@@ -224,7 +224,7 @@ def css_exception_response(exception)
224224
}
225225
CSS
226226

227-
[ 200, { "Content-Type" => "text/css; charset=utf-8", "Content-Length" => body.bytesize.to_s }, [ body ] ]
227+
[ 200, { "content-type" => "text/css; charset=utf-8", "content-length" => body.bytesize.to_s }, [ body ] ]
228228
end
229229

230230
# Escape special characters for use inside a CSS content("...") string
@@ -245,18 +245,18 @@ def cache_headers(env, etag)
245245
headers = {}
246246

247247
# Set caching headers
248-
headers["Cache-Control"] = "public"
249-
headers["ETag"] = %("#{etag}")
248+
headers["cache-control"] = "public"
249+
headers["etag"] = %("#{etag}")
250250

251251
# If the request url contains a fingerprint, set a long
252252
# expires on the response
253253
if path_fingerprint(env["PATH_INFO"])
254-
headers["Cache-Control"] += ", max-age=31536000"
254+
headers["cache-control"] += ", max-age=31536000"
255255

256256
# Otherwise set `must-revalidate` since the asset could be modified.
257257
else
258-
headers["Cache-Control"] += ", must-revalidate"
259-
headers["Vary"] = "Accept-Encoding"
258+
headers["cache-control"] += ", must-revalidate"
259+
headers["vary"] = "Accept-Encoding"
260260
end
261261

262262
headers
@@ -266,15 +266,15 @@ def headers(env, asset, length)
266266
headers = {}
267267

268268
# Set content length header
269-
headers["Content-Length"] = length.to_s
269+
headers["content-length"] = length.to_s
270270

271271
# Set content type header
272272
if type = asset.content_type
273273
# Set charset param for text/* mime types
274274
if type.start_with?("text/") && asset.charset
275275
type += "; charset=#{asset.charset}"
276276
end
277-
headers["Content-Type"] = type
277+
headers["content-type"] = type
278278
end
279279

280280
headers.merge(cache_headers(env, asset.etag))

sprockets.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
1212
s.executables = ["sprockets"]
1313

1414
s.add_dependency "base64"
15-
s.add_dependency "rack", "> 1", "< 3"
15+
s.add_dependency "rack", ">= 2.2.4", "< 4"
1616
s.add_dependency "concurrent-ruby", "~> 1.0"
1717

1818
s.add_development_dependency "closure-compiler", "~> 1.1"
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
2323
s.add_development_dependency "execjs", "~> 2.0"
2424
s.add_development_dependency "minitest", "~> 5.0"
2525
s.add_development_dependency "nokogiri", "~> 1.3"
26-
s.add_development_dependency "rack-test", "~> 0.6"
26+
s.add_development_dependency "rack-test", "~> 2.0.0"
2727
s.add_development_dependency "rake"
2828
s.add_development_dependency "sass", "~> 3.1"
2929
s.add_development_dependency "uglifier", "~> 2.3"

test/sprockets_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require "sprockets"
33
require "sprockets/environment"
44
require "fileutils"
5+
require "rack/lint"
56

67
old_verbose, $VERBOSE = $VERBOSE, false
78
Encoding.default_external = 'UTF-8'
@@ -205,4 +206,3 @@ def self.silence(&block)
205206
end
206207
end
207208
end
208-

0 commit comments

Comments
 (0)