module Roda::RodaPlugins::Public::RequestMethods
def public
def public public_serve_with(roda_class.opts[:public_server]) end
def public_file_readable?(path)
def public_file_readable?(path) ::File.file?(path) && ::File.readable?(path) rescue SystemCallError # :nocov: false # :nocov: end
def public_path_segments(path)
Return an array of segments for the given path, handling ..
def public_path_segments(path) segments = [] path.split(SPLIT).each do |seg| next if seg.empty? || seg == '.' seg == '..' ? segments.pop : segments << seg end segments end
def public_serve(server, path)
def public_serve(server, path) server.serving(self, path) end
def public_serve(server, path)
def public_serve(server, path) server = server.dup server.path = path server.serving(env) end
def public_serve_compressed(server, path, suffix, encoding)
Serve the compressed file if it exists. This should only
def public_serve_compressed(server, path, suffix, encoding) compressed_path = path + suffix if public_file_readable?(compressed_path) s, h, b = public_serve(server, compressed_path) headers = response.headers headers.replace(h) unless s == 304 headers[RodaResponseHeaders::CONTENT_TYPE] = ::Rack::Mime.mime_type(::File.extname(path), 'text/plain') headers[RodaResponseHeaders::CONTENT_ENCODING] = encoding end halt [s, headers, b] end end
def public_serve_with(server)
def public_serve_with(server) return unless is_get? path = PARSER.unescape(real_remaining_path) return if path.include?("\0") roda_opts = roda_class.opts path = ::File.join(server.root, *public_path_segments(path)) if accept_encoding = env['HTTP_ACCEPT_ENCODING'] roda_opts[:public_encodings].each do |enc, ext, regexp| if regexp.send(MATCH_METHOD, accept_encoding) public_serve_compressed(server, path, ext, enc) end end end if public_file_readable?(path) s, h, b = public_serve(server, path) headers = response.headers headers.replace(h) halt [s, headers, b] end end