Skip to content

Commit

Permalink
[CLIENT] Deserialize response based on request.headers not "body in…
Browse files Browse the repository at this point in the history
…spection"

Related: elasticsearch-py@05c4eef
  • Loading branch information
karmi committed Feb 9, 2014
1 parent 87c6bd5 commit 80c48dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def perform_request(method, path, params={}, body=nil, &block)
raise e
end

json = serializer.load(response.body) if response.body.to_s =~ /^\{/
json = serializer.load(response.body) if response.headers && response.headers["content-type"] =~ /json/
took = (json['took'] ? sprintf('%.3fs', json['took']/1000.0) : 'n/a') rescue 'n/a' if logger || tracer
duration = Time.now-start if logger || tracer

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-transport/test/unit/transport_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def initialize(*); end
@transport.serializer.expects(:load).returns({'foo' => 'bar'})

response = @transport.perform_request 'GET', '/' do
Elasticsearch::Transport::Transport::Response.new 200, '{"foo":"bar"}'
Elasticsearch::Transport::Transport::Response.new 200, '{"foo":"bar"}', {"content-type" => 'application/json'}
end

assert_instance_of Elasticsearch::Transport::Transport::Response, response
Expand All @@ -153,7 +153,7 @@ def initialize(*); end
@transport.expects(:get_connection).returns(stub_everything :failures => 1)
@transport.serializer.expects(:load).never
response = @transport.perform_request 'GET', '/' do
Elasticsearch::Transport::Transport::Response.new 200, 'FOOBAR'
Elasticsearch::Transport::Transport::Response.new 200, 'FOOBAR', {"content-type" => 'text/plain'}
end

assert_instance_of Elasticsearch::Transport::Transport::Response, response
Expand Down

0 comments on commit 80c48dd

Please sign in to comment.