Skip to content
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

TRACE shouldn't default to chunked encoding #25783

Closed
HQidea opened this issue Jan 29, 2019 · 0 comments
Closed

TRACE shouldn't default to chunked encoding #25783

HQidea opened this issue Jan 29, 2019 · 0 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@HQidea
Copy link

HQidea commented Jan 29, 2019

  • 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

@bnoordhuis bnoordhuis added the http Issues or PRs related to the http subsystem. label Jan 29, 2019
lpinca added a commit to lpinca/node that referenced this issue May 13, 2019
targos pushed a commit that referenced this issue May 20, 2019
Fixes: #25783

PR-URL: #27673
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants