Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function Multipart(boy, cfg) {
field.removeAllListeners('end');
}

var additionalHeaders = {};
part.on('header', function(header) {
var contype,
fieldname,
Expand Down Expand Up @@ -169,6 +170,10 @@ function Multipart(boy, cfg) {
else
encoding = '7bit';

Object.keys(header).forEach(function(k) {
if (!isRequiredHeader(k)) additionalHeaders[k] = header[k];
});

var onData,
onEnd;
if (contype === 'application/octet-stream' || filename !== undefined) {
Expand Down Expand Up @@ -210,7 +215,8 @@ function Multipart(boy, cfg) {
cb();
}
};
boy.emit('file', fieldname, file, filename, encoding, contype);

boy.emit('file', fieldname, file, filename, encoding, contype, additionalHeaders);

onData = function(data) {
if ((nsize += data.length) > fileSizeLimit) {
Expand Down Expand Up @@ -258,7 +264,8 @@ function Multipart(boy, cfg) {
curField = undefined;
if (buffer.length)
buffer = decodeText(buffer, 'binary', charset);
boy.emit('field', fieldname, buffer, false, truncated, encoding, contype);

boy.emit('field', fieldname, buffer, false, truncated, encoding, contype, additionalHeaders);
--nends;
checkFinished();
};
Expand Down Expand Up @@ -317,6 +324,13 @@ function FileStream(opts) {

this.truncated = false;
}

function isRequiredHeader(h) {
return h === 'content-type'
|| h === 'content-disposition'
|| h === 'content-transfer-encoding';
}

inherits(FileStream, ReadableStream);

FileStream.prototype._read = function(n) {};
Expand Down