Skip to content

TRACE shouldn't default to chunked encoding #25783

@HQidea

Description

@HQidea
  • 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

and here are two references:
aef0960
#2703

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions