Class: Waitress::DirHandler
- Defined in:
- lib/waitress/handlers/dirhandler.rb
Overview
The DirHandler class is an instance of Waitress::Handler
that is responsible for loading files from the filesystem and serving them if they exist in the VHost’s root. It automatically handles mimetypes, evaluation and almost everything about the serving process for files in the FileSystem.
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#priority ⇒ Object
Returns the value of attribute priority.
Class Method Summary collapse
-
.resources_handler ⇒ Object
Get the instance of DirHandler that will load Waitress’ resources such as the default 404 and index pages, as well as CSS and JS.
Instance Method Summary collapse
-
#initialize(directory, priority = 50) ⇒ DirHandler
constructor
Create a new DirHandler, with the given FileSystem directory as a root and priority.
- #respond?(request, vhost) ⇒ Boolean
- #serve(request, response, client, vhost) ⇒ Object
Methods inherited from Handler
Constructor Details
#initialize(directory, priority = 50) ⇒ DirHandler
Create a new DirHandler, with the given FileSystem directory as a root and priority.
21 22 23 24 |
# File 'lib/waitress/handlers/dirhandler.rb', line 21 def initialize directory, priority=50 @directory = File.absolute_path(directory) @priority = priority end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
10 11 12 |
# File 'lib/waitress/handlers/dirhandler.rb', line 10 def directory @directory end |
#priority ⇒ Object
Returns the value of attribute priority.
9 10 11 |
# File 'lib/waitress/handlers/dirhandler.rb', line 9 def priority @priority end |
Class Method Details
.resources_handler ⇒ Object
Get the instance of DirHandler that will load Waitress’ resources such as the default 404 and index pages, as well as CSS and JS
14 15 16 17 |
# File 'lib/waitress/handlers/dirhandler.rb', line 14 def self.resources_handler @@resources_handler ||= Waitress::DirHandler.new(Waitress::Chef.resources_http, -1000) @@resources_handler end |
Instance Method Details
#respond?(request, vhost) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/waitress/handlers/dirhandler.rb', line 26 def respond? request, vhost path = File. File.join("#{directory}", request.path) res = Waitress::Chef.find_file(path)[:result] path.include?(directory) && (res == :ok) end |
#serve(request, response, client, vhost) ⇒ Object
32 33 34 35 36 |
# File 'lib/waitress/handlers/dirhandler.rb', line 32 def serve request, response, client, vhost path = File. File.join("#{directory}", request.path) file = Waitress::Chef.find_file(path)[:file] Waitress::Chef.serve_file request, response, client, vhost, file end |