Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #14 from indexzero/master
Browse files Browse the repository at this point in the history
Fix for #12 and #13
  • Loading branch information
mikeal committed Jan 12, 2012
2 parents 3a060ae + 14363c9 commit f7c21c9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.js
Expand Up @@ -82,13 +82,14 @@ function File (options) {
}

// Source is an HTTP Server Request
if (self.src && (self.src.method === 'GET' || self.src.method === 'HEAD')) {

self.dest.setHeader('content-type', self.mimetype)
self.dest.setHeader('etag', self.etag)
self.dest.setHeader('last-modified', self.lastmodified)
if (self.src && (self.src.method === 'GET' || self.src.method === 'HEAD') && self.dest) {
if (self.dest.setHeader) {
self.dest.setHeader('content-type', self.mimetype)
self.dest.setHeader('etag', self.etag)
self.dest.setHeader('last-modified', self.lastmodified)
}

if (self.dest && self.dest.writeHead) {
if (self.dest.writeHead) {
if (self.src && self.src.headers) {
if (self.src.headers['if-none-match'] === self.etag ||
// Lazy last-modifed matching but it's faster than parsing Datetime
Expand All @@ -101,15 +102,17 @@ function File (options) {
// We're going to return the whole file
self.dest.statusCode = 200
self.dest.setHeader('content-length', stats.size)
} else if (self.dest && !self.dest.writeHead) {
} else {
// Destination is not an HTTP response, GET and HEAD method are not allowed
return
}
if (self.dest || self.src.method !== 'HEAD') {

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
Expand All @@ -125,6 +128,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
Expand Down

0 comments on commit f7c21c9

Please sign in to comment.