class Puppet::Network::HTTP::Route
Constants
- MethodNotAllowedHandler
- NO_HANDLERS
Attributes
path_matcher[R]
Public Class Methods
new(path_matcher)
click to toggle source
# File lib/puppet/network/http/route.rb 15 def initialize(path_matcher) 16 @path_matcher = path_matcher 17 @method_handlers = { 18 :GET => NO_HANDLERS, 19 :HEAD => NO_HANDLERS, 20 :OPTIONS => NO_HANDLERS, 21 :POST => NO_HANDLERS, 22 :PUT => NO_HANDLERS, 23 :DELETE => NO_HANDLERS 24 } 25 @chained = [] 26 end
path(path_matcher)
click to toggle source
# File lib/puppet/network/http/route.rb 11 def self.path(path_matcher) 12 new(path_matcher) 13 end
Public Instance Methods
any(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 58 def any(*handlers) 59 @method_handlers.each do |method, registered_handlers| 60 @method_handlers[method] = handlers 61 end 62 return self 63 end
chain(*routes)
click to toggle source
# File lib/puppet/network/http/route.rb 65 def chain(*routes) 66 @chained = routes 67 self 68 end
delete(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 53 def delete(*handlers) 54 @method_handlers[:DELETE] = handlers 55 return self 56 end
get(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 28 def get(*handlers) 29 @method_handlers[:GET] = handlers 30 return self 31 end
head(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 33 def head(*handlers) 34 @method_handlers[:HEAD] = handlers 35 return self 36 end
inspect()
click to toggle source
# File lib/puppet/network/http/route.rb 93 def inspect 94 "Route #{@path_matcher.inspect}" 95 end
matches?(request)
click to toggle source
# File lib/puppet/network/http/route.rb 70 def matches?(request) 71 Puppet.debug { "Evaluating match for #{self.inspect}" } 72 if match(request.routing_path) 73 return true 74 else 75 Puppet.debug { "Did not match path (#{request.routing_path.inspect})" } 76 end 77 return false 78 end
options(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 38 def options(*handlers) 39 @method_handlers[:OPTIONS] = handlers 40 return self 41 end
post(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 43 def post(*handlers) 44 @method_handlers[:POST] = handlers 45 return self 46 end
process(request, response)
click to toggle source
# File lib/puppet/network/http/route.rb 80 def process(request, response) 81 handlers = @method_handlers[request.method.upcase.intern] || NO_HANDLERS 82 handlers.each do |handler| 83 handler.call(request, response) 84 end 85 86 subrequest = request.route_into(match(request.routing_path).to_s) 87 chained_route = @chained.find { |route| route.matches?(subrequest) } 88 if chained_route 89 chained_route.process(subrequest, response) 90 end 91 end
put(*handlers)
click to toggle source
# File lib/puppet/network/http/route.rb 48 def put(*handlers) 49 @method_handlers[:PUT] = handlers 50 return self 51 end
Private Instance Methods
match(path)
click to toggle source
# File lib/puppet/network/http/route.rb 99 def match(path) 100 @path_matcher.match(path) 101 end