For Buffers, set the content type to application/octet-stream by default.#54
For Buffers, set the content type to application/octet-stream by default.#54UndeadKernel wants to merge 2 commits intoform-data:masterfrom
Conversation
…ation/octet-stream by default.
|
It would be nice to have a test to test new functionality. |
|
The patch removes the ability to set a custom content type for buffers, which is an unacceptable regression. Please add a test / make sure that custom options will always be honored. (you're already doing this for filename correctly) |
|
Ay Ay Captain! |
😄 - thank you so much for spending time on making this library better! |
A new unit test was created to verify that Buffers are being sent correctly and all custom options are taken into account.
|
Are there any other things left to make this pull? |
|
At first glance looks exactly what we need, I'll play with it tonight. |
|
Interesting your test is not failing if I run it against old codebase. :) |
|
This one This is how request body looks like: And it's been parsed by Do you mind to share your setup and what exactly doesn't work? |
|
Btw, what is your environment on receiving end? |
|
My receiving environment is basically plain express. I opened this pull request because I noticed that when I wanted to transfer a binary file that I had previously fetched into a buffer to express the data sent would not be the same in the receiving end. I then noticed that if you where sending an arbitrary "buffer" without a filename, the content ype was chosen to be "plan/text" by default. |
|
I see, maybe it's Formidable being smart enough. Oh, and in Express, can you set default encoding to |
|
I'm not sure I completely understand what you mean with "set the default encoding..." in express. |
|
Hey, I just wanted to follow up on this. |
|
I thought you're going to update the test to make it fail without your changes, otherwise it's not really a test, or it's working and no need to change anything. :) |
|
I see, I misunderstood your second to last message. |
|
Sorry for not being clear and let me know if you need a hand with something. |
|
Ok, we will incorporate this feature into |
|
That's good to know. Let me know if other things need to be done to this pull request. |
There was a problem hiding this comment.
Do we really need to have this header?
There was a problem hiding this comment.
I believe it is required according to the documentation here:
http://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html
On Tue, Jun 24, 2014 at 6:41 PM, Alex Indigo [email protected]
wrote:
In lib/form_data.js:
- if (Buffer.isBuffer(value)) {
// let the user provide a filename for the buffer.if(options.filename) {header += '; filename="' + options.filename + '"';}
header += FormData.LINE_BREAK;// let the user set a custom content-typeif (options.contentType) {header += 'Content-Type: ' + options.contentType;} else {header += 'Content-Type: application/octet-stream';}
// if a buffer is being sent then set the encoding as binary.header += FormData.LINE_BREAK + 'Content-Transfer-Encoding: binary';Do we really need to have this header?
—
Reply to this email directly or view it on GitHub
https://github.com/felixge/node-form-data/pull/54/files#r14139683.
There was a problem hiding this comment.
Quote: "As of the publication of this document, there are no standardized Internet transports for which it is legitimate to include unencoded 8-bit or binary data in mail bodies. Thus there are no circumstances in which the "8bit" or "binary" Content-Transfer-Encoding is actually legal on the Internet. However, in the event that 8-bit or binary mail transport becomes a reality in Internet mail, or when this document is used in conjunction with any other 8-bit or binary-capable transport mechanism, 8-bit or binary bodies should be labeled as such using this mechanism."
And it seems like they very concerned about mail transport in the future, I don't want to sound Bill Gates here, but I don't see using [email protected] to send emails.
And my main concern, that if it does make the difference (not yet so far) it will introduce different behavior when you send binary files and binary buffers, which is totally unexpected from user's point of view.
There was a problem hiding this comment.
With this that you show me, I agree that the header is not needed.
|
@UndeadKernel I still can't make your test fail without your modifications to form_data.js, means it doesn't really test the problem. Can you refactor it? Thank you. |
|
I'm using tabs instead of spaces!? Silly me :p Last time I checked the tests were not failing because I was using On Tue, Jun 24, 2014 at 6:49 PM, Alex Indigo [email protected]
|
|
It's what we're using for tests, maybe in your test you don't need to rely on Formidable but rather get naked request and check the difference "manually". Otherwise there is no point to have the test if it doesn't really test stuff, right? :) |
There was a problem hiding this comment.
Here should be change to options.contentType || mime.lookup(options.filename || value.path) || 'application/octet-stream'.
mime.lookup will return false when lookup failed, then data will be 'Content-Type: false'
|
I have a problem with superagent, cause by "Content-Type: false" |
When buffers are attached to a form they were added with no content type; therefore, the content type would default to 'text/plan'. This modification changes this behaviour to default to 'application/octet-stream' for buffers.
The user is also able to add a 'filename' optional field to the header in case a file is being sent in binary form.