开发者

open-uri open command run on a domain, against the same domain

开发者 https://www.devze.com 2023-03-16 12:49 出处:网络
Ive built a form on a webpage that allows a user to enter a URL and some information about the URL\'s CSS is returned. The tool works fine, apart from one issue i have noticed.

Ive built a form on a webpage that allows a user to enter a URL and some information about the URL's CSS is returned. The tool works fine, apart from one issue i have noticed.

When i enter the URL of the site where the script is hosted (tested locally, on a staging server and on a production server), the open-uri command 'open' returns a Timeout::Error. Now this isn't hugely surprising, i'm guessing something is getting locked up somewhere along the line and in the process of running the script and opening the current URL, processes are getting tied up a little.

For reference, here is the method where the Timeout occurs:

 # loads the Nokogiri XML object if it hasn't already been loaded
 def site
   begin
     timeout(10) do
       @site ||= Nokogiri::HTML(open(url))
     end
   rescue Timeout::Error
     return nil
   end
 end

My question is,开发者_运维百科 how do i enable the script to be able to 'open' the domain the script is currently running on? Do i need to create another Thread or something to process this particular aspect of my tool, if so how do i ensure the rest of my script isn't run until i receive something valid from the 'open' command?

Thanks for any suggestions or tips on this.


I wonder if you're getting into a recursive loop. Are you seeing repeated entries in your httpd log showing requests for the same site?

If so you might want to short-circuit requests to that particular domain and pre-stuff the @site instance variable so it falls through.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号