- Version: all
- Platform: all
- Subsystem: none
example:
// 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.
According to rfc7231:
A client MUST NOT send a message body in a TRACE request.
and rfc7230:
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.
https://github.com/nodejs/node/blob/master/lib/_http_client.js#L165-L173
and here are two references:
aef0960
#2703
example:
As you can see, I haven't added a
content-lengthheader, but node itself adds it for me.According to rfc7231:
and rfc7230:
After doing some digging, I recommend changing the value of
useChunkedEncodingByDefaultfor TRACE.https://github.com/nodejs/node/blob/master/lib/_http_client.js#L165-L173
and here are two references:
aef0960
#2703