Fix request bug.
This commit is contained in:
parent
fd23167f98
commit
5240e84160
|
@ -86,6 +86,21 @@ class SiteFeed
|
||||||
def channel_title_for_cache
|
def channel_title_for_cache
|
||||||
!self[:channel_title].to_s.empty? ? self[:channel_title] : I18n.t("feed.source")
|
!self[:channel_title].to_s.empty? ? self[:channel_title] : I18n.t("feed.source")
|
||||||
end
|
end
|
||||||
|
def http_request(http, request)
|
||||||
|
response = http.request(request)
|
||||||
|
if response.code.to_i == 301 || response.code.to_i == 302
|
||||||
|
location = response["location"]
|
||||||
|
new_uri = URI(location)
|
||||||
|
http = Net::HTTP.new(new_uri.host, new_uri.port)
|
||||||
|
if location.include?('https')
|
||||||
|
http.use_ssl = true
|
||||||
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
end
|
||||||
|
request.instance_variable_set(:@path, new_uri.path)
|
||||||
|
response = http_request(http, request)
|
||||||
|
end
|
||||||
|
response
|
||||||
|
end
|
||||||
def add_notify
|
def add_notify
|
||||||
unless self.enable_notify
|
unless self.enable_notify
|
||||||
root_url = Site.first.root_url rescue ""
|
root_url = Site.first.root_url rescue ""
|
||||||
|
@ -98,7 +113,7 @@ class SiteFeed
|
||||||
http_req.open_timeout = 10
|
http_req.open_timeout = 10
|
||||||
request = Net::HTTP::Post.new("/xhr/#{self.channel_key.pluralize}/feed_add_remote/#{self.feed_uid}", 'Content-Type' => 'application/json')
|
request = Net::HTTP::Post.new("/xhr/#{self.channel_key.pluralize}/feed_add_remote/#{self.feed_uid}", 'Content-Type' => 'application/json')
|
||||||
request.body = {"url"=>root_url}.to_json
|
request.body = {"url"=>root_url}.to_json
|
||||||
response = http_req.request(request)
|
response = http_request( http_req , request )
|
||||||
if response.code.to_i == 200
|
if response.code.to_i == 200
|
||||||
self.update(:enable_notify=>true)
|
self.update(:enable_notify=>true)
|
||||||
end
|
end
|
||||||
|
@ -117,7 +132,7 @@ class SiteFeed
|
||||||
http_req.open_timeout = 10
|
http_req.open_timeout = 10
|
||||||
request = Net::HTTP::Post.new("/xhr/#{self.channel_key.pluralize}/feed_remove_remote/#{self.feed_uid}", 'Content-Type' => 'application/json')
|
request = Net::HTTP::Post.new("/xhr/#{self.channel_key.pluralize}/feed_remove_remote/#{self.feed_uid}", 'Content-Type' => 'application/json')
|
||||||
request.body = {"url"=>root_url}.to_json
|
request.body = {"url"=>root_url}.to_json
|
||||||
response = http_req.request(request)
|
response = http_request( http_req , request )
|
||||||
if response.code.to_i == 200
|
if response.code.to_i == 200
|
||||||
self.update(:enable_notify=>false)
|
self.update(:enable_notify=>false)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue