Skip to content

content-length request header is removed when parseReqBody is false #545

Open
@mdmower-csnw

Description

@mdmower-csnw

Problem
When option {parseReqBody: false} is used, the original request content-length header is lost when the request is forwarded to the target origin.

Analysis
It looks like the header is removed here:

function reqHeaders(req, options) {
var headers = options.headers || {};
var skipHdrs = [ 'connection', 'content-length' ];
if (!options.preserveHostHdr) {
skipHdrs.push('host');
}
var hds = extend(headers, req.headers, skipHdrs);
hds.connection = 'close';
return hds;
}

But then is only recalculated when parseReqBody is true, here:

proxyReq.setHeader('Content-Length', Buffer.byteLength(body));

Potential solution
When {parseReqBody: false}...

  1. If bodyContent is provided, then content-length could be determined from the size of bodyContent
  2. If bodyContent is not provided (i.e. proxyReq is piped), then the original content-length header could be restored (if defined)

Supposing number item 1 is handled (content-length determined from size of bodyContent), then it may not be necessary to remove content-length from the original request at all. It would be overwritten in sendProxyRequest when appropriate and left alone otherwise.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions