diff --git a/kong/pdk/response.lua b/kong/pdk/response.lua index 33564b16eab4..bb6bee29fc6b 100644 --- a/kong/pdk/response.lua +++ b/kong/pdk/response.lua @@ -245,7 +245,6 @@ local function new(self, major_version) end local header_value = ngx.header[name] - -- local header_value = _RESPONSE.get_headers()[name] if type(header_value) == "table" then return header_value[1] end diff --git a/kong/pdk/service/request.lua b/kong/pdk/service/request.lua index 2ee665c5462e..9c01c237bc15 100644 --- a/kong/pdk/service/request.lua +++ b/kong/pdk/service/request.lua @@ -653,7 +653,6 @@ local function new(self) error("mime must be a string", 2) end if not mime then - -- mime = ngx.req.get_headers()[CONTENT_TYPE] mime = ngx_var.http_content_type if not mime then return nil, "content type was neither explicitly given " .. diff --git a/kong/plugins/aws-lambda/request-util.lua b/kong/plugins/aws-lambda/request-util.lua index 053299efff24..fe59f786c983 100644 --- a/kong/plugins/aws-lambda/request-util.lua +++ b/kong/plugins/aws-lambda/request-util.lua @@ -294,7 +294,6 @@ local function build_request_payload(conf) end if conf.forward_request_body then - -- local content_type = kong.request.get_header("content-type") local content_type = ngx.var.http_content_type local body_raw = read_request_body(conf.skip_large_bodies) local body_args, err = kong.request.get_body() diff --git a/kong/plugins/bchen-hello/handler.lua b/kong/plugins/bchen-hello/handler.lua new file mode 100644 index 000000000000..96ac24892a94 --- /dev/null +++ b/kong/plugins/bchen-hello/handler.lua @@ -0,0 +1,54 @@ +-- This software is copyright Kong Inc. and its licensors. +-- Use of the software is subject to the agreement between your organization +-- and Kong Inc. If there is no such agreement, use is governed by and +-- subject to the terms of the Kong Master Software License Agreement found +-- at https://konghq.com/enterprisesoftwarelicense/. +-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] +local get_header = require("kong.tools.http").get_header + +local MyPluginHandler = { + PRIORITY = 1000, + VERSION = "0.0.1", +} + +function MyPluginHandler:access() + -- ngx.ctx.get_headers_patch = 0 + local start = os.clock() + for i=1,10 do + local headers = ngx.req.get_headers() + -- ngx.req.set_header("foo", tostring(i)) + -- ngx.log(ngx.WARN, "bchen access", ngx.req.get_headers()["Content-Type"]) + -- local v = headers["Content-Type"] + end + local elapsed = (os.clock() - start) + + ngx.log(ngx.WARN, "bchen access", string.format(" elapsed time: %.10f, %d\n", elapsed, 1)) + + -- ngx.request.set_header("foo", "bar") +end + +function MyPluginHandler:response(conf) + + -- local content_type = kong.response.get_header("Content-Type") + kong.response.set_header("X-BChen-Plugin", "response") + local headers = kong.response.get_headers() + local headers2 = kong.service.response.get_headers() + local fmt = string.format + local string_tools = require "kong.tools.string" + local replace_dashes_lower = string_tools.replace_dashes_lower +-- ngx.log(ngx.WARN, "single: ", "multi-foo-r".." : "..tostring(kong.response.get_header("multi-foo-r"))) + +-- for k, v in pairs(headers) do +-- ngx.log(ngx.WARN, "resp header: ", k.." : "..tostring(v)) +-- local var = fmt("upstream_http_%s", replace_dashes_lower(k)) +-- if ngx.var[var] then +-- ngx.log(ngx.WARN, "upstream header: ", k) +-- end +-- end +-- for k, v in pairs(headers2) do +-- ngx.log(ngx.WARN, "service header: ", k.." : "..tostring(v)) +-- end +end + + +return MyPluginHandler diff --git a/kong/plugins/bchen-hello/schema.lua b/kong/plugins/bchen-hello/schema.lua new file mode 100644 index 000000000000..7e5451efc722 --- /dev/null +++ b/kong/plugins/bchen-hello/schema.lua @@ -0,0 +1,22 @@ +-- This software is copyright Kong Inc. and its licensors. +-- Use of the software is subject to the agreement between your organization +-- and Kong Inc. If there is no such agreement, use is governed by and +-- subject to the terms of the Kong Master Software License Agreement found +-- at https://konghq.com/enterprisesoftwarelicense/. +-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] + +local PLUGIN_NAME = "bchen-hello" + +local schema = { + name = PLUGIN_NAME, + fields = { + { config = { + type = "record", + fields = { + }, + }, + }, + }, +} + +return schema diff --git a/kong/plugins/grpc-web/handler.lua b/kong/plugins/grpc-web/handler.lua index ce6ec660a414..437f92f119a0 100644 --- a/kong/plugins/grpc-web/handler.lua +++ b/kong/plugins/grpc-web/handler.lua @@ -12,7 +12,6 @@ local ngx_arg = ngx.arg local ngx_var = ngx.var local kong_request_get_path = kong.request.get_path --- local kong_request_get_header = kong.request.get_header local kong_request_get_method = kong.request.get_method local kong_request_get_raw_body = kong.request.get_raw_body local kong_response_exit = kong.response.exit @@ -51,7 +50,6 @@ function grpc_web:access(conf) end local dec, err = deco.new( - -- kong_request_get_header("Content-Type"), ngx.var.http_content_type, uri, conf.proto) diff --git a/kong/plugins/hmac-auth/access.lua b/kong/plugins/hmac-auth/access.lua index e8acb4381d52..cd4acaedbbc7 100644 --- a/kong/plugins/hmac-auth/access.lua +++ b/kong/plugins/hmac-auth/access.lua @@ -127,11 +127,12 @@ end -- plugin assumes the request parameters being used for creating -- signature by client are not changed by core or any other plugin -local function create_hash(request_uri, hmac_params, ctx) +local function create_hash(request_uri, hmac_params) local signing_string = "" local hmac_headers = hmac_params.hmac_headers local count = #hmac_headers + local ctx = {} for i = 1, count do local header = hmac_headers[i] local header_value = kong.request.get_header(header, ctx) @@ -166,8 +167,8 @@ local function create_hash(request_uri, hmac_params, ctx) end -local function validate_signature(hmac_params, ctx) - local signature_1 = create_hash(kong_request.get_path_with_query(), hmac_params, ctx) +local function validate_signature(hmac_params) + local signature_1 = create_hash(kong_request.get_path_with_query(), hmac_params) local signature_2 = decode_base64(hmac_params.signature) return signature_1 == signature_2 end @@ -330,9 +331,7 @@ local function do_authentication(conf) hmac_params.secret = credential.secret - -- since there are `clear_header` call before, we reset ctx, to get fresh headers - ctx = {} - if not validate_signature(hmac_params, ctx) then + if not validate_signature(hmac_params) then return false, unauthorized(SIGNATURE_NOT_SAME, www_auth_content) end diff --git a/kong/plugins/oauth2/access.lua b/kong/plugins/oauth2/access.lua index 8d2565a7a401..8b1dcb5ea95e 100644 --- a/kong/plugins/oauth2/access.lua +++ b/kong/plugins/oauth2/access.lua @@ -877,7 +877,6 @@ local function parse_access_token(conf) parameters[ACCESS_TOKEN] = nil kong.service.request.set_query(parameters) - -- local content_type = kong.request.get_header("content-type") local content_type = ngx.var.http_content_type local is_form_post = content_type and string_find(content_type, "application/x-www-form-urlencoded", 1, true) diff --git a/kong/plugins/request-transformer/access.lua b/kong/plugins/request-transformer/access.lua index 80006542e2da..dc47278ae1ea 100644 --- a/kong/plugins/request-transformer/access.lua +++ b/kong/plugins/request-transformer/access.lua @@ -8,7 +8,6 @@ local table_insert = table.insert local get_uri_args = kong.request.get_query local set_uri_args = kong.service.request.set_query local clear_header = kong.service.request.clear_header --- local get_header = kong.request.get_header local var = ngx.var local set_header = kong.service.request.set_header local get_headers = kong.request.get_headers @@ -423,7 +422,6 @@ local function transform_multipart_body(conf, body, content_length, content_type end local function transform_body(conf, template_env) - -- local content_type_value = get_header(CONTENT_TYPE) -- content-type is a builtin single value header, use var to fetch is faster. local content_type_value = var.http_content_type local content_type = get_content_type(content_type_value) @@ -459,7 +457,6 @@ local function transform_method(conf) if conf.http_method then set_method(conf.http_method:upper()) if conf.http_method == "GET" or conf.http_method == "HEAD" or conf.http_method == "TRACE" then - -- local content_type_value = get_header(CONTENT_TYPE) -- content-type is a builtin single value header, use var to fetch is faster. local content_type_value = var.http_content_type local content_type = get_content_type(content_type_value) diff --git a/t/01-pdk/08-response/02-get_header.t b/t/01-pdk/08-response/02-get_header.t index 378e1f9cdbef..c6bec909981a 100644 --- a/t/01-pdk/08-response/02-get_header.t +++ b/t/01-pdk/08-response/02-get_header.t @@ -116,7 +116,7 @@ X-Missing: nil -=== TEST 4: response.get_header() returns existing header will not by limited by get_headers() default max_headers configuration +=== TEST 4: response.get_header() returns existing header will not limited by get_headers() default max_headers configuration --- http_config eval: $t::Util::HttpConfig --- config location = /t {