got-headers
Version:
Hit URL and get HTTP headers only (using got module)
64 lines (40 loc) • 2.3 kB
Markdown
[](https://www.npmjs.com/package/got-headers)
[](http://travis-ci.org/overlookmotel/got-headers)
[](https://david-dm.org/overlookmotel/got-headers)
[](https://david-dm.org/overlookmotel/got-headers)
[](https://coveralls.io/r/overlookmotel/got-headers)
Function to hit a URL and stop as soon as headers are received i.e. do not fetch the body of the HTTP response.
Useful for example for checking the size of a large file without downloading it. Uses GET HTTP method (or whatever method requested) rather than HEAD as some servers may not support HEAD, or not use cookies with HEAD etc.
Returns a [Bluebird](https://www.npmjs.com/package/bluebird) Promise which resolves to the response object, or rejects with an error.
Uses [got](https://www.npmjs.com/package/got) to make the HTTP request.
### headers(url, [options])
```js
const headers = require('got-headers');
headers('http://www.google.com').then(function(res) {
// Print headers object
console.log(res.headers);
}).catch(function(err) {
// Print error
console.log('Error!', err);
// Print response object
console.log(err.res);
});
```
`options` object is passed directly to [got](https://www.npmjs.com/package/got) - use any of got's options.
Use `npm test` to run the tests. Use `npm run cover` to check coverage.
There are no tests at present but it seems to work fine!
See [changelog.md](https://github.com/overlookmotel/got-headers/blob/master/changelog.md)
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/got-headers/issues
Pull requests are very welcome. Please:
* ensure all tests pass before submitting PR
* add an entry to changelog
* add tests for new features
* document new functionality/API additions in README