Class: Rack::Acme::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/acme/endpoint.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Endpoint

Returns a new instance of Endpoint.



4
5
6
# File 'lib/rack/acme/endpoint.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/acme/endpoint.rb', line 8

def call(env)
  request = ::Rack::Request.new(env)

  if (m = request.fullpath.match(%r{\A/.well-known/acme-challenge/(.+)\z}))
    token = m[1]
    content = ::Rack::Acme.cache[token]

    if content
      return [200, {}, [content]]
    else
      return [404, {}, ["No match for #{token}"]]
    end
  else
    @app.call(env)
  end
end