Skip to content

Commit 8cb9709

Browse files
committed
Allow custom content-type without setting a filename
1 parent c8a77cc commit 8cb9709

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

lib/form_data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
167167
'filename="' + path.basename(value.client._httpMessage.path) + '"'
168168
);
169169
headers['Content-Type'].push(
170+
options.contentType ||
170171
value.headers['content-type'] ||
171172
FormData.DEFAULT_CONTENT_TYPE
172173
);

test/integration/test-custom-content-type.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ var FIELDS = {
1414
},
1515
'custom_type': {
1616
value: 'my_value',
17-
type: 'image/png',
17+
expectedType: 'image/png',
1818
options: {
1919
contentType: 'image/png'
2020
}
2121
},
2222
'default_type': {
23-
type: FormData.DEFAULT_CONTENT_TYPE,
23+
expectedType: FormData.DEFAULT_CONTENT_TYPE,
2424
value: function(){ return new Buffer([1, 2, 3]); }
2525
},
2626
'implicit_type': {
27-
type: mime.lookup(common.dir.fixture + '/unicycle.jpg'),
27+
expectedType: mime.lookup(common.dir.fixture + '/unicycle.jpg'),
2828
value: function(){ return fs.createReadStream(common.dir.fixture + '/unicycle.jpg'); }
2929
}
3030
};
31+
var fieldsPassed = false;
3132

3233
var server = http.createServer(function(req, res) {
3334
var body = '';
@@ -44,15 +45,17 @@ var server = http.createServer(function(req, res) {
4445
assert.ok(fields[0].indexOf('Content-Type"') === -1);
4546

4647
assert.ok(fields[1].indexOf('name="custom_type"') > -1);
47-
assert.ok(fields[1].indexOf('Content-Type: ' + FIELDS.custom_type.type) > -1);
48+
assert.ok(fields[1].indexOf('Content-Type: ' + FIELDS.custom_type.expectedType) > -1);
4849

4950
assert.ok(fields[2].indexOf('name="default_type"') > -1);
50-
assert.ok(fields[2].indexOf('Content-Type: ' + FIELDS.default_type.type) > -1);
51+
assert.ok(fields[2].indexOf('Content-Type: ' + FIELDS.default_type.expectedType) > -1);
5152

5253
assert.ok(fields[3].indexOf('name="implicit_type"') > -1);
53-
assert.ok(fields[3].indexOf('Content-Type: ' + FIELDS.implicit_type.type) > -1);
54+
assert.ok(fields[3].indexOf('Content-Type: ' + FIELDS.implicit_type.expectedType) > -1);
55+
56+
fieldsPassed = true;
57+
res.end();
5458
});
55-
res.end();
5659

5760
});
5861

@@ -88,4 +91,8 @@ server.listen(common.port, function() {
8891
server.close();
8992
});
9093

94+
});
95+
96+
process.on('exit', function() {
97+
assert.ok(fieldsPassed);
9198
});

0 commit comments

Comments
 (0)