creationix / couch-client

A minimal CouchDB client that easy and powerful
MIT License
101 stars 9 forks source link

HEAD requests fail #19

Open diversario opened 13 years ago

diversario commented 13 years ago

When I try to perform a HEAD request I get this:

undefined:0

^
SyntaxError: Unexpected end of input
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/usr/local/lib/node/.npm/couch-client/0.0.4/package/lib/cou ch-client.js:80:45)
    at IncomingMessage.emit (events.js:81:20)
    at HTTPParser.onMessageComplete (http.js:132:23)
    at Socket.ondata (http.js:1206:22)
    at Socket._onReadable (net.js:675:27)
    at IOWatcher.onReadable [as callback] (net.js:177:10)

Does couch-client support HEAD requests?

jacksonp commented 13 years ago

I came across this as well. I wanted the response status from HEAD requests so I changed line 81 in my copy of lib/couch-client.js to:

    if (callback) {
      if (options.method === 'HEAD') {
        callback(null, response.statusCode);
      } else {
        callback(null, JSON.parse(body));
      }
    }