Permalink
Browse files

allow append() to completely override header and boundary

  • Loading branch information...
1 parent b519203 commit 3fb2ad491f66e4b4ff16130be25b462820b8c972 Ben Buckman committed Oct 23, 2012
Showing with 27 additions and 17 deletions.
  1. +27 −17 lib/form_data.js
View
44 lib/form_data.js
@@ -91,25 +91,35 @@ FormData.prototype._trackLength = function(header, value) {
FormData.prototype._multiPartHeader = function(field, value, options) {
var boundary = this.getBoundary();
- var header =
- '--' + boundary + FormData.LINE_BREAK +
- 'Content-Disposition: form-data; name="' + field + '"';
-
- // fs- and request- streams have path property
- // TODO: Use request's response mime-type
- if (value.path) {
- header +=
- '; filename="' + path.basename(value.path) + '"' + FormData.LINE_BREAK +
- 'Content-Type: ' + mime.lookup(value.path);
-
- // http response has not
- } else if (value.readable && value.hasOwnProperty('httpVersion')) {
- header +=
- '; filename="' + path.basename(value.client._httpMessage.path) + '"' + FormData.LINE_BREAK +
- 'Content-Type: ' + value.headers['content-type'];
+ var header = '';
+
+ // custom header specified (as string)?
+ // it becomes responsible for boundary
+ // (e.g. to handle extra CRLFs on .NET servers)
+ if (options.header != null) {
+ header = options.header;
+ }
+ else {
+ header += '--' + boundary + FormData.LINE_BREAK +
+ 'Content-Disposition: form-data; name="' + field + '"';
+
+ // fs- and request- streams have path property
+ // TODO: Use request's response mime-type
+ if (value.path) {
+ header +=
+ '; filename="' + path.basename(value.path) + '"' + FormData.LINE_BREAK +
+ 'Content-Type: ' + mime.lookup(value.path);
+
+ // http response has not
+ } else if (value.readable && value.hasOwnProperty('httpVersion')) {
+ header +=
+ '; filename="' + path.basename(value.client._httpMessage.path) + '"' + FormData.LINE_BREAK +
+ 'Content-Type: ' + value.headers['content-type'];
+ }
+
+ header += FormData.LINE_BREAK + FormData.LINE_BREAK;
}
- header += FormData.LINE_BREAK + FormData.LINE_BREAK;
return header;
};

0 comments on commit 3fb2ad4

Please sign in to comment.