Module: Acme::Client::HTTPClient

Defined in:
lib/acme/client/http_client.rb

Defined Under Namespace

Classes: AcmeMiddleware, ErrorMiddleware

Class Method Summary collapse

Class Method Details

.new_acme_connection(url:, client:, mode:, options: {}, bad_nonce_retry: 0) ⇒ Faraday::Connection

Creates and returns a new HTTP client designed for the Acme-protocol, with default settings.

Parameters:

  • url (URI:HTTPS)
  • client (Acme::Client)
  • mode (Symbol)
  • options (Hash) (defaults to: {})
  • bad_nonce_retry (Integer) (defaults to: 0)

Returns:

  • (Faraday::Connection)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/acme/client/http_client.rb', line 28

def self.new_acme_connection(url:, client:, mode:, options: {}, bad_nonce_retry: 0)
  new_connection(url: url, options: options) do |configuration|
    if bad_nonce_retry > 0
      configuration.request(:retry,
        max: bad_nonce_retry,
        methods: Faraday::Connection::METHODS,
        exceptions: [Acme::Client::Error::BadNonce])
    end

    configuration.use Acme::Client::HTTPClient::AcmeMiddleware, client: client, mode: mode

    yield(configuration) if block_given?
  end
end

.new_connection(url:, options: {}) ⇒ Faraday::Connection

Creates and returns a new HTTP client, with default settings.

Parameters:

  • url (URI:HTTPS)
  • options (Hash) (defaults to: {})

Returns:

  • (Faraday::Connection)


9
10
11
12
13
14
15
16
17
18
# File 'lib/acme/client/http_client.rb', line 9

def self.new_connection(url:, options: {})
  Faraday.new(url, options) do |configuration|
    configuration.use Acme::Client::HTTPClient::ErrorMiddleware

    yield(configuration) if block_given?

    configuration.headers[:user_agent] = Acme::Client::USER_AGENT
    configuration.adapter Faraday.default_adapter
  end
end