Permalink
Browse files

logging handles nil content-type

  • Loading branch information...
1 parent 7b3ae7e commit a0f3da80781ad43386cd721f3189c8468b12065b @adamwiggins adamwiggins committed Aug 18, 2008
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/rest_client.rb
  2. +6 −0 spec/rest_client_spec.rb
View
@@ -196,7 +196,7 @@ def request_log
end
def response_log(res)
- "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{res['Content-type'].gsub(/;.*$/, '')} #{res.body.size} bytes"
+ "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{res.body.size} bytes"
end
def display_log(msg)
View
@@ -270,6 +270,12 @@
@request.response_log(res).should == "# => 200 OK | text/html 4 bytes"
end
+ it "logs a response with a nil Content-type" do
+ res = mock('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
+ res.stub!(:[]).with('Content-type').and_return(nil)
+ @request.response_log(res).should == "# => 200 OK | 4 bytes"
+ end
+
it "strips the charset from the response content type" do
res = mock('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
res.stub!(:[]).with('Content-type').and_return('text/html; charset=utf-8')

0 comments on commit a0f3da8

Please sign in to comment.