Permalink
Browse files

Added charset to mimetype when available

  • Loading branch information...
1 parent d91f706 commit 668c08c92c60bba1d486341dedc03d45a636e3ec @mafintosh committed Nov 12, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 main.js
View
11 main.js
@@ -32,6 +32,9 @@ function File (options) {
this.mimetype = options.mimetype || mime.lookup(this.path.slice(this.path.lastIndexOf('.')+1))
+ var charset = mime.charsets.lookup(this.mimetype);
+ if (charset) this.mimetype+='; charset='+charset;
+
var stopBuffering = function () {
self.buffering = false
while (self.buffers.length) {
@@ -107,13 +110,13 @@ function File (options) {
// Destination is not an HTTP response, GET and HEAD method are not allowed
return
}
-
+
if (self.src.method !== 'HEAD') {
fs.createReadStream(self.path).pipe(self.dest)
}
return
}
-
+
if (self.src && (self.src.method === 'PUT' || self.src.method === 'POST')) {
if (!err) {
// TODO handle overwrite case
@@ -129,7 +132,7 @@ function File (options) {
}
return
}
-
+
// Desination is an HTTP response, we already handled 404 and 500
if (self.dest && self.dest.writeHead) {
self.dest.statusCode = 200
@@ -158,7 +161,7 @@ function File (options) {
} else {
finish(err, stats)
}
-
+
if (!self.src && !self.dest) {
if (self.buffers.length > 0) {
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))

0 comments on commit 668c08c

Please sign in to comment.