class Mailpeek::WebApplication

Public: WebApplication

Constants

CONTENT_LENGTH
CONTENT_TYPE
CSP_HEADER

Public Class Methods

helpers(mod = nil, &block) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/mailpeek/web/application.rb, line 146
def self.helpers(mod = nil, &block)
  if block_given?
    WebAction.class_eval(&block)
  else
    WebAction.send(:include, mod)
  end
end
new(klass) click to toggle source
# File lib/mailpeek/web/application.rb, line 26
def initialize(klass)
  @klass = klass
end
set(key, val) click to toggle source
# File lib/mailpeek/web/application.rb, line 38
def self.set(key, val)
  # nothing, backwards compatibility
end
settings() click to toggle source
# File lib/mailpeek/web/application.rb, line 34
def self.settings
  Mailpeek::Web.settings
end

Public Instance Methods

call(env) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/mailpeek/web/application.rb, line 107
def call(env)
  action = self.class.match(env)

  unless action
    return [
      404,
      { 'Content-Type' => 'text/plain', 'X-Cascade' => 'pass' },
      ['Not Found']
    ]
  end

  response = catch(:halt) do
    response = action.instance_exec(env, &action.block)
  end

  response =
    case response
    when Array
      response
    else
      headers = {
        'Content-Type' => 'text/html',
        'Cache-Control' => 'no-cache',
        'Content-Security-Policy' => CSP_HEADER
      }

      [200, headers, [response]]
    end

  response[1] = response[1].dup

  response[1][CONTENT_LENGTH] = response[2].inject(0) do |l, p|
    l + p.bytesize
  end.to_s

  response
end
settings() click to toggle source
# File lib/mailpeek/web/application.rb, line 30
def settings
  @klass.settings
end