summaryrefslogtreecommitdiff
path: root/lib/rest-client-wrapper.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-03-29 14:50:03 +0200
committerChristoph Helma <helma@in-silico.ch>2012-03-29 14:50:03 +0200
commit97f9367b05a9a665022adc5c3f0a988acb1c4fa3 (patch)
tree0a716fa05fc4c8beacde349b13e7d749c1b23b9e /lib/rest-client-wrapper.rb
parent0d457e40c005ba4209ec7e3093aa06d73d65a442 (diff)
RestClientWrapper follows redirects
Diffstat (limited to 'lib/rest-client-wrapper.rb')
-rw-r--r--lib/rest-client-wrapper.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb
index 30292de..aa5d9c4 100644
--- a/lib/rest-client-wrapper.rb
+++ b/lib/rest-client-wrapper.rb
@@ -34,13 +34,16 @@ module OpenTox
headers.each{ |k,v| headers.delete(k) if v==nil } if headers #remove keys with empty values, as this can cause problems
args[:headers] = headers
- # perform request
@request = RestClient::Request.new(args)
- # do not throw RestClient exceptions in order to create a @response object (needed for error reports) in every case
- @response = @request.execute { |response, request, result| return response }
# ignore error codes from Task services (may return error codes >= 400 according to API, which causes exceptions in RestClient and RDF::Reader)
- raise OpenTox::RestCallError.new @request, @response, "Response code is #{@response.code}." unless @response.code < 400 or URI.task? uri
- @response
+ @response = @request.execute do |response, request, result|
+ if [301, 302, 307].include? response.code and request.method == :get
+ response.follow_redirection(request, result)
+ else
+ raise OpenTox::RestCallError.new response.to_s, request, uri unless response.code < 400 or URI.task? uri
+ response
+ end
+ end
end
end