-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional multipart headers as an optional parameter #183
base: master
Are you sure you want to change the base?
Changes from 3 commits
fb86698
17e5af4
b4e29f2
e67f154
99d6436
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
for (var h in header) { | ||
if (!isRequiredHeader(h)) additionalHeaders[h] = header[h][0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not be forcing the first value all the time, in case someone is interested in seeing all of the duplicate header values. Maybe at the very least we could just return the first value if |
||
} | ||
|
||
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) {}; | ||
|
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.
I think we should just iterate over
Object.keys(header)
to avoid traversing prototypes and the like.