Sha256: d7aacf287613272cf51969c068f14d886baa9988cea1a0bab2e5f782516d691b
Contents?: true
Size: 1.43 KB
Versions: 8
Compression:
Stored size: 1.43 KB
Contents
require 'rack' module Dassets; end class Dassets::Server class Request < Rack::Request # The HTTP request method. This is the standard implementation of this # method but is respecified here due to libraries that attempt to modify # the behavior to respect POST tunnel method specifiers. We always want # the real request method. def request_method; @env['REQUEST_METHOD']; end def path_info @env['PATH_INFO'].sub(dassets_base_url, '') end def dassets_base_url Dassets.config.base_url.to_s end # Determine if the request is for an asset file # This will be called on every request so speed is an issue # - first check if the request is a GET or HEAD (fast) # - then check if for a digested asset resource (kinda fast) # - then check if source exists for the digested asset (slower) def for_asset_file? !!((get? || head?) && for_digested_asset? && asset_file.exists?) end def asset_path @asset_path ||= path_digest_match.captures.select{ |m| !m.empty? }.join end def asset_file @asset_file ||= Dassets[asset_path] end private def for_digested_asset? !path_digest_match.captures.empty? end def path_digest_match @path_digest_match ||= begin path_info.match(/\/(.+)-[a-f0-9]{32}(\..+|)$/i) || NullDigestMatch.new end end class NullDigestMatch def captures; []; end end end end
Version data entries
8 entries across 8 versions & 1 rubygems