Allow custom headers and pre-known length in parts#17
Allow custom headers and pre-known length in parts#17alexindigo merged 6 commits intomasterfrom unknown repository
Conversation
|
A note on the Thanks |
There was a problem hiding this comment.
RE: header key/value option
Maybe something like this ...
``` javascript`
...
if (typeof(options.header) === 'object') {
for (key in options.header) {
header += key + ': ' options.header[key] + '\r\n'
}
} else if (typeof(options.header) === 'string') {
header = options.header
} else {
...
There was a problem hiding this comment.
@alexindigo Was this comment answered somewhere ? I'm currently in the middle of this nightmare.
There was a problem hiding this comment.
@Marsup too bad to hear FormData is failing you. Can you describe your situation? Maybe together we can figure out something.
There was a problem hiding this comment.
@alexindigo I need to add custom headers to each part I append, this snippet of code would make this possible it seems.
There was a problem hiding this comment.
This snippet only saves you one loop and if you came all the way to generate your own boundaries and pretty much to reimplement logic of the whole function, you can pass your custom headers as string with no greater complexity. Right? Or did I miss something?
There was a problem hiding this comment.
I want to add a file, so let form-data do its work on boundary, filename, mime etc... But I also want to add a few headers. Maybe this snippet is not perfect but the 1st "if" would probably solve this if put after (currently line 162).
There was a problem hiding this comment.
I mean, can you provide your code for better understanding, why this example doesn't work for you.
var FormData = require('form-data');
var form = new FormData();
var options = {
header: FormData.LINE_BREAK + '--' + form.getBoundary() + FormData.LINE_BREAK + 'X-Custom-Header: 123' + FormData.LINE_BREAK + FormData.LINE_BREAK
};
form.append('my_thing', theThing, options);There was a problem hiding this comment.
I'd have to recreate the whole Content-Disposition, Content-Type, name, filename, for that I'd have to add mime as direct dependency and basically copy most of _multiPartHeader, this doesn't make sense.
Isn't this much clearer this way ?
var FormData = require('form-data');
var form = new FormData();
var options = {
header: {
'X-Custom-Header': 123
}
};
form.append('my_thing', theThing, options);There was a problem hiding this comment.
Yes, you're right. This is legit issue. Let me see what I can do. Idea was to freeze new features while packing everything for 1.0 release. I'll get back to you soon.
…async size calculation
|
The additional commit (e2ac039) is for the same use case: We already know the file size of an inbound transfer, and want to stream it directly outbound to a server that requires a Content-Length, with minimal latency. Currently we have to download the file to disk to get the size, or wait for the inbound stream to end to gets its content-length, which both introduce the latency again. This change allows (Also fixed a minor typo.) Thank you. |
|
Hi Ben, Can you add a test to show off the issue you're solving? Thank you. |
|
Will do. |
|
Following up on this, is there anything else I should add to this pull request for it to be accepted? |
|
Hey, sorry, got carried away. Let me take a look and I'd get back to you shortly. |
Allow custom headers and pre-known length in parts
|
Thank you for the PR, and again terrible sorry for all the delays. :) |
|
Published new version to npm. |
|
Thanks! |
We're using this module (inside request) to stream files from 3rd-party file storage services straight through (as multipart POSTs) to our REST API. Our API expects special headers on each part, but the module currently doesn't support that. This change allows an
options.headerparameter to override the header string passed to each part (including the boundary and CRLFs - the latter being particularly important, similar to Request PR #272).Thank you!
(More additions below)