You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// server.jsconsthttp=require('http');constserver=http.createServer((req,res)=>{res.setHeader('x-req-headers',JSON.stringify(req.headers));res.end();});server.on('clientError',(err,socket)=>{socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');});server.listen(8000);
// clientconsthttp=require('http');constoptions={hostname: 'localhost',port: 8000,path: '/any',method: 'trace'};// Make a requestconstreq=http.request(options);req.end();req.on('response',(res)=>{console.log(res.headers);});
// result
'x-req-headers': '{"host":"localhost:8000","connection":"close","content-length":"0"}'
As you can see, I haven't added a content-length header, but node itself adds it for me.
A user agent SHOULD NOT send a
Content-Length header field when the request message does not contain
a payload body and the method semantics do not anticipate such a
body.
After doing some digging, I recommend changing the value of useChunkedEncodingByDefault for TRACE.
example:
As you can see, I haven't added a
content-length
header, but node itself adds it for me.According to rfc7231:
and rfc7230:
After doing some digging, I recommend changing the value of
useChunkedEncodingByDefault
for TRACE.https://github.com/nodejs/node/blob/master/lib/_http_client.js#L165-L173
and here are two references:
aef0960
#2703
The text was updated successfully, but these errors were encountered: