Sha256: 3c3634af466a94b162fd849f3ecd8e22d6bc6669dce37b6da68bd9d84ddf3782

Contents?: true

Size: 774 Bytes

Versions: 6

Compression:

Stored size: 774 Bytes

Contents

# Attempt to serve static files from public directory. Throws :halt when
# a matching file is found, returns nil otherwise.
def static!
  return if (public_dir = configs.public).nil?
  public_dir = File.expand_path(public_dir)

  path = File.expand_path(public_dir + unescape(request.path_info))
  return if path[0, public_dir.length] != public_dir
  return unless File.file?(path)

  env['sinatra.static_file'] = path
  send_file path, :disposition => nil
end


# Dispatch a request with error handling.
def dispatch!
  static! if configs.static? && (request.get? || request.head?)
  filter! :before
  route!
rescue NotFound => boom
  handle_not_found!(boom)
rescue ::Exception => boom
  handle_exception!(boom)
ensure
  filter! :after unless env['sinatra.static_file']
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
crystal-0.0.10 lib/crystal/rack/middleware/static_files.rb
crystal-0.0.8 crystal/lib/crystal/rack/middleware/static_files.rb
crystal-0.0.7 crystal/lib/crystal/rack/middleware/static_files.rb
crystal-0.0.6 crystal/lib/crystal/rack/middleware/static_files.rb
crystal-0.0.5 lib/crystal/rack/middleware/static_files.rb
crystal-0.0.4 lib/crystal/rack/middleware/static_files.rb