Module: Axlsx::UriUtils
- Defined in:
- lib/axlsx/util/uri_utils.rb
Overview
This module defines some utils related to mime type detection
Class Method Summary collapse
-
.fetch_headers(uri, redirect_limit = 5) ⇒ Object
Performs an HTTP GeT request fetching only headers.
Class Method Details
.fetch_headers(uri, redirect_limit = 5) ⇒ Object
Performs an HTTP GeT request fetching only headers
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/axlsx/util/uri_utils.rb', line 11 def fetch_headers(uri, redirect_limit = 5) redirect_count = 0 use_get = false while redirect_count < redirect_limit case (response = fetch_headers_request(uri, use_get: use_get)) when Net::HTTPSuccess return response when Net::HTTPMethodNotAllowed, Net::HTTPNotImplemented fail_response(response) if use_get use_get = true next # Retry current URL with GET when Net::HTTPRedirection uri = follow_redirect(uri, response) redirect_count += 1 else fail_response(response) end end raise ArgumentError, "Too many redirects (exceeded #{redirect_limit})" end |