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

Check form-data content-length value before setting up the header #1956

Merged
merged 2 commits into from Dec 12, 2015

Conversation

jongyoonlee
Copy link
Contributor

When creating a POST request with form data where the contents of the form data comes from http.IncomingMessage stream from another HTTP response, sometimes the length of the request cannot be calculated. One case is when the IncomingMessage is a chunked response. Then the form-data module cannot calculate the length until the stream is fully read, and it returns NaN in getLength() callback. The header Content-Length should not be set in such situation, otherwise the remote server returns with 400.

Ran into this problem a lot while processing the responses from google drive servers as they tend to send chunked response.

@simov
Copy link
Member

simov commented Dec 10, 2015

Good catch! Can you add a test case in tests/test-form-data-error.js?

@jongyoonlee
Copy link
Contributor Author

@simov added a test case there. Without the fix, bad content-length header will cause node http server to drop the connection.

@simov simov changed the title Add the check the value of content-length before setting the header Check form-data content-length value before setting up the header Dec 12, 2015
simov added a commit that referenced this pull request Dec 12, 2015
Check form-data content-length value before setting up the header
@simov simov merged commit 288f814 into request:master Dec 12, 2015
@simov
Copy link
Member

simov commented Dec 12, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants