Sha256: 43b636c4d3d94c9736ac65f98e28f54f4a7d3f19b2f3b3493322909e233bda62
Contents?: true
Size: 1.42 KB
Versions: 3
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true require "rack" module Dassets; end class Dassets::Server; end class Dassets::Server::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_file(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(%r{/(.+)-[a-f0-9]{32}(\..+|)$}i) || NullDigestMatch.new end end class NullDigestMatch def captures [] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dassets-0.15.3 | lib/dassets/server/request.rb |
dassets-0.15.2 | lib/dassets/server/request.rb |
dassets-0.15.1 | lib/dassets/server/request.rb |