The mixin that adds methods to Strelka::HTTPRequest for Cross-Origin Resource Sharing (CORS).
Returns true
if the request contains an Origin header whose
URI has a host that's different than its Host: header.
# File lib/strelka/httprequest/cors.rb, line 37
def cross_origin?
return self.origin && self.headers.host != self.origin.host
end
Return the URI in the Origin header (if the request has one) as a URI object. If the request doesn't have an Origin: header, returns nil.
# File lib/strelka/httprequest/cors.rb, line 25
def origin
unless @origin
origin_uri = self.headers.origin or return nil
@origin = URI( origin_uri )
end
return @origin
end
Returns true
if the receiver is a CORS
preflight request.
# File lib/strelka/httprequest/cors.rb, line 44
def preflight?
return self.origin &&
self.verb == :OPTIONS &&
self.header.access_control_request_method
end
Add some instance variables to the request object.
# File lib/strelka/httprequest/cors.rb, line 12
def initialize( * ) # :notnew:
super
@origin = nil
end