Strelka::HTTPRequest::

CORS

module

The mixin that adds methods to Strelka::HTTPRequest for Cross-Origin Resource Sharing (CORS).

Public Instance Methods

anchor
cross_origin?()

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
Also aliased as: is_cross_origin?
anchor
is_cross_origin?()
Alias for: cross_origin?
anchor
is_preflight?()
Alias for: preflight?
anchor
origin()

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
anchor
preflight?()

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
Also aliased as: is_preflight?

Protected Instance Methods

anchor
initialize( * )

Add some instance variables to the request object.

# File lib/strelka/httprequest/cors.rb, line 12
def initialize( * ) # :notnew:
        super
        @origin = nil
end