Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: response-rewrite plugin can't add only one character #9372

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/plugins/response-rewrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ local schema = {
items = {
type = "string",
-- "Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<number>"
pattern = "^[^:]+:[^:]+[^/]$"
pattern = "^[^:]+:[^:]*[^/]$"
}
},
set = {
Expand Down
37 changes: 37 additions & 0 deletions t/plugin/response-rewrite.t
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,40 @@ passed
--- request
GET /hello
--- response_body



=== TEST 27: test add header with one word
--- 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,
[[{
"plugins": {
"response-rewrite": {
"headers": {
"add": [
"X-Server-test:a"
]
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uris": ["/hello"]
}]]
)

ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to verify whether the header is valid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soulbird Hi, this PR only fixes the issue of not being able to configure a single character and adds test coverage, which header can be verified to have been covered by the previous tests, not what this PR needs to do. 🤔