diff --git a/lib/types/multipart.js b/lib/types/multipart.js index d33492a..4e3d5d7 100644 --- a/lib/types/multipart.js +++ b/lib/types/multipart.js @@ -121,6 +121,7 @@ function Multipart(boy, cfg) { field.removeAllListeners('end'); } + var additionalHeaders = {}; part.on('header', function(header) { var contype, fieldname, @@ -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) { @@ -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) { @@ -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(); }; @@ -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) {};