Skip to content

Commit

Permalink
Merge pull request #27 from artifactlabs/master
Browse files Browse the repository at this point in the history
Lets add the option for User Agent
  • Loading branch information
samholmes committed May 1, 2019
2 parents 7ea6a7c + 5a23bc5 commit ef532ed
Show file tree
Hide file tree
Showing 3 changed files with 541 additions and 4 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var shorthandProperties = {


exports = module.exports = function(url, cb, options){
exports.getHTML(url, function(err, html){
var userAgent = (options || {}).userAgent || 'NodeOpenGraphCrawler (https://github.com/samholmes/node-open-graph)'
exports.getHTML(url, userAgent, function(err, html){
if (err) return cb(err);

try {
Expand All @@ -27,7 +28,7 @@ exports = module.exports = function(url, cb, options){
}


exports.getHTML = function(url, cb){
exports.getHTML = function(url, userAgent, cb){
var purl = require('url').parse(url);

if (!purl.protocol)
Expand All @@ -39,7 +40,8 @@ exports.getHTML = function(url, cb){
url: url,
encoding: 'utf8',
gzip: true,
jar: true
jar: true,
headers: { 'User-Agent': userAgent },
},
function(err, res, body) {
if (err) return cb(err);
Expand Down
Loading

0 comments on commit ef532ed

Please sign in to comment.