Class: Wsv::App
- Inherits:
-
Object
- Object
- Wsv::App
- Defined in:
- lib/wsv/app.rb
Constant Summary collapse
- ALLOWED_METHODS =
%w[GET HEAD].freeze
- RANGE_PATTERN =
/\Abytes=(\d+)?-(\d+)?\z/
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(root) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(root) ⇒ App
Returns a new instance of App.
13 14 15 |
# File 'lib/wsv/app.rb', line 13 def initialize(root) @resolver = PathResolver.new(root) end |
Instance Method Details
#call(request) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wsv/app.rb', line 17 def call(request) head = request.head? unless ALLOWED_METHODS.include?(request.method) return Response.text(405, headers: { "Allow" => "GET, HEAD" }, head: head) end raw_path, query = request.target.split("?", 2) result = @resolver.resolve(raw_path) return Response.text(result.status, head: head) if result.error? return Response.redirect(redirect_location(raw_path, query), head: head) if result.redirect? file_response(result.file, request, head: head) end |