Skip to content

Commit

Permalink
Add test for handling 304 Not Modified responses
Browse files Browse the repository at this point in the history
Handling of not modified responses is currently broken because net/http
defines 304 as a subclass of HTTPRedirection.  The subclasses of
HTTPRedirection should be examined, as it isn't clear that automatic
redirection is the right action to take for all cases.  At least 304
should _not_ redirect and instead return a response with empty body so
that we can use httparty for conditional GETs.
  • Loading branch information
seth authored and sandro committed Jan 27, 2010
1 parent 3332c89 commit dc14b30
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions spec/httparty/request_spec.rb
Expand Up @@ -232,6 +232,13 @@ def stub_response(body, code = 200)
end

describe 'with non-200 responses' do
it 'should return a valid object for 304 not modified' do
stub_response '', 304
resp = @request.perform
resp.code.should == 304
resp.body.should == "" # or nil?
end

it 'should return a valid object for 4xx response' do
stub_response '<foo><bar>yes</bar></foo>', 401
resp = @request.perform
Expand All @@ -251,10 +258,12 @@ def stub_response(body, code = 200)
end

it "should not attempt to parse empty responses" do
stub_response "", 204
[204, 304].each do |code|
stub_response "", code

@request.options[:format] = :xml
@request.perform.should be_nil
@request.options[:format] = :xml
@request.perform.should be_nil
end
end

it "should not fail for missing mime type" do
Expand Down

0 comments on commit dc14b30

Please sign in to comment.