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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hitObject

Returns the value of attribute hit.



198
199
200
# File 'lib/rack/cors.rb', line 198

def hit
  @hit
end

#miss_reasonObject

Returns the value of attribute miss_reason.



198
199
200
# File 'lib/rack/cors.rb', line 198

def miss_reason
  @miss_reason
end

#preflightObject

Returns the value of attribute preflight.



198
199
200
# File 'lib/rack/cors.rb', line 198

def preflight
  @preflight
end

Class Method Details

.hit(env) ⇒ Object



208
209
210
211
212
213
# File 'lib/rack/cors.rb', line 208

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

.miss(env, reason) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/rack/cors.rb', line 215

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

.preflight_hit(env) ⇒ Object



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

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

.preflight_miss(env, reason) ⇒ Object



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

def self.preflight_miss(env, reason)
  r = Result.new
  r.preflight = true
  r.hit = false
  r.miss_reason = reason
  env[ENV_KEY] = r
end

Instance Method Details

#append_header(headers) ⇒ Object



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

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)


200
201
202
# File 'lib/rack/cors.rb', line 200

def hit?
  !!hit
end

#preflight?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/rack/cors.rb', line 204

def preflight?
  !!preflight
end