Skip to content

Commit 3fb2ad4

Browse files
author
Ben Buckman
committed
allow append() to completely override header and boundary
1 parent b519203 commit 3fb2ad4

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

lib/form_data.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,35 @@ FormData.prototype._trackLength = function(header, value) {
9191

9292
FormData.prototype._multiPartHeader = function(field, value, options) {
9393
var boundary = this.getBoundary();
94-
var header =
95-
'--' + boundary + FormData.LINE_BREAK +
96-
'Content-Disposition: form-data; name="' + field + '"';
97-
98-
// fs- and request- streams have path property
99-
// TODO: Use request's response mime-type
100-
if (value.path) {
101-
header +=
102-
'; filename="' + path.basename(value.path) + '"' + FormData.LINE_BREAK +
103-
'Content-Type: ' + mime.lookup(value.path);
104-
105-
// http response has not
106-
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
107-
header +=
108-
'; filename="' + path.basename(value.client._httpMessage.path) + '"' + FormData.LINE_BREAK +
109-
'Content-Type: ' + value.headers['content-type'];
94+
var header = '';
95+
96+
// custom header specified (as string)?
97+
// it becomes responsible for boundary
98+
// (e.g. to handle extra CRLFs on .NET servers)
99+
if (options.header != null) {
100+
header = options.header;
101+
}
102+
else {
103+
header += '--' + boundary + FormData.LINE_BREAK +
104+
'Content-Disposition: form-data; name="' + field + '"';
105+
106+
// fs- and request- streams have path property
107+
// TODO: Use request's response mime-type
108+
if (value.path) {
109+
header +=
110+
'; filename="' + path.basename(value.path) + '"' + FormData.LINE_BREAK +
111+
'Content-Type: ' + mime.lookup(value.path);
112+
113+
// http response has not
114+
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
115+
header +=
116+
'; filename="' + path.basename(value.client._httpMessage.path) + '"' + FormData.LINE_BREAK +
117+
'Content-Type: ' + value.headers['content-type'];
118+
}
119+
120+
header += FormData.LINE_BREAK + FormData.LINE_BREAK;
110121
}
111122

112-
header += FormData.LINE_BREAK + FormData.LINE_BREAK;
113123
return header;
114124
};
115125

0 commit comments

Comments
 (0)