Class: Mailpeek::WebApplication
- Inherits:
-
Object
- Object
- Mailpeek::WebApplication
- Extended by:
- WebRouter
- Defined in:
- lib/mailpeek/web/application.rb
Overview
Public: WebApplication
Constant Summary collapse
- CONTENT_LENGTH =
'Content-Length'
- CONTENT_TYPE =
'Content-Type'
- CSP_HEADER =
[ "default-src 'self' https: http:", "child-src 'self'", "connect-src 'self' https: http: wss: ws:", "font-src 'self' https: http:", "frame-src 'self'", "img-src 'self' https: http: data:", "manifest-src 'self'", "media-src 'self'", "object-src 'none'", "script-src 'self' https: http: 'unsafe-inline'", "style-src 'self' https: http: 'unsafe-inline'", "worker-src 'self'", "base-uri 'self'" ].join('; ').freeze
Constants included from WebRouter
Mailpeek::WebRouter::DELETE, Mailpeek::WebRouter::GET, Mailpeek::WebRouter::HEAD, Mailpeek::WebRouter::PATCH, Mailpeek::WebRouter::PATH_INFO, Mailpeek::WebRouter::POST, Mailpeek::WebRouter::PUT, Mailpeek::WebRouter::REQUEST_METHOD, Mailpeek::WebRouter::ROUTE_PARAMS
Class Method Summary collapse
-
.helpers(mod = nil, &block) ⇒ Object
rubocop:enable Metrics/MethodLength.
- .set(key, val) ⇒ Object
- .settings ⇒ Object
Instance Method Summary collapse
-
#call(env) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(klass) ⇒ WebApplication
constructor
A new instance of WebApplication.
- #settings ⇒ Object
Methods included from WebRouter
delete, get, match, patch, post, put, route
Constructor Details
#initialize(klass) ⇒ WebApplication
Returns a new instance of WebApplication.
26 27 28 |
# File 'lib/mailpeek/web/application.rb', line 26 def initialize(klass) @klass = klass end |
Class Method Details
.helpers(mod = nil, &block) ⇒ Object
rubocop:enable Metrics/MethodLength
146 147 148 149 150 151 152 |
# 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 |
.set(key, val) ⇒ Object
38 39 40 |
# File 'lib/mailpeek/web/application.rb', line 38 def self.set(key, val) # nothing, backwards compatibility end |
Instance Method Details
#call(env) ⇒ Object
rubocop:disable Metrics/MethodLength
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/mailpeek/web/application.rb', line 30 def settings @klass.settings end |