当有请求 body 时,如何在空手道中集中设置一个 `content-type` 而不会被覆盖为 'application/json'?
How can I centrally set a `content-type` in Karate without it being overwritten to 'application/json' when there's a request body?
我的每个功能文件的背景中都有一个 * configure headers = read('classpath:configure-headers.js')
。
configure-header.js
看起来像:
function() {
var out = {'Some-Header-We-Need': 'value'};
var authToken = karate.get('authToken');
if(authToken) {
out['Authorization'] = 'Bearer ' + authToken;
out['Content-Type'] = 'application/vnd.mycompany+json';
}
return out;
}
这些 header 总是出现在我期望的位置,除了当我制作 PUT
或 PATCH
或 POST
时,Content-Type header 正在设置为 application/json
。我可以通过在通话前设置它来获得我想要的 header,例如
Given path myPath
And header Content-Type = 'application/vnd.mycompany+json'
And request read('classpath:requestBody.json')
When method POST
我该怎么做才能不需要到处重写这个header?
哇,您确实发现了 Karate 中的一个错误,该错误很长一段时间都未被发现。谢谢!
我在这里开了一个问题,修复在开发分支中:https://github.com/intuit/karate/issues/510
希望您可以通过变通办法解决一段时间。如果紧急我们可以发布补丁版本。
我的每个功能文件的背景中都有一个 * configure headers = read('classpath:configure-headers.js')
。
configure-header.js
看起来像:
function() {
var out = {'Some-Header-We-Need': 'value'};
var authToken = karate.get('authToken');
if(authToken) {
out['Authorization'] = 'Bearer ' + authToken;
out['Content-Type'] = 'application/vnd.mycompany+json';
}
return out;
}
这些 header 总是出现在我期望的位置,除了当我制作 PUT
或 PATCH
或 POST
时,Content-Type header 正在设置为 application/json
。我可以通过在通话前设置它来获得我想要的 header,例如
Given path myPath
And header Content-Type = 'application/vnd.mycompany+json'
And request read('classpath:requestBody.json')
When method POST
我该怎么做才能不需要到处重写这个header?
哇,您确实发现了 Karate 中的一个错误,该错误很长一段时间都未被发现。谢谢!
我在这里开了一个问题,修复在开发分支中:https://github.com/intuit/karate/issues/510
希望您可以通过变通办法解决一段时间。如果紧急我们可以发布补丁版本。