Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Nov 17, 2022
1 parent 587a9f9 commit b477a1f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 75 deletions.
2 changes: 1 addition & 1 deletion kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion kong/clustering/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
72 changes: 0 additions & 72 deletions kong/tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
-- <url> ::= <scheme>://<authority>/<path>;<params>?<query>#<fragment>
-- <authority> ::= <userinfo>@<host>:<port>
-- <userinfo> ::= <user>[:<password>]
-- <path> :: = {<segment>/}<segment>
-- 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 {/<path>} is considered part of <path>
-----------------------------------------------------------------------------
_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

0 comments on commit b477a1f

Please sign in to comment.