Module: Ksef::HTTP::Connection

Defined in:
lib/ksef/http/connection.rb

Overview

Builds the single Faraday connection a Client owns.

One connection per client, shared across threads — safe with the default net_http adapter (DESIGN.md §5.2). The adapter is kept swappable via configuration.

Constant Summary collapse

JSON_CONTENT_TYPE =

application/problem+json is the current error content type, so the response parser must match it as well as plain application/json (docs/REFERENCE.md §5.1).

/\bjson\b/

Class Method Summary collapse

Class Method Details

.build(config) ⇒ Faraday::Connection

Parameters:

Returns:

  • (Faraday::Connection)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ksef/http/connection.rb', line 20

def build(config)
  Faraday.new(url: config.base_url, headers: default_headers(config)) do |f|
    f.request :json

    # Registration order is load-bearing. Faraday runs `on_complete` callbacks
    # innermost-first, so the JSON parser must be registered *after* the error
    # handler for the handler to see a decoded body rather than a raw string.
    f.use ErrorHandler
    f.use SystemWarning, logger: config.logger
    f.response :json, content_type: JSON_CONTENT_TYPE

    apply_transport_options(f, config)
    f.adapter config.adapter
  end
end