Permalink
Browse files

Merge pull request #153 from markiz/master

em_http_request_1_x: use bytesize of message instead of its length for content-length header
  • Loading branch information...
2 parents 265b249 + 904dda0 commit 2a5d3712d2b9f8e1b204ada364f18c7127f96c45 @bblimke committed Feb 4, 2012
View
2 lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb
@@ -189,7 +189,7 @@ def make_raw_response(response)
response_string = []
response_string << "HTTP/1.1 #{status[0]} #{status[1]}"
- headers["Content-Length"] = body.length unless headers["Content-Length"]
+ headers["Content-Length"] = body.bytesize unless headers["Content-Length"]
headers.each do |header, value|
value = value.join(", ") if value.is_a?(Array)
View
7 spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'spec_helper'
require 'acceptance/webmock_shared'
require 'ostruct'
@@ -133,6 +134,12 @@ def response(resp)
http_request(:post, "http://www.example.com", :body => {:a => "1", :b => "2"}).body.should == "ok"
end
+ it "should work with UTF-8 strings" do
+ body = "Привет, Мир!"
+ stub_request(:post, "www.example.com").to_return(:body => body)
+ http_request(:post, "http://www.example.com").body.bytesize.should == body.bytesize
+ end
+
describe "mocking EM::HttpClient API" do
before do
stub_request(:get, "www.example.com/")

0 comments on commit 2a5d371

Please sign in to comment.