Skip to content
Browse files

Content-Length is a bytesize of content

  • Loading branch information...
1 parent cb31604 commit dcbdd590cfebb129490a961dc482dd5c1c7891a8 @ichiban committed
Showing with 15 additions and 1 deletion.
  1. +1 −1 lib/mongrel2/response.rb
  2. +14 −0 spec/response_spec.rb
View
2 lib/mongrel2/response.rb
@@ -62,7 +62,7 @@ def send_resp(uuid, conn_id, data)
end
def build_http_response(body, status, headers)
- headers['Content-Length'] = body.size.to_s
+ headers['Content-Length'] = body.bytesize.to_s
headers = headers.map{ |k, v| '%s: %s' % [k,v] }.join("\r\n")
"HTTP/1.1 #{status} #{StatusMessage[status.to_i]}\r\n#{headers}\r\n\r\n#{body}"
end
View
14 spec/response_spec.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Mongrel2::Response do
@@ -26,4 +27,17 @@
@response.close(@req)
end
+
+ it 'should count bytesize of body as Content-Length' do
+ def @response.send_resp(uuid, conn_id, data)
+ # do nothing
+ end
+ @req.stub(:uuid).and_return(nil)
+ @req.stub(:conn_id).and_return(nil)
+ headers = {}
+ @response.send_http @req, 'abc', 200, headers
+ headers['Content-Length'].should eql('abc'.bytesize.to_s)
+ @response.send_http @req, 'あいう', 200, headers
+ headers['Content-Length'].should eql('あいう'.bytesize.to_s)
+ end
end

0 comments on commit dcbdd59

Please sign in to comment.
Something went wrong with that request. Please try again.