Module: Roda::RodaPlugins::RenderStatic::RequestMethods
- Defined in:
- lib/zleb/plugins/render_static.rb
Instance Method Summary collapse
-
#render_static(render_path) ⇒ Object
Serve files from the public directory if the file exists and this is a GET request.
Instance Method Details
#render_static(render_path) ⇒ Object
Serve files from the public directory if the file exists and this is a GET request.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/zleb/plugins/render_static.rb', line 66 def render_static(render_path) if is_get? path = PARSER.unescape(render_path) return if path.include?("\0") roda_opts = roda_class.opts server = roda_opts[:public_server] path = ::File.join(server.root, *public_path_segments(path)) if roda_opts[:public_gzip] && env['HTTP_ACCEPT_ENCODING'] =~ /\bgzip\b/ gzip_path = path + '.gz' if public_file_readable?(gzip_path) res = public_serve(server, gzip_path) headers = res[1] unless res[0] == 304 if mime_type = ::Rack::Mime.mime_type(::File.extname(path), 'text/plain') headers['Content-Type'] = mime_type end headers['Content-Encoding'] = 'gzip' end halt res end end if public_file_readable?(path) halt public_serve(server, path) end end end |