From c0a181ef2bd94b539879f28eee9cd521ce8418ef Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 19 Aug 2013 01:20:38 +0300 Subject: [PATCH] Support for querying with HTTP HEAD requets to fetch only meta info like result count without returning all results. --- api.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api.coffee b/api.coffee index 10284b5..21c58e7 100644 --- a/api.coffee +++ b/api.coffee @@ -275,8 +275,8 @@ else ) else if QUERY_REGEX.test(urlParts.pathname) collectionName = QUERY_REGEX.exec(urlParts.pathname)[1] - if request.method isnt 'GET' - response.writeHead 405, {'Allow' : 'GET'} + if request.method not in ['GET', 'HEAD'] + response.writeHead 405, {'Allow' : 'GET, HEAD'} response.end('405 Method Not Allowed') return collection = db["#{collectionName}Collection"] @@ -316,6 +316,9 @@ else cur.limit(parseInt(urlParts.query.limit)) if urlParts.query.limit? cur.count((err, total) -> response.writeHead(200, {'Content-Type' : 'application/json', 'total' : total}) + if request.method is 'HEAD' + response.end() + return response.write("[\n") i = 0 cur.each((err, item) ->