-
Notifications
You must be signed in to change notification settings - Fork 280
Modify multipart body and calculate Content-Length in the right order #841
Conversation
src/transaction-runner.coffee
Outdated
isMultipart: (headers) -> | ||
contentType = caseless(headers).get('Content-Type') | ||
return false unless contentType | ||
return contentType.indexOf('multipart') > -1 |
There was a problem hiding this comment.
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 return
s into one - return false if not contentType else contentType.indexOf('multipart') > -1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 3055aba
There was a problem hiding this comment.
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 🙂
There was a problem hiding this comment.
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
😏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in a4da5dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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 👍
1ee4f0d
to
3055aba
Compare
3055aba
to
a4da5dd
Compare
Got verbal approval from @michalholasek of the coverage drop explanation, merging. |
🚀 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 theContent-Length
header accordingly. This wasn't updated with introduction of therequest
library. That resulted in theContent-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?
npm run lint