diff --git a/kong.conf.default b/kong.conf.default index 1b849c763942..cdca4f01aa3d 100644 --- a/kong.conf.default +++ b/kong.conf.default @@ -222,7 +222,7 @@ # stack traces to help improve Kong. -#proxy_server # Proxy server defined as a URL. Kong will only use +#proxy_server = # Proxy server defined as a URL. Kong will only use # option if any component is explictly configured # to use proxy. #------------------------------------------------------------------------------ diff --git a/kong/clustering/utils.lua b/kong/clustering/utils.lua index d631f8acb01e..79b1fd8ca341 100644 --- a/kong/clustering/utils.lua +++ b/kong/clustering/utils.lua @@ -7,7 +7,9 @@ local ocsp = require("ngx.ocsp") local http = require("resty.http") local ws_client = require("kong.resty.websocket.client") local ws_server = require("resty.websocket.server") -local parse_url = require("kong.tools.utils").parse_url +local utils = require("kong.tools.utils") +local meta = require("kong.meta") +local parse_url = require "socket.url".parse local type = type local tonumber = tonumber diff --git a/kong/conf_loader/init.lua b/kong/conf_loader/init.lua index d721e9bcfa21..04ec5ed58fe8 100644 --- a/kong/conf_loader/init.lua +++ b/kong/conf_loader/init.lua @@ -7,6 +7,7 @@ local openssl_pkey = require "resty.openssl.pkey" local openssl_x509 = require "resty.openssl.x509" local pl_stringio = require "pl.stringio" local pl_stringx = require "pl.stringx" +local socket_url = require "socket.url" local constants = require "kong.constants" local listeners = require "kong.conf_loader.listeners" local pl_pretty = require "pl.pretty" @@ -987,7 +988,7 @@ local function check_and_infer(conf, opts) end if conf.proxy_server then - local parsed, err = utils.parse_url(conf.proxy_server) + local parsed, err = socket_url.parse(conf.proxy_server) if err then errors[#errors + 1] = "proxy_server is invalid: " .. err diff --git a/kong/tools/utils.lua b/kong/tools/utils.lua index 98cba939cfbb..39f74f31b85b 100644 --- a/kong/tools/utils.lua +++ b/kong/tools/utils.lua @@ -33,7 +33,6 @@ local lower = string.lower local fmt = string.format local find = string.find local gsub = string.gsub -local match = string.match local split = pl_stringx.split local re_find = ngx.re.find local re_match = ngx.re.match @@ -1567,75 +1566,4 @@ _M.sha256_hex = sha256_hex _M.sha256_base64 = sha256_base64 _M.sha256_base64url = sha256_base64url - ------------------------------------------------------------------------------ --- From https://github.com/lunarmodules/luasocket/blob/master/src/url.lua --- Parses a url and returns a table with all its parts according to RFC 2396 --- The following grammar describes the names given to the URL parts --- ::= :///;?# --- ::= @: --- ::= [:] --- :: = {/} --- Input --- url: uniform resource locator of request --- default: table with default values for each field --- Returns --- table with the following fields, where RFC naming conventions have --- been preserved: --- scheme, authority, userinfo, user, password, host, port, --- path, params, query, fragment --- Obs: --- the leading '/' in {/} is considered part of ------------------------------------------------------------------------------ -_M.parse_url = function(url, default) - -- initialize default parameters - local parsed = {} - for i,v in pairs(default or parsed) do parsed[i] = v end - -- empty url is parsed to nil - if not url or url == "" then return nil, "invalid url" end - -- remove whitespace - -- url = string.gsub(url, "%s", "") - -- get scheme - url = gsub(url, "^([%w][%w%+%-%.]*)%:", - function(s) parsed.scheme = s; return "" end) - -- get authority - url = gsub(url, "^//([^/]*)", function(n) - parsed.authority = n - return "" - end) - -- get fragment - url = gsub(url, "#(.*)$", function(f) - parsed.fragment = f - return "" - end) - -- get query string - url = gsub(url, "%?(.*)", function(q) - parsed.query = q - return "" - end) - -- get params - url = gsub(url, "%;(.*)", function(p) - parsed.params = p - return "" - end) - -- path is whatever was left - if url ~= "" then parsed.path = url end - local authority = parsed.authority - if not authority then return parsed end - authority = gsub(authority,"^([^@]*)@", - function(u) parsed.userinfo = u; return "" end) - authority = gsub(authority, ":([^:%]]*)$", - function(p) parsed.port = p; return "" end) - if authority ~= "" then - -- IPv6? - parsed.host = match(authority, "^%[(.+)%]$") or authority - end - local userinfo = parsed.userinfo - if not userinfo then return parsed end - userinfo = gsub(userinfo, ":([^:]*)$", - function(p) parsed.password = p; return "" end) - parsed.user = userinfo - return parsed -end - return _M