Skip to content

Commit

Permalink
Changes to support custom content-type and getLengthSync.
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Dralyuk committed May 2, 2012
1 parent 6431c10 commit 7e354e1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/form_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ FormData.prototype._lastBoundary = function() {

FormData.prototype.getHeaders = function(userHeaders) {
var formHeaders = {
'content-type': 'multipart/form-data; boundary=' + this.getBoundary(),
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
};

for (var header in userHeaders) {
Expand All @@ -106,6 +106,17 @@ FormData.prototype.getHeaders = function(userHeaders) {
return formHeaders;
}

FormData.prototype.getCustomHeaders = function(contentType) {
contentType = contentType ? contentType : 'multipart/form-data';

var formHeaders = {
'content-type': contentType + '; boundary=' + this.getBoundary(),
'content-length': this.getLengthSync()
};

return formHeaders;
}

FormData.prototype.getBoundary = function() {
if (!this._boundary) {
this._generateBoundary();
Expand All @@ -125,6 +136,16 @@ FormData.prototype._generateBoundary = function() {
this._boundary = boundary;
};

FormData.prototype.getLengthSync = function() {
var knownLength = this._overheadLength + this._valueLength;

if (this._streams.length) {
knownLength += this._lastBoundary().length;
}

return knownLength;
};

FormData.prototype.getLength = function(cb) {
var knownLength = this._overheadLength + this._valueLength;

Expand Down

0 comments on commit 7e354e1

Please sign in to comment.