Skip to content

Commit

Permalink
Add redirect support on POST, as an opt-in. In particular, the 201 re…
Browse files Browse the repository at this point in the history
…sponse is a valid response for newly created resources. Needs specs.
  • Loading branch information
d11wtq committed Jul 5, 2011
1 parent 91208e5 commit edd9914
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/dm-rest-adapter/adapter.rb
Expand Up @@ -16,7 +16,16 @@ def create(resources)
response = @rest_client[@format.resource_path(*path_items)].post(
@format.string_representation(resource),
:content_type => @format.mime, :accept => @format.mime
)
) do |response, request, result, &block|
# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2 for HTTP response 201
if @options[:allow_post_redirect] && [201, 301, 302, 307].include?(response.code)
args[:method] = :get
response.args.delete(:payload)
response.follow_redirection(request, result, &block)
else
response.return!(request, result, &block)
end
end

@format.update_attributes(resource, response.body)
end
Expand Down

0 comments on commit edd9914

Please sign in to comment.