feat: mock plugin support adding headers#9720
Conversation
|
Documentation changes are pending. |
| response_schema = { type = "object" }, | ||
| with_mock_header = { type = "boolean", default = true } | ||
| with_mock_header = { type = "boolean", default = true }, | ||
| headers = { |
There was a problem hiding this comment.
The name headers and its placement just below with_mock_header can create confusion as to whether these two keys are related.
headerstoresponse_headers?- add comment
-- specify response headers.
| if conf.headers then | ||
| for key, value in pairs(conf.headers) do | ||
| core.log.warn(key, value, "dibag") | ||
| core.response.add_header(key, value) |
There was a problem hiding this comment.
- remove the core.log.warn?
- use
ngx.header[key] = valueinstead? keep the same as line 227
There was a problem hiding this comment.
Using core.response is more efficient.
| core.response.add_header(key, value) | ||
| end | ||
| end | ||
| if conf.delay > 0 then |
| "X-Apisix": "is-cool", | ||
| "X-Really":"yes" |
There was a problem hiding this comment.
What happens if you set 2 identical response headers? Add a test case
There was a problem hiding this comment.
What do you mean by "identical response headers"?
There was a problem hiding this comment.
"response_headers": {
"X-Apisix": "is-cool",
"X-Apisix": "yes"
}
}
There was a problem hiding this comment.
-
Only the last one is retained, the first one is lost. However, if someone needs multiple values for a header they can do
"header-name": "val1, val2". -
Why is this test case needed?
There was a problem hiding this comment.
You could test, I don't think you are right.
There was a problem hiding this comment.
I don't think you are right.
Well, you can give it a try on your local machine 😀
P.S.: I pushed a new commit that would demonstrate the addition of multiple values for a header.
There was a problem hiding this comment.
I said this because you use the function core.response.add_header to add the response header, the function will append the value to the same header name, but i tested locally, and found that the conf.response_headers won't pass the duplicated headers.
If we pass
"response_headers": {
"X-Apisix": "is-cool",
"X-Apisix": "yes"
}
we will get
"response_headers": {
"X-Apisix": "yes"
}
So it's ok for this.
But i don't see you example
|
The doc should be updated |
Description
Fixes #9717
Checklist