Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created January 31, 2010 01:55
Show Gist options
  • Save isaacs/290838 to your computer and use it in GitHub Desktop.
Save isaacs/290838 to your computer and use it in GitHub Desktop.
diff --git a/lib/multipart.js b/lib/multipart.js
index a5afeff..4114569 100644
--- a/lib/multipart.js
+++ b/lib/multipart.js
@@ -51,7 +51,8 @@ proto.init = function(options) {
this.part = null;
if ('headers' in options) {
- var req = options, contentType = req.headers['content-type'];
+ var req = options,
+ contentType = req.headers['content-type'].slice(-1)[0];
if (!contentType) {
throw new Error('Content-Type header not set');
}
@@ -62,7 +63,7 @@ proto.init = function(options) {
}
this.boundary = '--'+boundary[1];
- this.bytesTotal = req.headers['content-length'];
+ this.bytesTotal = req.headers['content-length'].slice(-1)[0];
var self = this;
req
@@ -131,6 +132,7 @@ sys.inherits(Part, events.EventEmitter);
Part.prototype.parsedHeaders = function() {
for (var header in this.headers) {
+ // TODO: Support multiple values?
var parts = this.headers[header].split(/; ?/), parsedHeader = {};
for (var i = 0; i < parts.length; i++) {
var pair = parts[i].split('=');
@@ -177,6 +179,7 @@ Part.prototype.write = function(chunk) {
return;
} else if (offset > 0) {
var header = this.buffer.substr(0, offset).split(/: ?/);
+ // TODO: support multiple values?
this.headers[header[0].toLowerCase()] = header[1];
this.buffer = this.buffer.substr(offset+2);
} else if (offset === false) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment