Skip to content

Commit a7eb3f4

Browse files
authored
Merge pull request #145 from lostapathy/unicode_sizes
Correct Content-Length bug of Rack::NotFound
2 parents e361122 + 967f5ae commit a7eb3f4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rack/contrib/not_found.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(path = nil, content_type = 'text/html')
1919
else
2020
@content = F.read(path)
2121
end
22-
@length = @content.size.to_s
22+
@length = @content.bytesize.to_s
2323

2424
@content_type = content_type
2525
end

test/spec_rack_not_found.rb

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'minitest/autorun'
22
require 'rack/mock'
33
require 'rack/contrib/not_found'
4+
require 'tempfile'
45

56
describe "Rack::NotFound" do
67

@@ -40,4 +41,18 @@
4041
response.status.must_equal(404)
4142
end
4243

44+
specify "should return correct size" do
45+
Tempfile.open('test') do |f|
46+
f.write '<!DOCTYPE html>'
47+
f.write '<meta charset=utf-8>'
48+
f.write '☃ snowman'
49+
f.close
50+
app = Rack::Builder.new do
51+
use Rack::Lint
52+
run Rack::NotFound.new(f.path)
53+
end
54+
response = Rack::MockRequest.new(app).get('/')
55+
response.headers['Content-Length'].must_equal('46')
56+
end
57+
end
4358
end

0 commit comments

Comments
 (0)