Skip to content

Commit

Permalink
Added support for HEAD method.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr committed Jul 16, 2010
1 parent 7040a22 commit b3160d1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/renderer.js
Expand Up @@ -113,7 +113,9 @@ RequestContext.prototype.render = function(view, useLayout) {
this.response.end();
} else if(typeof view == 'function') {
this.response.writeHead(this.status, this.headers);
view();
if(this.request.method != 'HEAD') {
view();
}
this.response.end();
} else {
if(useLayout === undefined) {
Expand Down Expand Up @@ -148,11 +150,20 @@ RequestContext.prototype.renderText = function(text) {

RequestContext.prototype.send = function(text) {
this.response.writeHead(this.status, this.headers);
this.response.write(text, this.encoding);
if(this.request.method != 'HEAD') {
this.response.write(text, this.encoding);
}
this.response.end();
};

RequestContext.prototype.renderStatic = function() {
if(this.request.method != 'GET' && this.request.method != 'HEAD') {
self.extn = defaultViewExtn;
self.headers['content-type'] = mime.mimes[defaultViewExtn];
self.renderError(404);
return;
}

var staticFile = staticsDir + decodeURIComponent(url.parse(this.request.url).pathname);
var self = this;
fs.stat(staticFile, function(err, stats) {
Expand All @@ -168,9 +179,13 @@ RequestContext.prototype.renderStatic = function() {
self.headers['content-length'] = stats.size;
var rs = fs.createReadStream(staticFile);
self.response.writeHead(self.status, self.headers);
sys.pump(rs, self.response, function() {
if(this.request.method == 'GET') {
sys.pump(rs, self.response, function() {
self.response.end();
});
} else {
self.response.end();
});
}
}
});
};
Expand Down

0 comments on commit b3160d1

Please sign in to comment.