提交 cbceb78f 编写于 作者: K Kasper Timm Hansen

Extract method to share path expansion logic.

Then just yield the location for the place where we need some extra processing.
上级 0e8b4e11
......@@ -327,19 +327,17 @@ def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: n
request_encoder = RequestEncoder.encoder(as)
if path =~ %r{://}
location = URI.parse(path)
path = build_expanded_path(path, request_encoder) do |location|
https! URI::HTTPS === location if location.scheme
if url_host = location.host
default = Rack::Request::DEFAULT_PORTS[location.scheme]
url_host += ":#{location.port}" if default != location.port
host! url_host
end
path = request_encoder.append_format_to location.path
path = location.query ? "#{path}?#{location.query}" : path
end
elsif as
location = URI.parse(path)
path = request_encoder.append_format_to location.path
path = location.query ? "#{path}?#{location.query}" : path
path = build_expanded_path(path, request_encoder)
end
hostname, port = host.split(':')
......@@ -398,6 +396,13 @@ def build_full_uri(path, env)
"#{env['rack.url_scheme']}://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{path}"
end
def build_expanded_path(path, request_encoder)
location = URI.parse(path)
yield location if block_given?
path = request_encoder.append_format_to location.path
location.query ? "#{path}?#{location.query}" : path
end
class RequestEncoder # :nodoc:
@encoders = {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册