Module: Lslinks::Reader::Http

Defined in:
lib/lslinks/reader/http.rb

Constant Summary collapse

DEFAULT_HTTP_HEADERS =
{
  "User-Agent" => "Ruby/#{RUBY_VERSION} lslinks/#{Lslinks::VERSION}",
}

Class Method Summary collapse

Class Method Details

.open(resource_name, **options, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lslinks/reader/http.rb', line 7

def open(resource_name, **options, &block)
  begin
    uri = URI(resource_name)
  rescue URI::InvalidURIError
    raise Lslinks::Error::UnsupportedResource
  end
  raise Lslinks::Error::UnsupportedResource if !uri.is_a?(URI::HTTP)

  http_headers = DEFAULT_HTTP_HEADERS.merge(options[:http_headers])
  return uri.open(http_headers, &block)
end