-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Description
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:
express-http-proxy/lib/requestOptions.js
Lines 52 to 65 in b05cb04
| 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}...
- If
bodyContentis provided, thencontent-lengthcould be determined from the size ofbodyContent - If
bodyContentis not provided (i.e.proxyReqis piped), then the originalcontent-lengthheader 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