Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for #12 and #13 #14

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.