Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:mikeal/filed

  • Loading branch information...
commit 129c3c403ae002ad5436f36959acc0725f3aaa7c 2 parents 228294c + f7c21c9
@mikeal mikeal authored
Showing with 12 additions and 8 deletions.
  1. +12 −8 main.js
View
20 main.js
@@ -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
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.