summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChimrod <contact+git@chimrod.com>2011-08-30 15:47:18 +0200
committerChimrod <contact+git@chimrod.com>2011-08-30 15:47:18 +0200
commitdd474b72f01ca9ac3b431d0592cb10c19dee6415 (patch)
tree26e93517d3e38ca83aa9da83c3dcc8e10ba89967 /lib
parent5ff5b6d733136936af1789793e66d84df15731d5 (diff)
downloadfeed2imap-dd474b72f01ca9ac3b431d0592cb10c19dee6415.tar.gz
feed2imap-dd474b72f01ca9ac3b431d0592cb10c19dee6415.tar.bz2
feed2imap-dd474b72f01ca9ac3b431d0592cb10c19dee6415.zip
Set timeout for feed fetching
Diffstat (limited to 'lib')
-rw-r--r--lib/feed2imap/config.rb5
-rw-r--r--lib/feed2imap/feed2imap.rb4
-rw-r--r--lib/feed2imap/httpfetcher.rb17
3 files changed, 19 insertions, 7 deletions
diff --git a/lib/feed2imap/config.rb b/lib/feed2imap/config.rb
index 74d5507..fd4e94f 100644
--- a/lib/feed2imap/config.rb
+++ b/lib/feed2imap/config.rb
@@ -34,7 +34,7 @@ LOGNAME = Etc.getlogin
# Feed2imap configuration
class F2IConfig
- attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated, :parts
+ attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated, :parts, :timeout
# Load the configuration from the IO stream
# TODO should do some sanity check on the data read.
@@ -60,6 +60,8 @@ class F2IConfig
@reupload_if_updated = true
@reupload_if_updated = @conf['reupload-if-updated'] if @conf.has_key?('reupload-if-updated')
+ @timeout = if @conf['timeout'] == nil then 30 else @conf['timeout'].to_i end
+
@default_email = (@conf['default-email'] || "#{LOGNAME}@#{HOSTNAME}")
ImapAccount.no_ssl_verify = (@conf.has_key?('disable-ssl-verification') and @conf['disable-ssl-verification'] == true)
@hostname = HOSTNAME # FIXME: should this be configurable as well?
@@ -137,6 +139,7 @@ class ConfigFeed
@reupload_if_updated = f2iconfig.reupload_if_updated
@reupload_if_updated = f['reupload-if-updated'] if f.has_key?('reupload-if-updated')
+
end
def needfetch(lastcheck)
diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb
index b938a39..acfb56e 100644
--- a/lib/feed2imap/feed2imap.rb
+++ b/lib/feed2imap/feed2imap.rb
@@ -121,7 +121,9 @@ class Feed2Imap
end
fetch_start = Time::now
if feed.url
- s = HTTPFetcher::fetch(feed.url, @cache.get_last_check(feed.name))
+ fetcher = HTTPFetcher::new
+ fetcher::timeout = @config.timeout
+ s = fetcher::fetch(feed.url, @cache.get_last_check(feed.name))
elsif feed.execurl
# avoid running more than one command at the same time.
# We need it because the called command might not be
diff --git a/lib/feed2imap/httpfetcher.rb b/lib/feed2imap/httpfetcher.rb
index 9980578..6734465 100644
--- a/lib/feed2imap/httpfetcher.rb
+++ b/lib/feed2imap/httpfetcher.rb
@@ -34,7 +34,14 @@ HTTPDEBUG = false
# Class used to retrieve the feed over HTTP
class HTTPFetcher
- def HTTPFetcher::fetcher(baseuri, uri, lastcheck, recursion)
+
+ @timeout = 30 # should be enough for everybody...
+
+ def timeout=(value)
+ @timeout = value
+ end
+
+ def fetcher(baseuri, uri, lastcheck, recursion)
proxy_host = nil
proxy_port = nil
proxy_user = nil
@@ -50,8 +57,8 @@ class HTTPFetcher
proxy_port,
proxy_user,
proxy_pass ).new(uri.host, uri.port)
- http.read_timeout = 30 # should be enough for everybody...
- http.open_timeout = 30
+ http.read_timeout = @timeout
+ http.open_timeout = @timeout
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -108,8 +115,8 @@ class HTTPFetcher
end
end
- def HTTPFetcher::fetch(url, lastcheck)
+ def fetch(url, lastcheck)
uri = URI::parse(url)
- return HTTPFetcher::fetcher(uri, uri, lastcheck, MAXREDIR)
+ return fetcher(uri, uri, lastcheck, MAXREDIR)
end
end