Class: Acme::Client::HTTPClient::AcmeMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/acme/client/http_client.rb

Overview

AcmeMiddleware implements the Acme-protocol requirements for JWK requests.

Constant Summary collapse

CONTENT_TYPE =
'application/jose+json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ AcmeMiddleware

Returns a new instance of AcmeMiddleware.



61
62
63
64
65
# File 'lib/acme/client/http_client.rb', line 61

def initialize(app, options)
  super(app)
  @client = options.fetch(:client)
  @mode = options.fetch(:mode)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



57
58
59
# File 'lib/acme/client/http_client.rb', line 57

def client
  @client
end

#envObject (readonly)

Returns the value of attribute env.



57
58
59
# File 'lib/acme/client/http_client.rb', line 57

def env
  @env
end

#responseObject (readonly)

Returns the value of attribute response.



57
58
59
# File 'lib/acme/client/http_client.rb', line 57

def response
  @response
end

Instance Method Details

#call(env) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/acme/client/http_client.rb', line 67

def call(env)
  @env = env
  @env[:request_headers]['Content-Type'] = CONTENT_TYPE

  if @env.method != :get
    @env.body = client.jwk.jws(header: jws_header, payload: env.body)
  end

  @app.call(env).on_complete { |response_env| on_complete(response_env) }
end

#on_complete(env) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/acme/client/http_client.rb', line 78

def on_complete(env)
  @env = env

  raise_on_not_found!
  store_nonce
  env.body = decode_body
  env.response_headers['Link'] = decode_link_headers

  return if env.success?

  raise_on_error!
end