Skip to content

Commit

Permalink
Set the 'Content-Type' header on responses, using 'node-mime'.
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Apr 2, 2011
1 parent f604797 commit a76cff6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions index.js
@@ -1,7 +1,9 @@
var fs = require('fs');
var url = require('url');
var path = require('path');
var mime = require('mime');
var gitteh = require('gitteh');
var extname = require('path').extname;

var GIT_DIR = '.git';

Expand Down Expand Up @@ -94,7 +96,7 @@ function setup(repoPath, options) {
if (err.code === 'ENOENT') return next();
else return next(err);
}
serveBuffer(buf, res);
serveBuffer(buf, res, gitPath);
});
} else {
// Is a bare repo, serve file from resolved HEAD
Expand Down Expand Up @@ -149,7 +151,7 @@ function serveGitFile(repo, tree, parts, res, next) {
repo.getRawObject(entry.id, function(err, buf) {
if (err) return next(err);
if (!buf.data) return next();
serveBuffer(buf.data, res);
serveBuffer(buf.data, res, parts.join('/'));
});
} else {
repo.getTree(entry.id, function(err, entryTree) {
Expand All @@ -161,8 +163,9 @@ function serveGitFile(repo, tree, parts, res, next) {
}


function serveBuffer(buf, res) {
function serveBuffer(buf, res, filename) {
res.setHeader('Content-Length', buf.length);
res.setHeader('Content-Type', mime.lookup(extname(filename)) );
res.end(buf);
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -9,7 +9,8 @@
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)",
"main": "./index.js",
"dependencies": {
"gitteh": ">= 0.0.3"
"gitteh": ">= 0.0.3",
"mime": ">= 1.2.1"
},
"directories": {
"lib": "."
Expand All @@ -20,4 +21,4 @@
"files": [
""
]
}
}

0 comments on commit a76cff6

Please sign in to comment.