Last active
December 20, 2015 01:08
-
-
Save thlorenz/6046358 to your computer and use it in GitHub Desktop.
HEAD request using https and hyperquest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The below works, although having to call res.on('data') is not ideal | |
var https = require('https'); | |
var opts = { | |
hostname : 'github.com' | |
, path : '/substack/hyperquest' | |
, method : 'GET' | |
} | |
https.request(opts, function (res) { | |
console.log('statusCode: ', res.statusCode); | |
res.on('data', function () { /* don't care but need to call res.on('data', fn) since it hangs otherwise */ }) | |
}).end(); | |
// => statusCode: 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The below does the same as the above. Tricky part that you have to call .end() as well (not documented on hyperquest site). | |
// Advantage is that res.on('data') call is not needed since it returns without that call | |
var hyperquest = require('hyperquest'); | |
var url = 'https://github.com/substack/hyperquest'; | |
var opts = { method: 'HEAD' }; | |
hyperquest(url, opts, function (err, res) { | |
if (err) return console.error(err); | |
console.log('statusCode: ', res.statusCode); | |
}).end(); | |
// => statusCode: 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment