我在函数中使用AJAX调用以这种方式从服务器检索一些数据:
getPolicies: function() {
$.ajax({
async: false, // wait for response
type: "GET",
url: "http://localhost:8080/getPolicies",
contentType: "application/json",
dataType: "json",
success: function(jsonList) {
for(var i in jsonList) {
console.dir(jsonList[i].policyName);
}
return jsonList;
},
failure: function(err) {console.log("Error");}
});
}
Run Code Online (Sandbox Code Playgroud)
我正确地得到了JSON数组:
[
{
"policyName": "policy1"
},
{
"policyName": "policy2"
},
{
"policyName": "policy3"
}
]
Run Code Online (Sandbox Code Playgroud)
该函数返回此JSON数组.但是当我调用函数getPolicies()时,我只得到一个空的JSON对象{}.具体来说,如果我尝试
var policies = getPolicies();
console.log(policies[1].policyName);
Run Code Online (Sandbox Code Playgroud)
我明白了:
Uncaught TypeError: Cannot read property 'policyName' of undefined
Run Code Online (Sandbox Code Playgroud)
那么,即使我正确获取JSON数组,该函数又有可能返回一个空对象吗?!谢谢...
我在 Kubernetes 集群上安装了 Kong,使用 kubernetes-ingress-controller 功能(https://github.com/Kong/kubernetes-ingress-controller)。
我想删除以下 Kong 的相关标题:
我通过应用以下 KongPlugin 资源尝试使用响应转换器插件:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: kong-response-transformer
config:
remove:
headers:
- "X-Kong-Upstream-Latency"
- "X-Kong-Proxy-Latency"
- "Via"
- "Server"
plugin: response-transformer
Run Code Online (Sandbox Code Playgroud)
但只有“服务器”标头从响应中删除。有没有办法通过使用一些自定义资源以“kubernetes-ingress-controller”方式从响应中删除此类标头?
我发现了几个与此问题相关的 GitHub 问题(1、2),但所有这些问题都涉及更新 Kong 配置文件(/etc/kong/kong.yml)的可能性,老实说,我不知道如何应用此类更改在我的 Kubernetes 环境中。将以下行传递到 ConfigMap 并不能解决问题:
# Add additional response headers
header_filter_by_lua_block {
kong.header_filter()
ngx.header["Server"] = nil
ngx.header["Via"] = nil
ngx.header["X-Kong-Proxy-Latency"] = nil
ngx.header["X-Kong-Upstream-Latency"] = nil
}
Run Code Online (Sandbox Code Playgroud)
这有什么帮助吗?谢谢...
编辑:Kong 版本是 2.0.3,kong-ingress-controller 版本是 0.8.1。