Skip to content

Commit 572235a

Browse files
authored
Merge branch 'main' into fix-css-sourcemap-default-charset
2 parents ed0404e + 42f7d5e commit 572235a

27 files changed

+60
-48
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
44

55
- Fix for precompile issues when multiple extensions map to the same MIME type (eg. `.jpeg` / `.jpg`). [#781](https://github.com/rails/sprockets/pull/781)
66
- Fix `application/css-sourcemap+json` charset [#764](https://github.com/rails/sprockets/pull/764)
7+
- Fix compatibility with Rack 2 applications. [#790](https://github.com/rails/sprockets/pull/790)
78

89
## 4.2.0
910

1011
- Rack 3 compatibility. [#758](https://github.com/rails/sprockets/pull/758)
1112
- Fix thread safety of `Sprockets::CachedEnvironment` and `Sprockets::Cache::MemoryStore`. [#771](https://github.com/rails/sprockets/pull/771)
1213
- Add support for Rack 3.0. Headers set by sprockets will now be lower case. [#758](https://github.com/rails/sprockets/pull/758)
1314
- Make `Sprockets::Utils.module_include` thread safe on JRuby. [#759](https://github.com/rails/sprockets/pull/759)
15+
- Fix typo in `asset.rb` file. [#768](https://github.com/rails/sprockets/pull/768)
1416

1517
## 4.1.1
1618

lib/sprockets/asset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def hexdigest
137137
DigestUtils.pack_hexdigest(digest)
138138
end
139139

140-
# Pubic: ETag String of Asset.
140+
# Public: ETag String of Asset.
141141
def etag
142142
version = environment_version
143143

lib/sprockets/server.rb

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require 'set'
33
require 'time'
4-
require 'rack/utils'
4+
require 'rack'
55

66
module Sprockets
77
# `Server` is a concern mixed into `Environment` and
@@ -11,6 +11,16 @@ module Server
1111
# Supported HTTP request methods.
1212
ALLOWED_REQUEST_METHODS = ['GET', 'HEAD'].to_set.freeze
1313

14+
# :stopdoc:
15+
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3")
16+
X_CASCADE = "X-Cascade"
17+
VARY = "Vary"
18+
else
19+
X_CASCADE = "x-cascade"
20+
VARY = "vary"
21+
end
22+
# :startdoc:
23+
1424
# `call` implements the Rack 1.x specification which accepts an
1525
# `env` Hash and returns a three item tuple with the status code,
1626
# headers, and body.
@@ -148,39 +158,39 @@ def not_modified_response(env, etag)
148158
# Returns a 400 Forbidden response tuple
149159
def bad_request_response(env)
150160
if head_request?(env)
151-
[ 400, { "content-type" => "text/plain", "content-length" => "0" }, [] ]
161+
[ 400, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "0" }, [] ]
152162
else
153-
[ 400, { "content-type" => "text/plain", "content-length" => "11" }, [ "Bad Request" ] ]
163+
[ 400, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "11" }, [ "Bad Request" ] ]
154164
end
155165
end
156166

157167
# Returns a 403 Forbidden response tuple
158168
def forbidden_response(env)
159169
if head_request?(env)
160-
[ 403, { "content-type" => "text/plain", "content-length" => "0" }, [] ]
170+
[ 403, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "0" }, [] ]
161171
else
162-
[ 403, { "content-type" => "text/plain", "content-length" => "9" }, [ "Forbidden" ] ]
172+
[ 403, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "9" }, [ "Forbidden" ] ]
163173
end
164174
end
165175

166176
# Returns a 404 Not Found response tuple
167177
def not_found_response(env)
168178
if head_request?(env)
169-
[ 404, { "content-type" => "text/plain", "content-length" => "0", "x-cascade" => "pass" }, [] ]
179+
[ 404, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "0", X_CASCADE => "pass" }, [] ]
170180
else
171-
[ 404, { "content-type" => "text/plain", "content-length" => "9", "x-cascade" => "pass" }, [ "Not found" ] ]
181+
[ 404, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "9", X_CASCADE => "pass" }, [ "Not found" ] ]
172182
end
173183
end
174184

175185
def method_not_allowed_response
176-
[ 405, { "content-type" => "text/plain", "content-length" => "18" }, [ "Method Not Allowed" ] ]
186+
[ 405, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "18" }, [ "Method Not Allowed" ] ]
177187
end
178188

179189
def precondition_failed_response(env)
180190
if head_request?(env)
181-
[ 412, { "content-type" => "text/plain", "content-length" => "0", "x-cascade" => "pass" }, [] ]
191+
[ 412, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "0", X_CASCADE => "pass" }, [] ]
182192
else
183-
[ 412, { "content-type" => "text/plain", "content-length" => "19", "x-cascade" => "pass" }, [ "Precondition Failed" ] ]
193+
[ 412, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "19", X_CASCADE => "pass" }, [ "Precondition Failed" ] ]
184194
end
185195
end
186196

@@ -189,7 +199,7 @@ def precondition_failed_response(env)
189199
def javascript_exception_response(exception)
190200
err = "#{exception.class.name}: #{exception.message}\n (in #{exception.backtrace[0]})"
191201
body = "throw Error(#{err.inspect})"
192-
[ 200, { "content-type" => "application/javascript", "content-length" => body.bytesize.to_s }, [ body ] ]
202+
[ 200, { Rack::CONTENT_TYPE => "application/javascript", Rack::CONTENT_LENGTH => body.bytesize.to_s }, [ body ] ]
193203
end
194204

195205
# Returns a CSS response that hides all elements on the page and
@@ -242,7 +252,7 @@ def css_exception_response(exception)
242252
}
243253
CSS
244254

245-
[ 200, { "content-type" => "text/css; charset=utf-8", "content-length" => body.bytesize.to_s }, [ body ] ]
255+
[ 200, { Rack::CONTENT_TYPE => "text/css; charset=utf-8", Rack::CONTENT_LENGTH => body.bytesize.to_s }, [ body ] ]
246256
end
247257

248258
# Escape special characters for use inside a CSS content("...") string
@@ -258,18 +268,18 @@ def cache_headers(env, etag)
258268
headers = {}
259269

260270
# Set caching headers
261-
headers["cache-control"] = +"public"
262-
headers["etag"] = %("#{etag}")
271+
headers[Rack::CACHE_CONTROL] = +"public"
272+
headers[Rack::ETAG] = %("#{etag}")
263273

264274
# If the request url contains a fingerprint, set a long
265275
# expires on the response
266276
if path_fingerprint(env["PATH_INFO"])
267-
headers["cache-control"] << ", max-age=31536000, immutable"
277+
headers[Rack::CACHE_CONTROL] << ", max-age=31536000, immutable"
268278

269279
# Otherwise set `must-revalidate` since the asset could be modified.
270280
else
271-
headers["cache-control"] << ", must-revalidate"
272-
headers["vary"] = "Accept-Encoding"
281+
headers[Rack::CACHE_CONTROL] << ", must-revalidate"
282+
headers[VARY] = "Accept-Encoding"
273283
end
274284

275285
headers
@@ -279,15 +289,15 @@ def headers(env, asset, length)
279289
headers = {}
280290

281291
# Set content length header
282-
headers["content-length"] = length.to_s
292+
headers[Rack::CONTENT_LENGTH] = length.to_s
283293

284294
# Set content type header
285295
if type = asset.content_type
286296
# Set charset param for text/* mime types
287297
if type.start_with?("text/") && asset.charset
288298
type += "; charset=#{asset.charset}"
289299
end
290-
headers["content-type"] = type
300+
headers[Rack::CONTENT_TYPE] = type
291301
end
292302

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

test/sprockets_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test(name, &block)
9393
end
9494
end
9595

96-
class Sprockets::TestCase < MiniTest::Test
96+
class Sprockets::TestCase < Minitest::Test
9797
extend Sprockets::TestDefinition
9898

9999
FIXTURE_ROOT = File.join(__dir__, "fixtures")

test/test_babel_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'sprockets/cache'
55
require 'sprockets/babel_processor'
66

7-
class TestBabelProcessor < MiniTest::Test
7+
class TestBabelProcessor < Minitest::Test
88
def setup
99
@env = Sprockets::Environment.new
1010
@env.append_path File.expand_path("../fixtures", __FILE__)

test/test_cache_store.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_clear
8585
end
8686
end
8787

88-
class TestNullStore < MiniTest::Test
88+
class TestNullStore < Minitest::Test
8989
def setup
9090
@_store = Sprockets::Cache::NullStore.new
9191
@store = Sprockets::Cache.new(Sprockets::Cache::NullStore.new)
@@ -99,7 +99,7 @@ def test_inspect
9999
include CacheStoreNullTests
100100
end
101101

102-
class TestMemoryStore < MiniTest::Test
102+
class TestMemoryStore < Minitest::Test
103103
def setup
104104
@_store = Sprockets::Cache::MemoryStore.new
105105
@store = Sprockets::Cache.new(@_store)
@@ -132,7 +132,7 @@ def test_set_with_lru
132132
end
133133
end
134134

135-
class TestZeroMemoryStore < MiniTest::Test
135+
class TestZeroMemoryStore < Minitest::Test
136136
def setup
137137
@_store = Sprockets::Cache::MemoryStore.new(0)
138138
@store = Sprockets::Cache.new(@_store)
@@ -145,7 +145,7 @@ def test_inspect
145145
include CacheStoreNullTests
146146
end
147147

148-
class TestFileStore < MiniTest::Test
148+
class TestFileStore < Minitest::Test
149149
def setup
150150
@root = Dir::mktmpdir "sprockets-file-store"
151151
@_store = Sprockets::Cache::FileStore.new(@root)
@@ -180,7 +180,7 @@ def test_clear_store_dir_not_exist
180180
include CacheStoreTests
181181
end
182182

183-
class TestZeroFileStore < MiniTest::Test
183+
class TestZeroFileStore < Minitest::Test
184184
def setup
185185
@tmpdir = Dir::mktmpdir "sprockets-file-store-zero"
186186
@_store = Sprockets::Cache::FileStore.new(@tmpdir, 0)

test/test_closure_compressor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'sprockets/cache'
44
require 'sprockets/closure_compressor'
55

6-
class TestClosureCompressor < MiniTest::Test
6+
class TestClosureCompressor < Minitest::Test
77
def test_compress_javascript
88
input = {
99
data: "function foo() {\n return true;\n}",

test/test_coffee_script_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'sprockets/coffee_script_processor'
66
require 'sprockets/source_map_utils'
77

8-
class TestCoffeeScriptProcessor < MiniTest::Test
8+
class TestCoffeeScriptProcessor < Minitest::Test
99
def setup
1010
@env = Sprockets::Environment.new
1111
@env.append_path File.expand_path("../fixtures", __FILE__)

test/test_digest_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/digest_utils'
44

5-
class TestDigestUtils < MiniTest::Test
5+
class TestDigestUtils < Minitest::Test
66
include Sprockets::DigestUtils
77

88
def test_detect_digest_class

test/test_eco_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'sprockets/cache'
44
require 'sprockets/eco_processor'
55

6-
class TestEcoProcessor < MiniTest::Test
6+
class TestEcoProcessor < Minitest::Test
77
def test_compile_eco_template_to_js
88
input = {
99
content_type: 'application/javascript',

test/test_ejs_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'sprockets/cache'
44
require 'sprockets/ejs_processor'
55

6-
class TestEjsProcessor < MiniTest::Test
6+
class TestEjsProcessor < Minitest::Test
77
def test_compile_ejs_template_to_js
88
input = {
99
content_type: 'application/javascript',

test/test_encoding_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'minitest/autorun'
44
require 'sprockets/encoding_utils'
55

6-
class TestDigestUtils < MiniTest::Test
6+
class TestDigestUtils < Minitest::Test
77
include Sprockets::EncodingUtils
88

99
def test_deflate

test/test_erb_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'sprockets/erb_processor'
66
require 'sass'
77

8-
class TestERBProcessor < MiniTest::Test
8+
class TestERBProcessor < Minitest::Test
99

1010
def uri_path(path)
1111
path = '/' + path if path[1] == ':' # Windows path / drive letter

test/test_http_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/http_utils'
44

5-
class TestHTTPUtils < MiniTest::Test
5+
class TestHTTPUtils < Minitest::Test
66
include Sprockets::HTTPUtils
77

88
def test_match_mime_type

test/test_jsminc_compressor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
unless RUBY_PLATFORM.include?('java')
55
require 'sprockets/jsminc_compressor'
66

7-
class TestJSMincCompressor < MiniTest::Test
7+
class TestJSMincCompressor < Minitest::Test
88

99
def test_compress_javascript
1010
input = {

test/test_jst_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'sprockets/cache'
44
require 'sprockets/jst_processor'
55

6-
class TestJstProcessor < MiniTest::Test
6+
class TestJstProcessor < Minitest::Test
77
def test_export_js_template_in_JST
88
input = {
99
name: 'users/show',

test/test_manifest_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'sprockets/manifest_utils'
44
require 'logger'
55

6-
class TestManifestUtils < MiniTest::Test
6+
class TestManifestUtils < Minitest::Test
77
include Sprockets::ManifestUtils
88

99
def test_generate_manifest_path

test/test_path_dependency_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/path_dependency_utils'
44

5-
class TestPathDependencyUtils < MiniTest::Test
5+
class TestPathDependencyUtils < Minitest::Test
66
include Sprockets::PathDependencyUtils
77

88
def test_entries_with_dependencies

test/test_path_digest_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/path_digest_utils'
44

5-
class TestPathDigestUtils < MiniTest::Test
5+
class TestPathDigestUtils < Minitest::Test
66
include Sprockets::PathDigestUtils
77

88
def test_file_stat_digest

test/test_path_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/path_utils'
44

5-
class TestPathUtils < MiniTest::Test
5+
class TestPathUtils < Minitest::Test
66
include Sprockets::PathUtils
77

88
DOSISH = File::ALT_SEPARATOR != nil

test/test_processor_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_charset_supersedes_default
3737
end
3838
end
3939

40-
class TestProcessorUtils < MiniTest::Test
40+
class TestProcessorUtils < Minitest::Test
4141
include Sprockets::ProcessorUtils
4242

4343
class Processor

test/test_require.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require 'minitest/autorun'
33

4-
class TestRequire < MiniTest::Test
4+
class TestRequire < Minitest::Test
55
parallelize_me!
66

77
ROOT = File.expand_path("../..", __FILE__)

test/test_source_map_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/source_map_utils'
44

5-
class TestSourceMapUtils < MiniTest::Test
5+
class TestSourceMapUtils < Minitest::Test
66

77
def deep_dup(object)
88
Marshal.load( Marshal.dump(object) )

test/test_uglifier_compressor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'sprockets/cache'
55
require 'sprockets/uglifier_compressor'
66

7-
class TestUglifierCompressor < MiniTest::Test
7+
class TestUglifierCompressor < Minitest::Test
88
def setup
99
@env = Sprockets::Environment.new
1010
@env.append_path File.expand_path("../fixtures", __FILE__)

test/test_uri_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/uri_utils'
44

5-
class TestURIUtils < MiniTest::Test
5+
class TestURIUtils < Minitest::Test
66
include Sprockets::URIUtils
77

88
DOSISH = File::ALT_SEPARATOR != nil

0 commit comments

Comments
 (0)