Permalink
Browse files

Changes to support custom content-type and getLengthSync.

  • Loading branch information...
idralyuk committed May 2, 2012
1 parent 6431c10 commit 7e354e1242cb8538ab2a9bc8fc3b4f3592bc58c9
Showing with 22 additions and 1 deletion.
  1. +22 −1 lib/form_data.js
View
@@ -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) {
@@ -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();
@@ -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;

0 comments on commit 7e354e1

Please sign in to comment.