-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Closed
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.
Description
- Version: all
- Platform: all
- Subsystem: none
example:
// server.js
const http = require('http');
const server = 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);
// client
const http = require('http');
const options = {
hostname: 'localhost',
port: 8000,
path: '/any',
method: 'trace'
};
// Make a request
const req = 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
Metadata
Metadata
Assignees
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.