Skip to content

Commit

Permalink
support HTTP HEAD method, closes danwrong#58
Browse files Browse the repository at this point in the history
  • Loading branch information
disfated committed Jan 8, 2012
1 parent aa20e82 commit 3f62973
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/restler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -356,6 +360,7 @@ mixin(exports, {
post: post,
put: put,
del: del,
head: head,
parsers: parsers,
file: multipart.file,
data: multipart.data
Expand Down
15 changes: 12 additions & 3 deletions test/restler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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 /');
Expand Down

0 comments on commit 3f62973

Please sign in to comment.