1 # -*- encoding: binary -*-
2 module Metropolis::Common
3 include Rack::Utils # unescape
4 autoload :RO, 'metropolis/common/ro'
7 @headers = { 'Content-Type' => 'application/octet-stream' }
8 @headers.merge!(opts[:response_headers] || {})
9 @nr_slots = opts[:nr_slots]
14 raise ArgumentError, ":path_pattern may only be used if path is '/'"
15 @path_pattern.scan(/%\d*x/).size == 1 or
16 raise ArgumentError, "only one '/%\d*x/' may appear in #@path_pattern"
19 raise ArgumentError, ":nr_slots may be used with :path_pattern"
22 @readonly = !!opts[:readonly]
23 @exclusive = !!opts[:exclusive]
24 if @readonly && @exclusive
25 raise ArgumentError, ":readonly and :exclusive may not be used together"
27 case @encoding = opts[:encoding]
30 extend(Metropolis::Deflate)
32 extend(Metropolis::Gzip)
34 raise ArgumentError, "unsupported encoding"
38 def r(code, body = nil)
39 body ||= "#{HTTP_STATUS_CODES[code]}\n"
41 { 'Content-Length' => body.size.to_s, 'Content-Type' => 'text/plain' },
46 if %r{\A/(.*)\z} =~ env["PATH_INFO"]
48 case env["REQUEST_METHOD"]
65 # generic HEAD implementation, some databases can optimize this by
66 # not retrieving the value