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

Modify multipart body and calculate Content-Length in the right order #841

Merged
merged 4 commits into from
Aug 8, 2017

Conversation

honzajavorek
Copy link
Contributor

πŸš€ Why this change?

Current implementation of multipart request bodies is broken. See #786.

In #734 Dredd's custom implementation of HTTP requesting was replaced with the request library. There is some special handling of multipart requests, solving apiaryio/api-blueprint#401, which modifies the body payload and also modifies the Content-Length header accordingly. This wasn't updated with introduction of the request library. That resulted in the Content-Length being sent with incorrect number, causing the server under test to hang, waiting for more bytes.

My changes makes the code dealing with apiaryio/api-blueprint#401 a lot simpler and more functional (no side effects). It removes any modifications to Content-Length and instead it changes the order in which the body gets modified and the header gets calculated.

πŸ“ Related issues and Pull Request

Fixes #786.

βœ… What didn't I forget?

  • To write docs - N/A
  • To write tests
  • To put Conventional Changelog prefixes in front of all my commits and run npm run lint

isMultipart: (headers) ->
contentType = caseless(headers).get('Content-Type')
return false unless contentType
return contentType.indexOf('multipart') > -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can join these two returns into one - return false if not contentType else contentType.indexOf('multipart') > -1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3055aba

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I think that change made in 3055aba is worse than the original two returns. I think that solution from above reads a little bit better, yours has a little bit of Yoda tongue in it πŸ™‚

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I though that was typo of yours, I did not know that's valid CoffeeScript πŸ˜„

return false if not contentType else contentType.indexOf('multipart') > -1

won't compile. I'll change it to normal if/else 😏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a4da5dd

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

Copy link
Contributor

@michalholasek michalholasek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nitpick, otherwise I think it is good to go πŸ‘

@honzajavorek
Copy link
Contributor Author

The drop in coverage is caused by "statistics". There's less lines in the transaction runner now, which means the uncovered part takes larger percentage of it. The drop is thus caused by Dredd consisting of less lines in overall, not by adding uncovered code:

image

@honzajavorek
Copy link
Contributor Author

Got verbal approval from @michalholasek of the coverage drop explanation, merging.

@honzajavorek honzajavorek merged commit acecae5 into master Aug 8, 2017
@honzajavorek honzajavorek deleted the honzajavorek/multipart-fix branch August 8, 2017 14:12
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.

Multipart not passing formdata to endpoint
2 participants