mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-11 09:43:49 +08:00
chore: format the string.find (#2785)
This commit is contained in:
parent
e7223e77a3
commit
208ae3d2b7
@ -36,6 +36,7 @@ setmetatable(_M, {__index = string})
|
||||
|
||||
|
||||
-- find a needle from a haystack in the plain text way
|
||||
-- note: Make sure that the haystack is 'string' type, otherwise an exception will be thrown.
|
||||
function _M.find(haystack, needle, from)
|
||||
return str_find(haystack, needle, from or 1, true)
|
||||
end
|
||||
|
@ -28,7 +28,7 @@ local ngx = ngx
|
||||
local ngx_timer_at = ngx.timer.at
|
||||
local ngx_timer_every = ngx.timer.every
|
||||
local string_sub = string.sub
|
||||
local string_find = string.find
|
||||
local str_find = core.string.find
|
||||
local log = core.log
|
||||
|
||||
local default_weight
|
||||
@ -76,9 +76,9 @@ local function service_info()
|
||||
local basic_auth
|
||||
-- TODO Add health check to get healthy nodes.
|
||||
local url = host[math_random(#host)]
|
||||
local auth_idx = string_find(url, "@", 1, true)
|
||||
local auth_idx = str_find(url, "@")
|
||||
if auth_idx then
|
||||
local protocol_idx = string_find(url, "://", 1, true)
|
||||
local protocol_idx = str_find(url, "://")
|
||||
local protocol = string_sub(url, 1, protocol_idx + 2)
|
||||
local user_and_password = string_sub(url, protocol_idx + 3, auth_idx - 1)
|
||||
local other = string_sub(url, auth_idx + 1)
|
||||
|
@ -20,7 +20,7 @@ local plugin = require("apisix.plugin")
|
||||
local ngx = ngx
|
||||
local ipairs = ipairs
|
||||
local pairs = pairs
|
||||
local str_find = string.find
|
||||
local str_find = core.string.find
|
||||
local str_lower = string.lower
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ local function set_common_header(data)
|
||||
|
||||
if outer_headers then
|
||||
for k, v in pairs(outer_headers) do
|
||||
local is_content_header = str_find(k, "content-", 1, true) == 1
|
||||
local is_content_header = str_find(k, "content-") == 1
|
||||
-- skip header start with "content-"
|
||||
if not req.headers[k] and not is_content_header then
|
||||
req.headers[k] = v
|
||||
|
@ -17,7 +17,7 @@
|
||||
local core = require("apisix.core")
|
||||
local ngx = ngx
|
||||
local plugin_name = "cors"
|
||||
local str_find = string.find
|
||||
local str_find = core.string.find
|
||||
local re_gmatch = ngx.re.gmatch
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ local _M = {
|
||||
|
||||
|
||||
local function create_mutiple_origin_cache(conf)
|
||||
if not str_find(conf.allow_origins, ",", 1, true) then
|
||||
if not str_find(conf.allow_origins, ",") then
|
||||
return nil
|
||||
end
|
||||
local origin_cache = {}
|
||||
|
@ -18,7 +18,7 @@ local ipairs = ipairs
|
||||
local core = require("apisix.core")
|
||||
local ipmatcher = require("resty.ipmatcher")
|
||||
local str_sub = string.sub
|
||||
local str_find = string.find
|
||||
local str_find = core.string.find
|
||||
local tonumber = tonumber
|
||||
local lrucache = core.lrucache.new({
|
||||
ttl = 300, count = 512
|
||||
@ -69,7 +69,7 @@ local _M = {
|
||||
|
||||
local function valid_ip(ip)
|
||||
local mask = 0
|
||||
local sep_pos = str_find(ip, "/", 1, true)
|
||||
local sep_pos = str_find(ip, "/")
|
||||
if sep_pos then
|
||||
mask = str_sub(ip, sep_pos + 1)
|
||||
mask = tonumber(mask)
|
||||
|
@ -25,6 +25,7 @@ local io = io
|
||||
local os = os
|
||||
local table = table
|
||||
local string = string
|
||||
local str_find = core.string.find
|
||||
local local_conf
|
||||
|
||||
|
||||
@ -57,7 +58,7 @@ end
|
||||
|
||||
local function get_last_index(str, key)
|
||||
local rev = string.reverse(str)
|
||||
local _, idx = string.find(rev, key, 1, true)
|
||||
local _, idx = str_find(rev, key)
|
||||
local n
|
||||
if idx then
|
||||
n = string.len(rev) - idx + 1
|
||||
|
@ -22,7 +22,7 @@ local ngx = ngx
|
||||
local type = type
|
||||
local re_sub = ngx.re.sub
|
||||
local sub_str = string.sub
|
||||
local find_str = string.find
|
||||
local str_find = core.string.find
|
||||
|
||||
local schema = {
|
||||
type = "object",
|
||||
@ -158,7 +158,7 @@ function _M.rewrite(conf, ctx)
|
||||
end
|
||||
end
|
||||
|
||||
local index = find_str(upstream_uri, "?", 1, true)
|
||||
local index = str_find(upstream_uri, "?")
|
||||
if index then
|
||||
upstream_uri = core.utils.uri_safe_encode(sub_str(upstream_uri, 1, index-1)) ..
|
||||
sub_str(upstream_uri, index)
|
||||
|
@ -22,7 +22,7 @@ local config_util = require("apisix.core.config_util")
|
||||
local ipairs = ipairs
|
||||
local type = type
|
||||
local error = error
|
||||
local str_find = string.find
|
||||
local str_find = core.string.find
|
||||
local aes = require "resty.aes"
|
||||
local assert = assert
|
||||
local str_gsub = string.gsub
|
||||
@ -218,7 +218,7 @@ function _M.match_and_set(api_ctx)
|
||||
if type(api_ctx.matched_sni) == "table" then
|
||||
local matched = false
|
||||
for _, msni in ipairs(api_ctx.matched_sni) do
|
||||
if sni_rev == msni or not str_find(sni_rev, ".", #msni, true) then
|
||||
if sni_rev == msni or not str_find(sni_rev, ".", #msni) then
|
||||
matched = true
|
||||
end
|
||||
end
|
||||
@ -233,7 +233,7 @@ function _M.match_and_set(api_ctx)
|
||||
return false
|
||||
end
|
||||
else
|
||||
if str_find(sni_rev, ".", #api_ctx.matched_sni, true) then
|
||||
if str_find(sni_rev, ".", #api_ctx.matched_sni) then
|
||||
core.log.warn("failed to find any SSL certificate by SNI: ",
|
||||
sni, " matched SNI: ", api_ctx.matched_sni:reverse())
|
||||
return false
|
||||
|
@ -19,7 +19,7 @@ local json = require("cjson.safe")
|
||||
local core = require("apisix.core")
|
||||
local aes = require "resty.aes"
|
||||
local ngx_encode_base64 = ngx.encode_base64
|
||||
local str_find = string.find
|
||||
local str_find = core.string.find
|
||||
local dir_names = {}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user