Skip to content
Extraits de code Groupes Projets
Valider 22d83ec5 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

update http_multi to adjust urls when you get a redirect

parent f3202e15
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter