Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix HEAD requests #21

Open
wants to merge 1 commit into from

3 participants

@kesla

The http responses were not ended properly

@kesla kesla fix HEAD requests
The http responses were not ended properly
d8dc964
@kesla

@mikeal Ping! This seem to have been forgotten about :)

@bahamas10

I just ended up implementing this on my own, to cover the same issue. Making a HEAD request to a static asset without if-none-match, it just hangs.

I made a second change, not sure if it is appropriate or not

@@ -108,7 +108,9 @@ function File (options) {
           return
         }

-        if (self.src.method !== 'HEAD') {
+        if (self.src.method === 'HEAD') {
+          self.dest.end()
+        } else {
           fs.createReadStream(self.path).pipe(self.dest)
         }
         return
@@ -137,7 +139,11 @@ function File (options) {
         self.dest.setHeader('etag', self.etag)
         self.dest.setHeader('last-modified', self.lastmodified)
         self.dest.setHeader('content-length', stats.size)
-        fs.createReadStream(self.path).pipe(self.dest)
+        if (self.src.method === 'HEAD') {
+          self.dest.end()
+        } else {
+          fs.createReadStream(self.path).pipe(self.dest)
+        }
         return
       }
@bahamas10

@mikeal ping on this again. not trying to annoy, but i'm working on a new project, and filed is 99% perfect for the job, it's just lacking proper support for HEAD requests. i'd love to see this get implemented.

@mikeal
Owner

can we get @bahamas10's additions to this pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 2, 2012
  1. @kesla

    fix HEAD requests

    kesla authored
    The http responses were not ended properly
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 0 deletions.
  1. +2 −0  main.js
  2. +13 −0 test/test.js
View
2  main.js
@@ -110,6 +110,8 @@ function File (options) {
if (self.src.method !== 'HEAD') {
fs.createReadStream(self.path).pipe(self.dest)
+ } else {
+ self.dest.end()
}
return
}
View
13 test/test.js
@@ -142,6 +142,12 @@ function testhttp () {
x.pipe(resp)
})
+ s.on('/test-head', function (req, resp) {
+ var x = filed(__dirname)
+ req.pipe(x)
+ x.pipe(resp)
+ })
+
s.listen(port, function () {
fs.createReadStream(testfile).pipe(request.put(url+'/test-req'))
@@ -201,6 +207,13 @@ function testhttp () {
console.log("Passed Not Found produces 404")
})
+ request.head(url+'/test-head', function (e, resp) {
+ if (e) throw e
+ if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is'+resp.statusCode)
+ assert.equal(resp.headers['content-type'], 'text/html')
+ console.log("Passed HEAD of directory index")
+ })
+
})
}
Something went wrong with that request. Please try again.