Class: I18n::Backend::Http::EtagHttpClient
- Inherits:
-
Object
- Object
- I18n::Backend::Http::EtagHttpClient
- Defined in:
- lib/i18n/backend/http/etag_http_client.rb
Constant Summary collapse
- STATS_NAMESPACE =
'i18n-backend-http.etag_client'.freeze
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.
9 10 11 |
# File 'lib/i18n/backend/http/etag_http_client.rb', line 9 def initialize() @options = end |
Instance Method Details
#download(path, etag:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/i18n/backend/http/etag_http_client.rb', line 13 def download(path, etag:) @client ||= Faraday.new(@options[:host]) start = Time.now 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 = ["status_code:#{response.status}", "path:#{path}"] record :timing, time: (Time.now - start).to_f * 1000, tags: case response.status when 200 record :success, tags: [response.body, response['ETag']] when 304 record :success, tags: nil else record :failure, tags: raise "Failed request: #{response.inspect}" end end |