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.



166
167
168
# File 'lib/rack/cors.rb', line 166

def hit
  @hit
end

#miss_reasonObject

Returns the value of attribute miss_reason.



166
167
168
# File 'lib/rack/cors.rb', line 166

def miss_reason
  @miss_reason
end

#preflightObject

Returns the value of attribute preflight.



166
167
168
# File 'lib/rack/cors.rb', line 166

def preflight
  @preflight
end

Class Method Details

.hit(env) ⇒ Object



176
177
178
179
180
181
# File 'lib/rack/cors.rb', line 176

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

.miss(env, reason) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/rack/cors.rb', line 183

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



191
192
193
194
195
196
# File 'lib/rack/cors.rb', line 191

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

.preflight_miss(env, reason) ⇒ Object



198
199
200
201
202
203
204
# File 'lib/rack/cors.rb', line 198

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



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

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

#hit?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/rack/cors.rb', line 168

def hit?
  !!hit
end

#preflight?Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/rack/cors.rb', line 172

def preflight?
  !!preflight
end