Skip to content

Commit

Permalink
Add support for handling 204 'No Content' responses. fixes RestKit#450
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Dec 2, 2011
1 parent 9208101 commit 8a39f93
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
5 changes: 5 additions & 0 deletions Code/Network/RKResponse.h
Expand Up @@ -170,6 +170,11 @@
*/
- (BOOL)isCreated;

/**
* Indicates an HTTP response code of 204
*/
- (BOOL)isNoContent;

/**
* Indicates an HTTP response code of 304
*/
Expand Down
4 changes: 4 additions & 0 deletions Code/Network/RKResponse.m
Expand Up @@ -336,6 +336,10 @@ - (BOOL)isCreated {
return ([self statusCode] == 201);
}

- (BOOL)isNoContent {
return ([self statusCode] == 204);
}

- (BOOL)isNotModified {
return ([self statusCode] == 304);
}
Expand Down
4 changes: 4 additions & 0 deletions Code/ObjectMapping/RKObjectLoader.m
Expand Up @@ -254,6 +254,10 @@ - (BOOL)isResponseMappable {
[self finalizeLoad:NO error:self.response.failureError];

return NO;
} else if ([self.response isNoContent]) {
// The No Content (204) response will never have a message body or a MIME Type. Invoke the delegate with self
[self informDelegateOfObjectLoadWithResultDictionary:[NSDictionary dictionaryWithObject:self forKey:@""]];
return NO;
} else if (NO == [self canParseMIMEType:[self.response MIMEType]]) {
// We can't parse the response, it's unmappable regardless of the status code
RKLogWarning(@"Encountered unexpected response with status code: %d (MIME Type: %@)", self.response.statusCode, self.response.MIMEType);
Expand Down
36 changes: 3 additions & 33 deletions Rakefile
@@ -1,36 +1,7 @@
require 'rubygems'

begin
gem 'uispecrunner'
require 'uispecrunner'
require 'uispecrunner/options'
rescue LoadError => error
puts "Unable to load UISpecRunner: #{error}"
end

namespace :uispec do
desc "Run all specs"
task :all do
options = UISpecRunner::Options.from_file('uispec.opts') rescue {}
uispec_runner = UISpecRunner.new(options)
uispec_runner.run_all!
end

desc "Run all unit specs (those that implement UISpecUnit)"
task :units do
options = UISpecRunner::Options.from_file('uispec.opts') rescue {}
uispec_runner = UISpecRunner.new(options)
uispec_runner.run_protocol!('UISpecUnit')
end

desc "Run all integration specs (those that implement UISpecIntegration)"
task :integration do
options = UISpecRunner::Options.from_file('uispec.opts') rescue {}
uispec_runner = UISpecRunner.new(options)
uispec_runner.run_protocol!('UISpecIntegration')
end

desc "Run the Spec server via Shotgun"
namespace :spec do
desc "Run the RestKit spec server"
task :server do
server_path = File.dirname(__FILE__) + '/Specs/Server/server.rb'
system("ruby #{server_path}")
Expand All @@ -57,8 +28,7 @@ def run(command, min_exit_status = 0)
return $?.exitstatus
end

desc "Run all specs"
task :default => 'uispec:all'
task :default => 'spec:server'

desc "Build RestKit for iOS and Mac OS X"
task :build do
Expand Down
1 change: 1 addition & 0 deletions Specs/Server/server.rb
Expand Up @@ -79,6 +79,7 @@ class RestKit::SpecServer < Sinatra::Base
end

post '/204' do
status 204
content_type 'application/json'
""
end
Expand Down

0 comments on commit 8a39f93

Please sign in to comment.