Class: Hanami::Routing::HttpRouter Private
- Inherits:
-
HttpRouter
- Object
- HttpRouter
- Hanami::Routing::HttpRouter
- Defined in:
- lib/hanami/routing/http_router.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
HTTP router
This implementation is based on ::HttpRouter (http_router gem).
Hanami::Router wraps an instance of this class, in order to protect its public API from any future change of ::HttpRouter.
Constant Summary collapse
- SCRIPT_NAME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Script name - rack environment variable
'SCRIPT_NAME'.freeze
- PATH_INFO =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path info - rack environment variable
'PATH_INFO'.freeze
- DEFAULT_PATH_INFO =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default PATH_INFO for Rack requests
'/'.freeze
- URL_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
URL separator
'/'.freeze
Instance Attribute Summary collapse
- #namespace ⇒ Object readonly private
- #prefix ⇒ Object readonly private
Instance Method Summary collapse
-
#action_separator ⇒ Object
private
Separator between controller and action name.
-
#find(options) ⇒ Object
private
Finds a path from the given options.
-
#initialize(options = {}, &blk) ⇒ HttpRouter
constructor
private
Initialize the router.
-
#mount(app, options) ⇒ Object
private
Allow to mount a Rack app.
- #no_response(request, env) ⇒ Object private
-
#options(path, options = {}, &blk) ⇒ Object
private
Support for OPTIONS HTTP verb.
- #pass_on_response(response) ⇒ Object private
- #raw_call(env, &blk) ⇒ Object private
-
#raw_path(route, *args) ⇒ Object
private
Generate a relative URL for a specified named route.
-
#raw_url(route, *args) ⇒ Object
private
Generate an absolute URL for a specified named route.
- #reset! ⇒ Object private
- #rewrite_partial_path_info(env, request) ⇒ Object private
Constructor Details
#initialize(options = {}, &blk) ⇒ HttpRouter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the router.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hanami/routing/http_router.rb', line 69 def initialize( = {}, &blk) if [:parsers] = 'Hanami::Router options[:parsers] is deprecated and it will be removed in future versions' Hanami::Utils::Deprecation.new() end @compiled = false @uri_parser = URI::Parser.new super(, &nil) @namespace = [:namespace] if [:namespace] @default_scheme = [:scheme] if [:scheme] @default_host = [:host] if [:host] @default_port = [:port] if [:port] @route_class = [:route] || Routing::Route @resolver = [:resolver] || Routing::EndpointResolver.new() @parsers = Routing::Parsers.new([:parsers]) @prefix = Utils::PathPrefix.new([:prefix] || '') @force_ssl = Hanami::Routing::ForceSsl.new(!![:force_ssl], host: @default_host, port: @default_port) end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 |
# File 'lib/hanami/routing/http_router.rb', line 57 def namespace @namespace end |
#prefix ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 |
# File 'lib/hanami/routing/http_router.rb', line 61 def prefix @prefix end |
Instance Method Details
#action_separator ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Separator between controller and action name.
95 96 97 |
# File 'lib/hanami/routing/http_router.rb', line 95 def action_separator @resolver.action_separator end |
#find(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds a path from the given options.
105 106 107 |
# File 'lib/hanami/routing/http_router.rb', line 105 def find() @resolver.find() end |
#mount(app, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allow to mount a Rack app
149 150 151 152 153 |
# File 'lib/hanami/routing/http_router.rb', line 149 def mount(app, ) add("#{ .fetch(:at) }*", host: [:host]).to( @resolver.resolve(to: app) ) end |
#no_response(request, env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
177 178 179 180 181 182 183 |
# File 'lib/hanami/routing/http_router.rb', line 177 def no_response(request, env) if request.acceptable_methods.any? && !request.acceptable_methods.include?(env['REQUEST_METHOD']) [405, {'Allow' => request.acceptable_methods.sort.join(", ")}, []] else @default_app.call(env) end end |
#options(path, options = {}, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Support for OPTIONS HTTP verb
139 140 141 |
# File 'lib/hanami/routing/http_router.rb', line 139 def (path, = {}, &blk) add_with_request_method(path, :options, , &blk) end |
#pass_on_response(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
172 173 174 |
# File 'lib/hanami/routing/http_router.rb', line 172 def pass_on_response(response) super response.to_a end |
#raw_call(env, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
156 157 158 159 160 161 162 |
# File 'lib/hanami/routing/http_router.rb', line 156 def raw_call(env, &blk) if response = @force_ssl.call(env) response else super(@parsers.call(env)) end end |
#raw_path(route, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a relative URL for a specified named route.
115 116 117 118 119 |
# File 'lib/hanami/routing/http_router.rb', line 115 def raw_path(route, *args) _rescue_url_recognition do _custom_path(super(route, *args)) end end |
#raw_url(route, *args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate an absolute URL for a specified named route.
127 128 129 130 131 |
# File 'lib/hanami/routing/http_router.rb', line 127 def raw_url(route, *args) _rescue_url_recognition do _custom_path(super(route, *args)) end end |
#reset! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
165 166 167 168 169 |
# File 'lib/hanami/routing/http_router.rb', line 165 def reset! uncompile @routes, @named_routes, @root = [], Hash.new{|h,k| h[k] = []}, Node::Root.new(self) @default_host, @default_port, @default_scheme = 'localhost', 80, 'http' end |
#rewrite_partial_path_info(env, request) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/hanami/routing/http_router.rb', line 186 def rewrite_partial_path_info(env, request) if request.path.empty? env[SCRIPT_NAME] += env[PATH_INFO] env[PATH_INFO] = DEFAULT_PATH_INFO else path_info_before = env[PATH_INFO].dup env[PATH_INFO] = "/#{@uri_parser.escape(request.path.join(URL_SEPARATOR))}" env[SCRIPT_NAME] += path_info_before[0, path_info_before.bytesize - env[PATH_INFO].bytesize] end end |