Class: I18n::Backend::Http::EtagHttpClient
- Inherits:
-
Object
- Object
- I18n::Backend::Http::EtagHttpClient
- Defined in:
- lib/i18n/backend/http/etag_http_client.rb
Instance Method Summary collapse
- #download(path, etag:) ⇒ Object
-
#initialize(options) ⇒ EtagHttpClient
constructor
A new instance of EtagHttpClient.
Constructor Details
#initialize(options) ⇒ EtagHttpClient
Returns a new instance of EtagHttpClient.
7 8 9 |
# File 'lib/i18n/backend/http/etag_http_client.rb', line 7 def initialize() @options = end |
Instance Method Details
#download(path, etag:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/i18n/backend/http/etag_http_client.rb', line 11 def download(path, etag:) @client ||= Faraday.new(@options[:host]) response = @client.get(path) do |request| request.headers.merge!(@options[:headers]) if @options[:headers] request.headers["If-None-Match"] = etag if etag request.[:timeout] = @options[:http_read_timeout] request.[:open_timeout] = @options[:http_open_timeout] end case response.status when 200 then [response.body, response['ETag']] when 304 then nil else raise "Failed request: #{response.inspect}" end end |