class Miteru::HTTPClient
Constants
- DEFAULT_UA
- URLSCAN_UA
Attributes
ssl_context[R]
Public Class Methods
download(url, base_dir = "/tmp")
click to toggle source
# File lib/miteru/http_client.rb, line 49 def download(url, base_dir = "/tmp") new.download(url, base_dir) end
get(url, options = {})
click to toggle source
# File lib/miteru/http_client.rb, line 53 def get(url, options = {}) new.get url, options end
head(url, options = {})
click to toggle source
# File lib/miteru/http_client.rb, line 61 def head(url, options = {}) new.head url, options end
new()
click to toggle source
# File lib/miteru/http_client.rb, line 14 def initialize ctx = OpenSSL::SSL::SSLContext.new ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE @ssl_context = ctx end
post(url, options = {})
click to toggle source
# File lib/miteru/http_client.rb, line 57 def post(url, options = {}) new.post url, options end
Public Instance Methods
download(url, destination)
click to toggle source
# File lib/miteru/http_client.rb, line 20 def download(url, destination) down = Down::Http.new(**default_options) { |client| client.headers(**default_headers) } down.download(url, destination: destination) destination end
get(url, options = {})
click to toggle source
# File lib/miteru/http_client.rb, line 35 def get(url, options = {}) options = options.merge default_options HTTP.follow .timeout(write: 2, connect: 5, read: 10) .headers(urlscan_url?(url) ? urlscan_headers : default_headers) .get(url, options) end
head(url, options = {})
click to toggle source
# File lib/miteru/http_client.rb, line 26 def head(url, options = {}) options = options.merge default_options HTTP.follow .timeout(3) .headers(urlscan_url?(url) ? urlscan_headers : default_headers) .head(url, options) end
post(url, options = {})
click to toggle source
# File lib/miteru/http_client.rb, line 44 def post(url, options = {}) HTTP.post url, options end
Private Instance Methods
default_headers()
click to toggle source
# File lib/miteru/http_client.rb, line 68 def default_headers { user_agent: DEFAULT_UA } end
default_options()
click to toggle source
# File lib/miteru/http_client.rb, line 72 def default_options { ssl_context: ssl_context } end
urlscan_headers()
click to toggle source
# File lib/miteru/http_client.rb, line 76 def urlscan_headers { user_agent: URLSCAN_UA } end
urlscan_url?(url)
click to toggle source
# File lib/miteru/http_client.rb, line 80 def urlscan_url?(url) uri = URI(url) uri.hostname == "urlscan.io" end