update http_multi to adjust urls when you get a redirect
This commit is contained in:
parent
f3202e15d6
commit
22d83ec502
2 changed files with 21 additions and 1 deletions
|
|
@ -3,7 +3,7 @@ module Job
|
|||
@queue = :http
|
||||
|
||||
MAX_RETRIES = 3
|
||||
OPTS = {:max_redirects => 3, :follow_location => true, :timeout => 5000, :method => :post}
|
||||
OPTS = {:max_redirects => 3, :timeout => 5000, :method => :post}
|
||||
|
||||
def self.perform_delegate(user_id, enc_object_xml, person_ids, retry_count=0)
|
||||
user = User.find(user_id)
|
||||
|
|
@ -22,6 +22,12 @@ module Job
|
|||
request = Typhoeus::Request.new(url, OPTS.merge(:params => {:xml => CGI::escape(xml)}))
|
||||
|
||||
request.on_complete do |response|
|
||||
if response.code >= 300 && response.code < 400
|
||||
if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://')
|
||||
person.url = response.headers_hash['Location']
|
||||
person.save
|
||||
end
|
||||
end
|
||||
unless response.success?
|
||||
Rails.logger.info("event=http_multi_fail sender_id=#{user_id} recipient_id=#{person.id} url=#{response.effective_url} response_code='#{response.code}' xml='#{Base64.decode64(enc_object_xml)}'")
|
||||
failed_request_people << person.id
|
||||
|
|
|
|||
|
|
@ -60,4 +60,18 @@ describe Job::HttpMulti do
|
|||
|
||||
Job::HttpMulti.perform(bob.id, @post_xml, [person.id])
|
||||
end
|
||||
|
||||
it 'updates http users who have moved to https' do
|
||||
person = @people.first
|
||||
person.url = 'http://remote.net/'
|
||||
person.save
|
||||
response = Typhoeus::Response.new(:code => 301, :headers_hash => {"Location" => person.receive_url.sub('http://', 'https://')}, :body => "", :time => 0.2)
|
||||
@hydra.stub(:post, person.receive_url).and_return(response)
|
||||
|
||||
Typhoeus::Hydra.stub!(:new).and_return(@hydra)
|
||||
|
||||
Job::HttpMulti.perform(bob.id, @post_xml, [person.id])
|
||||
person.reload
|
||||
person.url.should =~ /https:\/\/remote.net\//
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue