Skip to content

Commit

Permalink
fix(http-logger): avoid empty Authorization header by default
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Jul 12, 2022
1 parent 3c94f21 commit ebb2a78
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apisix/plugins/http-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local schema = {
type = "object",
properties = {
uri = core.schema.uri_def,
auth_header = {type = "string", default = ""},
auth_header = {type = "string"},
timeout = {type = "integer", minimum = 1, default = 3},
include_req_body = {type = "boolean", default = false},
include_resp_body = {type = "boolean", default = false},
Expand Down
57 changes: 57 additions & 0 deletions t/plugin/http-logger2.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ add_block_preprocessor(sub {
}
}
location /http-logger/Authorization {
content_by_lua_block {
ngx.log(ngx.WARN, "received Authorization header: [", ngx.var.http_authorization, "]")
ngx.say("OK")
}
}
location /http-logger/center {
content_by_lua_block {
local function str_split(str, reps)
Expand Down Expand Up @@ -253,3 +260,53 @@ test-http-logger-response
request.body:test-http-logger-request
response.body:test-http-logger-response
--- wait: 1.5
=== TEST 8:
--- FIRST
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["POST"],
"plugins": {
"http-logger": {
"uri": "http://127.0.0.1:12001/http-logger/Authorization",
"batch_max_size": 1,
"max_retry_count": 1,
"retry_delay": 2,
"buffer_duration": 2,
"inactive_timeout": 2
}
},
"upstream": {
"nodes": {
"127.0.0.1:12001": 1
},
"type": "roundrobin"
},
"uri": "/http-logger/test"
}]])
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 9: hit
--- request
POST /http-logger/test
test-http-logger-request
--- error_log
received Authorization header: [nil]
--- wait: 1.5

0 comments on commit ebb2a78

Please sign in to comment.