Skip to content

Commit

Permalink
return correct content-length when response includes multibyte charac…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
lostapathy committed Dec 7, 2017
1 parent 40b0842 commit 967f5ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/contrib/not_found.rb
Expand Up @@ -19,7 +19,7 @@ def initialize(path = nil, content_type = 'text/html')
else
@content = F.read(path)
end
@length = @content.size.to_s
@length = @content.bytesize.to_s

@content_type = content_type
end
Expand Down
15 changes: 15 additions & 0 deletions test/spec_rack_not_found.rb
@@ -1,6 +1,7 @@
require 'minitest/autorun'
require 'rack/mock'
require 'rack/contrib/not_found'
require 'tempfile'

describe "Rack::NotFound" do

Expand Down Expand Up @@ -40,4 +41,18 @@
response.status.must_equal(404)
end

specify "should return correct size" do
Tempfile.open('test') do |f|
f.write '<!DOCTYPE html>'
f.write '<meta charset=utf-8>'
f.write '☃ snowman'
f.close
app = Rack::Builder.new do
use Rack::Lint
run Rack::NotFound.new(f.path)
end
response = Rack::MockRequest.new(app).get('/')
response.headers['Content-Length'].must_equal('46')
end
end
end

0 comments on commit 967f5ae

Please sign in to comment.