Class: Rack::Cors::Result

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

Constant Summary collapse

HEADER_KEY =
'X-Rack-CORS'.freeze
MISS_NO_ORIGIN =
'no-origin'.freeze
MISS_NO_PATH =
'no-path'.freeze
MISS_NO_METHOD =
'no-method'.freeze
MISS_DENY_METHOD =
'deny-method'.freeze
MISS_DENY_HEADER =
'deny-header'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hitObject

Returns the value of attribute hit.



217
218
219
# File 'lib/rack/cors.rb', line 217

def hit
  @hit
end

#miss_reasonObject

Returns the value of attribute miss_reason.



217
218
219
# File 'lib/rack/cors.rb', line 217

def miss_reason
  @miss_reason
end

#preflightObject

Returns the value of attribute preflight.



217
218
219
# File 'lib/rack/cors.rb', line 217

def preflight
  @preflight
end

Class Method Details

.hit(env) ⇒ Object



232
233
234
235
236
237
# File 'lib/rack/cors.rb', line 232

def self.hit(env)
  r = Result.new
  r.preflight = false
  r.hit = true
  env[RACK_CORS] = r
end

.miss(env, reason) ⇒ Object



239
240
241
242
243
244
245
# File 'lib/rack/cors.rb', line 239

def self.miss(env, reason)
  r = Result.new
  r.preflight = false
  r.hit = false
  r.miss_reason = reason
  env[RACK_CORS] = r
end

.preflight(env) ⇒ Object



247
248
249
250
251
# File 'lib/rack/cors.rb', line 247

def self.preflight(env)
  r = Result.new
  r.preflight = true
  env[RACK_CORS] = r
end

Instance Method Details

#append_header(headers) ⇒ Object



254
255
256
257
258
259
260
261
262
263
# File 'lib/rack/cors.rb', line 254

def append_header(headers)
  headers[HEADER_KEY] = if hit?
    preflight? ? 'preflight-hit' : 'hit'
  else
    [
      (preflight? ? 'preflight-miss' : 'miss'),
      miss_reason
    ].join('; ')
  end
end

#hit?Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/rack/cors.rb', line 219

def hit?
  !!hit
end

#miss(reason) ⇒ Object



227
228
229
230
# File 'lib/rack/cors.rb', line 227

def miss(reason)
  self.hit = false
  self.miss_reason = reason
end

#preflight?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/rack/cors.rb', line 223

def preflight?
  !!preflight
end