Permalink
Browse files

Fix and tests for issue 98

  • Loading branch information...
Alexis Dorais-Joncas
Alexis Dorais-Joncas committed Jun 8, 2011
1 parent 5fff9d3 commit 49dfdec9e7d5a84c594aa0709973785acf61b440
Showing with 22 additions and 2 deletions.
  1. +14 −2 lib/typhoeus/response.rb
  2. +8 −0 spec/typhoeus/response_spec.rb
View
@@ -62,8 +62,20 @@ def headers_hash
end
def status_message
- # http://rubular.com/r/eAr1oVYsVa
- @status_message ||= first_header_line ? first_header_line[/\d{3} (.*)$/, 1].chomp : nil
+ return @status_message if @status_message

This comment has been minimized.

Show comment Hide comment
@dbalatero

dbalatero Jun 8, 2011

If @status_message gets set to nil below, this shortcut return won't run. Maybe we want:

if defined?(@status_message)

in this case? Thoughts?

@dbalatero

dbalatero Jun 8, 2011

If @status_message gets set to nil below, this shortcut return won't run. Maybe we want:

if defined?(@status_message)

in this case? Thoughts?

This comment has been minimized.

Show comment Hide comment
@balexis

balexis Jun 8, 2011

Owner

Yes that would be much better. Let me see how to edit the commit.

@balexis

balexis Jun 8, 2011

Owner

Yes that would be much better. Let me see how to edit the commit.

This comment has been minimized.

Show comment Hide comment
@dbalatero

dbalatero Jun 8, 2011

@dbalatero

dbalatero via email Jun 8, 2011

This comment has been minimized.

Show comment Hide comment
@balexis

balexis Jun 8, 2011

Owner

Yeah, that's what I ended up doing :)

@balexis

balexis Jun 8, 2011

Owner

Yeah, that's what I ended up doing :)

+
+ # HTTP servers can choose not to include the explanation to HTTP codes. The RFC
+ # states this (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4):
+ # Except when responding to a HEAD request, the server SHOULD include an entity containing
+ # an explanation of the error situation [...]
+ # This means 'HTTP/1.1 404' is as valid as 'HTTP/1.1 404 Not Found' and we have to handle it.
+
+ # Regexp doc: http://rubular.com/r/eAr1oVYsVa
+ if first_header_line != nil and first_header_line[/\d{3} (.*)$/, 1] != nil
+ @status_message = first_header_line[/\d{3} (.*)$/, 1].chomp
+ else
+ @status_message = nil
+ end
end
def http_version
@@ -36,6 +36,10 @@
Typhoeus::Response.new.status_message.should be_nil
end
+ it "should return nil for status_message if a message-less header is given" do
+ Typhoeus::Response.new(:headers => "HTTP/1.1 200\r\n").status_message.should == nil
+ end
+
it "should store http_version" do
Typhoeus::Response.new(:http_version => '1.1').http_version.should == '1.1'
end
@@ -44,6 +48,10 @@
Typhoeus::Response.new.http_version.should be_nil
end
+ it "should return nil for http version if an invalid or incomplete header is given" do
+ Typhoeus::Response.new(:headers => "HTTP foo/bar 200 OK\r\n").http_version.should == nil
+ end
+
it "should store response_headers" do
Typhoeus::Response.new(:headers => "a header!").headers.should == "a header!"
end

0 comments on commit 49dfdec

Please sign in to comment.