Validate a url in check_url() instead of doing it in the caller

Also when a non-HTTP url is given, it is logged.

Akinori MUSHA лет %!s(int64=9): %!d(string=назад)
Родитель
Сommit
e593aaa2d6
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      app/models/agents/website_agent.rb

+ 4 - 1
app/models/agents/website_agent.rb

@@ -191,6 +191,10 @@ module Agents
191 191
     end
192 192
 
193 193
     def check_url(url, payload = {})
194
+      unless /\Ahttps?:\/\//i === url
195
+        error "Ignoring a non-HTTP url: #{url.inspect}"
196
+        return
197
+      end
194 198
       log "Fetching #{url}"
195 199
       response = faraday.get(url)
196 200
       raise "Failed: #{response.inspect}" unless response.success?
@@ -254,7 +258,6 @@ module Agents
254 258
       incoming_events.each do |event|
255 259
         interpolate_with(event) do
256 260
           url_to_scrape = event.payload['url']
257
-          next unless url_to_scrape =~ /^https?:\/\//i
258 261
           check_url(url_to_scrape,
259 262
                     interpolated['mode'].to_s == "merge" ? event.payload : {})
260 263
         end