Permalink
Browse files

Fix CONTENT_LENGTH in RackResponse

  • Loading branch information...
1 parent 0f0de80 commit 01d8f0f30594a4b5ceaf67b2507d8a9544eedc45 @Claster Claster committed Mar 26, 2014
Showing with 12 additions and 2 deletions.
  1. +1 −1 lib/webmock/rack_response.rb
  2. +1 −1 spec/support/my_rack_app.rb
  3. +10 −0 spec/unit/rack_response_spec.rb
@@ -32,7 +32,7 @@ def build_rack_env(request)
# CGI variables specified by Rack
'REQUEST_METHOD' => request.method.to_s.upcase,
'CONTENT_TYPE' => headers.delete('Content-Type'),
- 'CONTENT_LENGTH' => body.size,
+ 'CONTENT_LENGTH' => body.bytesize,
'PATH_INFO' => uri.path,
'QUERY_STRING' => uri.query || '',
'SERVER_NAME' => uri.host,
@@ -24,7 +24,7 @@ def self.call(env)
when ['GET', '/locked']
[200, {}, ["Single threaded response."]]
when ['POST', '/greet']
- name = env["rack.input"].read[/name=([^&]*)/, 1] || "World"
+ name = env["rack.input"].read(env["CONTENT_LENGTH"]).force_encoding("UTF-8")[/name=([^&]*)/, 1] || "World"
[200, {}, ["Good to meet you, #{name}!"]]
when ['GET', '/compute']
if env['SERVER_PORT'] == 80 && env["SCRIPT_NAME"] == ""
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'spec_helper'
describe WebMock::RackResponse do
@@ -49,6 +50,15 @@
response.body.should include('Good to meet you, Jimmy!')
end
+ it "should send params with proper content length if params have non-ascii symbols" do
+ request = WebMock::RequestSignature.new(:post, 'www.example.com/greet',
+ :body => 'name=Олег'
+ )
+
+ response = @rack_response.evaluate(request)
+ response.body.should include('Good to meet you, Олег!')
+ end
+
describe 'rack error output' do
before :each do
@original_stderr = $stderr

0 comments on commit 01d8f0f

Please sign in to comment.