Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions http_router.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |s|
# dependencies
s.add_runtime_dependency 'rack', '>= 1.0.0'
s.add_runtime_dependency 'url_mount', '~> 0.2.1'
s.add_runtime_dependency 'addressable', '~> 2.4'
s.add_development_dependency 'minitest', '~> 2.0.0'
s.add_development_dependency 'code_stats'
s.add_development_dependency 'rake', '~> 0.8.7'
Expand Down
5 changes: 4 additions & 1 deletion lib/http_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def initialize(*args, &blk)
@ignore_trailing_slash = options && options.key?(:ignore_trailing_slash) ? options[:ignore_trailing_slash] : true
@redirect_trailing_slash = options && options.key?(:redirect_trailing_slash) ? options[:redirect_trailing_slash] : false
@route_class = Route
@compiled = false
reset!
instance_eval(&blk) if blk
end
Expand Down Expand Up @@ -118,7 +119,9 @@ def route_class
# Adds a path that only responds to the request method +GET+.
#
# Returns the route object.
def get(path, opts = {}, &app); add_with_request_method(path, [:get, :head], opts, &app); end
def get(path, opts = {}, &app)
add_with_request_method(path, [:get, :head], opts, &app)
end

# Performs recoginition without actually calling the application and returns an array of all
# matching routes or nil if no match was found.
Expand Down
10 changes: 6 additions & 4 deletions lib/http_router/generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'addressable/uri'

class HttpRouter
class Generator
SCHEME_PORTS = {'http' => 80, 'https' => 443}
Expand Down Expand Up @@ -36,13 +38,13 @@ def initialize(route, path, validation_regex = nil)
instance_eval <<-EOT, __FILE__, __LINE__ + 1
def generate(args, options)
generated_path = \"#{code}\"
#{validation_regex.inspect}.match(generated_path) ? URI.escape(generated_path) : nil
#{validation_regex.inspect}.match(generated_path) ? Addressable::URI.escape(generated_path) : nil
end
EOT
else
instance_eval <<-EOT, __FILE__, __LINE__ + 1
def generate(args, options)
URI.escape(\"#{code}\")
Addressable::URI.escape(\"#{code}\")
end
EOT
end
Expand All @@ -55,7 +57,7 @@ def initialize(route, paths)
@router = @route.router
@route.generator = self
@path_generators = @paths.map do |p|
generator = PathGenerator.new(route, p.is_a?(String) ? p : route.path_for_generation, p.is_a?(Regexp) ? p : nil)
PathGenerator.new(route, p.is_a?(String) ? p : route.path_for_generation, p.is_a?(Regexp) ? p : nil)
end
end

Expand Down Expand Up @@ -147,4 +149,4 @@ def append_querystring(uri, params)
uri
end
end
end
end
4 changes: 2 additions & 2 deletions lib/http_router/node/abstract_request_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def to_code
def inspect_label
"#{self.class.name.split("::").last} #{tests.inspect} (#{@matchers.size} matchers)"
end
end
end
end
end
end
6 changes: 4 additions & 2 deletions lib/http_router/request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'addressable/uri'

class HttpRouter
class Request
attr_accessor :path, :params, :rack_request, :extra_env, :continue, :passed_with, :called
Expand All @@ -7,7 +9,7 @@ class Request

def initialize(path, rack_request)
@rack_request = rack_request
@path = URI.unescape(path).split(/\//)
@path = Addressable::URI.unescape(path).split(/\//)
@path.shift if @path.first == ''
@path.push('') if path[-1] == ?/
@extra_env = {}
Expand All @@ -27,4 +29,4 @@ def path_finished?
@path.size == 0 or @path.size == 1 && @path.first == ''
end
end
end
end
6 changes: 5 additions & 1 deletion lib/http_router/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
class HttpRouter
class Route
# The list of HTTP request methods supported by HttpRouter.
VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE PATCH OPTIONS LINK UNLINK}
VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE PATCH LINK UNLINK}
VALID_HTTP_VERBS_WITHOUT_GET = VALID_HTTP_VERBS - %w{GET}

attr_reader :default_values, :other_hosts, :paths, :request_methods, :name
attr_accessor :match_partially, :router, :host, :user_agent, :ignore_trailing_slash,
:path_for_generation, :path_validation_regex, :generator, :scheme, :original_path, :dest

def initialize
@match_with = nil
end

def create_clone(new_router)
r = clone
r.dest = (begin; dest.clone; rescue; dest; end)
Expand Down
4 changes: 2 additions & 2 deletions lib/http_router/route_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def static(root)
@match_partially = true if File.directory?(root)
to File.directory?(root) ?
::Rack::File.new(root) :
proc {|env|
proc {|env|
env['PATH_INFO'] = File.basename(root)
::Rack::File.new(File.dirname(root)).call(env)
}
end
end
end
end