require 'lets_encrypt_heroku_client/version' class LetsEncryptHerokuClient def initialize(app) @app = app end def call(env) if challenge_url?(env['PATH_INFO']) body = ENV['LETS_ENCRYPT_CHALLENGE_FILE_CONTENT'] headers = { 'Content-Length' => body.length.to_s } [200, headers, [body]] else app.call(env) end end private attr_reader :app def challenge_url?(path) ENV.include?('LETS_ENCRYPT_CHALLENGE_FILENAME') && path == "/#{ENV['LETS_ENCRYPT_CHALLENGE_FILENAME']}" end end