TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "Content-Length"
- Dominant language
- JavaScript
- Stars
- 953
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Description
Hello. When I use unirest to make a request a get an error ' Invalid value "undefined" for header "Content-Length" '. How can I prevent that? It happens from time to time, but not every time. I'm using node.js on backend for my application. Here is my function
```
function addTasks(object) {
return new Promise((resolve, reject) => {
unirest.post(`${xtmBaseUrl}/rest-api/projects`)
.headers({"Authorization": xtmToken,
'Content-Type': 'multipart/form-data'})
.field('customerId', object.customerId)
.field('name', object.name)
.field('sourceLanguage', object.source)
.field('targetLanguages', object.target)
.field('analysisTemplateId', object.templateId)
.field(withJoinObject)
.attach(filesObj)
.end(response => {
if(response.error) {
reject(response.error)
}
resolve(response.body)
})
})
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the addTasks function and trace the unirest.post multipart request built with headers, fields, and attachments. Reproduce the intermittent failure and inspect how the request reaches the Content-Length header; done means the same request no longer produces an undefined header value and the intermittent path is covered or explained.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100