-
Notifications
You must be signed in to change notification settings - Fork 148
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
ngx.fetch Content-Length header is not sent #693
Comments
Hi @Masterwow3, I cannot reproduce the problem so far, I am using the following config and js code
async function fetch(r) {
let reply = await ngx.fetch("http://127.0.0.1:8001/",
{ headers: { 'x-ms': "a", 'foo': 'xxx' } })
let body = await reply.text();
r.return(200, body);
}
function reply(r) {
let body = [njs.version, '\n'];
r.rawHeadersIn.forEach((header) => {
body.push(`${header[0]}: ${header[1]}\n`);
});
r.return(200, body.join(''));
}
export default { fetch, reply }; To run the nginx:
I tried njs versions from 0.7.10 to 0.7.12 and the latest one 0.8.2. Which njs version are you using? |
Hi @xeioex, But there is still a problem. The header Log output: async function send(r) {
await ngx.fetch("http://10.3.2.52:8082/", {
headers: {
"Content-Length": "0",
"x-ms": "123"
}
});
r.return(200);
}
async function log(r) {
r.log(JSON.stringify(r.rawHeadersIn));
r.return(200);
}
export default { send, log } server {
listen 8081;
js_import njs/test.js;
location / {
js_content test.send;
}
}
server {
listen 8082;
js_import njs/test.js;
location / {
js_content test.log;
}
} |
Hi @Masterwow3, "Content-Length" and a handful of other headers are treated in a special way by nginx. For example, with "Content-Length", the value is put to |
Hi @xeioex,
await ngx.fetch("http://10.3.2.52:8082/", {
headers: {
"Content-Length": "0",
"x-ms": "123"
}
}); Does that mean I can't send this header via njs? |
Hi @Masterwow3, There are no special treatment of
Can you confirm the njs version? Just output njs.version in JS code. |
Hi @xeioex,
Okay too bad, is it planned to support the header |
Hi @Masterwow3, There WAS a special treatment for Content-Length and other headers in accordance with Fetch API (between 0.7.10 and 0.7.12). But this was reverted back since 0.8.0. The latest released version is 0.8.2. Feel free to upgrade to nginx 1.25.3 and njs 0.8.2. |
nginx/1.25.3 Thank you, it works. |
With the current Nginx version nginx/1.24.0 there are no headers on the server that contain a minus sign in the key.
Example, works. The header x arrives at the server:
await ngx.fetch("https://yxy/asd", { verify: false, headers: { 'x': "a" } });
Example, header
x-ms
does not arrive at the server:await ngx.fetch("https://yxy/asd", { verify: false, headers: { 'x-ms': "a" } });
The text was updated successfully, but these errors were encountered: