Sha256: d13ffd0a90e3e7a27070144437afd552a331a7319eb90a81eed8fdd106574df3
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require "rack/utils" class Propshaft::Server def initialize(assembly) @assembly = assembly end def call(env) path, digest = extract_path_and_digest(env) if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest) compiled_content = @assembly.compilers.compile(asset) [ 200, { Rack::CONTENT_LENGTH => compiled_content.length.to_s, Rack::CONTENT_TYPE => asset.content_type.to_s, VARY => "Accept-Encoding", Rack::ETAG => asset.digest, Rack::CACHE_CONTROL => "public, max-age=31536000, immutable" }, [ compiled_content ] ] else [ 404, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "9" }, [ "Not found" ] ] end end def inspect self.class.inspect end private def extract_path_and_digest(env) full_path = Rack::Utils.unescape(env["PATH_INFO"].to_s.sub(/^\//, "")) digest = full_path[/-([0-9a-zA-Z]{7,128})\.(?!digested)[^.]+\z/, 1] path = digest ? full_path.sub("-#{digest}", "") : full_path [ path, digest ] end if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3") VARY = "Vary" else VARY = "vary" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
propshaft-0.8.0 | lib/propshaft/server.rb |