Permalink
Browse files

support HTTP HEAD method, closes #58

  • Loading branch information...
1 parent aa20e82 commit 3f62973cc4a1a94583973a2da7fc7a7019d9e731 @disfated disfated committed Jan 8, 2012
Showing with 17 additions and 3 deletions.
  1. +5 −0 lib/restler.js
  2. +12 −3 test/restler.js
View
5 lib/restler.js
@@ -224,6 +224,10 @@ function del(url, options) {
return request(url, shortcutOptions(options, 'DELETE'));
}
+function head(url, options) {
+ return request(url, shortcutOptions(options, 'HEAD'));
+}
+
var parsers = {
auto: function(data, callback) {
var contentType = this.headers['content-type'];
@@ -356,6 +360,7 @@ mixin(exports, {
post: post,
put: put,
del: del,
+ head: head,
parsers: parsers,
file: multipart.file,
data: multipart.data
View
15 test/restler.js
@@ -45,12 +45,14 @@ function echoResponse(request, response) {
request.addListener('data', function(chunk) {
echo += chunk.toString('binary');
});
+
request.addListener('end', function() {
response.writeHead(request.headers['x-status-code'] || 200, {
- 'Content-Type': 'text/plain',
- 'Content-Length': echo.length
+ 'content-type': 'text/plain',
+ 'content-length': echo.length,
+ 'request-method': request.method.toLowerCase()
});
- response.end(echo);
+ response.end(request.method == 'HEAD' ? undefined : echo);
});
}
@@ -87,6 +89,13 @@ module.exports['Basic'] = {
});
},
+ 'Should HEAD': function(test) {
+ rest.head(host).on('complete', function(data, response) {
+ test.equal(response.headers['request-method'], 'head', 'should be HEAD');
+ test.done();
+ });
+ },
+
'Should GET withouth path': function(test) {
rest.get(host).on('complete', function(data) {
test.re(data, /^GET \//, 'should hit /');

0 comments on commit 3f62973

Please sign in to comment.