From d618ab3e966e22655ed3b08f00b93a89ca0992fb Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 19 Oct 2018 11:10:28 +0800 Subject: [PATCH 1/2] bugfix: prevented loading HTTP subsystem only modules in non-HTTP subsystem. Also removed modules loaded repeatly both in global and in HTTP subsystem from resty/core.lua. --- lib/resty/core.lua | 14 ++++++-------- lib/resty/core/base64.lua | 4 +++- lib/resty/core/ctx.lua | 5 ++++- lib/resty/core/exit.lua | 5 ++++- lib/resty/core/hash.lua | 5 ++++- lib/resty/core/misc.lua | 3 ++- lib/resty/core/phase.lua | 4 +++- lib/resty/core/request.lua | 3 ++- lib/resty/core/response.lua | 3 ++- lib/resty/core/uri.lua | 5 ++++- lib/resty/core/var.lua | 4 +++- lib/resty/core/worker.lua | 3 ++- 12 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/resty/core.lua b/lib/resty/core.lua index 0f31e9da9..0192531fa 100644 --- a/lib/resty/core.lua +++ b/lib/resty/core.lua @@ -9,20 +9,18 @@ require "resty.core.time" if subsystem == 'http' then - require "resty.core.uri" - require "resty.core.hash" require "resty.core.base64" - require "resty.core.regex" - require "resty.core.exit" - require "resty.core.var" require "resty.core.ctx" + require "resty.core.exit" + require "resty.core.hash" require "resty.core.misc" + require "resty.core.ndk" + require "resty.core.phase" require "resty.core.request" require "resty.core.response" - require "resty.core.time" + require "resty.core.uri" + require "resty.core.var" require "resty.core.worker" - require "resty.core.phase" - require "resty.core.ndk" end diff --git a/lib/resty/core/base64.lua b/lib/resty/core/base64.lua index 981424cc7..92b4bc5a1 100644 --- a/lib/resty/core/base64.lua +++ b/lib/resty/core/base64.lua @@ -1,9 +1,11 @@ -- Copyright (C) Yichun Zhang (agentzh) -local ffi = require 'ffi' local base = require "resty.core.base" +base.allows_subsystem('http') + +local ffi = require 'ffi' local ffi_string = ffi.string local C = ffi.C local ngx = ngx diff --git a/lib/resty/core/ctx.lua b/lib/resty/core/ctx.lua index e348a7eb4..91c4dc9bc 100644 --- a/lib/resty/core/ctx.lua +++ b/lib/resty/core/ctx.lua @@ -1,9 +1,12 @@ -- Copyright (C) Yichun Zhang (agentzh) +local base = require "resty.core.base" +base.allows_subsystem('http') + + local ffi = require 'ffi' local debug = require 'debug' -local base = require "resty.core.base" local misc = require "resty.core.misc" diff --git a/lib/resty/core/exit.lua b/lib/resty/core/exit.lua index 55d7b6a7c..adc405ed6 100644 --- a/lib/resty/core/exit.lua +++ b/lib/resty/core/exit.lua @@ -1,12 +1,15 @@ -- Copyright (C) Yichun Zhang (agentzh) +local base = require "resty.core.base" +base.allows_subsystem('http') + + local ffi = require 'ffi' local ffi_string = ffi.string local C = ffi.C local ngx = ngx local error = error -local base = require "resty.core.base" local get_string_buf = base.get_string_buf local get_size_ptr = base.get_size_ptr local get_request = base.get_request diff --git a/lib/resty/core/hash.lua b/lib/resty/core/hash.lua index de97270c3..69a47ee5c 100644 --- a/lib/resty/core/hash.lua +++ b/lib/resty/core/hash.lua @@ -1,6 +1,10 @@ -- Copyright (C) Yichun Zhang (agentzh) +local base = require "resty.core.base" +base.allows_subsystem('http') + + local ffi = require 'ffi' local ffi_string = ffi.string local ffi_new = ffi.new @@ -9,7 +13,6 @@ local ngx = ngx local type = type local tostring = tostring local error = error -local base = require "resty.core.base" ffi.cdef[[ diff --git a/lib/resty/core/misc.lua b/lib/resty/core/misc.lua index cd056dcca..9a093ba25 100644 --- a/lib/resty/core/misc.lua +++ b/lib/resty/core/misc.lua @@ -2,9 +2,10 @@ local base = require "resty.core.base" -local ffi = require "ffi" +base.allows_subsystem('http') +local ffi = require "ffi" local FFI_NO_REQ_CTX = base.FFI_NO_REQ_CTX local FFI_BAD_CONTEXT = base.FFI_BAD_CONTEXT local new_tab = base.new_tab diff --git a/lib/resty/core/phase.lua b/lib/resty/core/phase.lua index e8fc3bfe8..f16acf9ea 100644 --- a/lib/resty/core/phase.lua +++ b/lib/resty/core/phase.lua @@ -1,6 +1,8 @@ -local ffi = require 'ffi' local base = require "resty.core.base" +base.allows_subsystem('http') + +local ffi = require 'ffi' local C = ffi.C local FFI_ERROR = base.FFI_ERROR local get_request = base.get_request diff --git a/lib/resty/core/request.lua b/lib/resty/core/request.lua index 895d1fc4a..60b4ab2ba 100644 --- a/lib/resty/core/request.lua +++ b/lib/resty/core/request.lua @@ -1,10 +1,11 @@ -- Copyright (C) Yichun Zhang (agentzh) -local ffi = require 'ffi' local base = require "resty.core.base" +base.allows_subsystem('http') +local ffi = require 'ffi' local FFI_BAD_CONTEXT = base.FFI_BAD_CONTEXT local FFI_DECLINED = base.FFI_DECLINED local FFI_OK = base.FFI_OK diff --git a/lib/resty/core/response.lua b/lib/resty/core/response.lua index c9610d2c0..7eef43c45 100644 --- a/lib/resty/core/response.lua +++ b/lib/resty/core/response.lua @@ -1,10 +1,11 @@ -- Copyright (C) Yichun Zhang (agentzh) -local ffi = require 'ffi' local base = require "resty.core.base" +base.allows_subsystem('http') +local ffi = require 'ffi' local C = ffi.C local ffi_cast = ffi.cast local ffi_str = ffi.string diff --git a/lib/resty/core/uri.lua b/lib/resty/core/uri.lua index af0e65572..8dd09c170 100644 --- a/lib/resty/core/uri.lua +++ b/lib/resty/core/uri.lua @@ -1,13 +1,16 @@ -- Copyright (C) Yichun Zhang (agentzh) +local base = require "resty.core.base" +base.allows_subsystem('http') + + local ffi = require 'ffi' local ffi_string = ffi.string local C = ffi.C local ngx = ngx local type = type local tostring = tostring -local base = require "resty.core.base" local get_string_buf = base.get_string_buf diff --git a/lib/resty/core/var.lua b/lib/resty/core/var.lua index 106c01be8..8d837f03b 100644 --- a/lib/resty/core/var.lua +++ b/lib/resty/core/var.lua @@ -1,9 +1,11 @@ -- Copyright (C) Yichun Zhang (agentzh) -local ffi = require 'ffi' local base = require "resty.core.base" +base.allows_subsystem('http') + +local ffi = require 'ffi' local ffi_new = ffi.new local ffi_str = ffi.string local C = ffi.C diff --git a/lib/resty/core/worker.lua b/lib/resty/core/worker.lua index 0da8086cc..4cb87dfc6 100644 --- a/lib/resty/core/worker.lua +++ b/lib/resty/core/worker.lua @@ -1,10 +1,11 @@ -- Copyright (C) Yichun Zhang (agentzh) -local ffi = require 'ffi' local base = require "resty.core.base" +base.allows_subsystem('http') +local ffi = require 'ffi' local C = ffi.C From a94680359b1907c6438d03471757941455b5cbcc Mon Sep 17 00:00:00 2001 From: spacewander Date: Wed, 24 Oct 2018 17:40:15 +0800 Subject: [PATCH 2/2] add a comment for regex module --- lib/resty/core.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/resty/core.lua b/lib/resty/core.lua index 0192531fa..e52fc5823 100644 --- a/lib/resty/core.lua +++ b/lib/resty/core.lua @@ -3,7 +3,9 @@ local subsystem = ngx.config.subsystem +-- regex module should be loaded first to inject ngx.re for other modules require "resty.core.regex" + require "resty.core.shdict" require "resty.core.time"