Skip to content

Commit e033910

Browse files
authored
Merge pull request rbren#13 from andjosh/master
Add user agent string to parseUrl method
2 parents dd76795 + 9299a4b commit e033910

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Entities = require("entities");
22
var FS = require('fs');
3+
var url = require('url');
34
var XML2JS = require('xml2js');
45

56
var HTTP = require('http');
@@ -177,10 +178,15 @@ Parser.parseString = function(xml, callback) {
177178
});
178179
}
179180

180-
Parser.parseURL = function(url, callback) {
181+
Parser.parseURL = function(feedUrl, callback) {
181182
var xml = '';
182-
var get = url.indexOf('https') === 0 ? HTTPS.get : HTTP.get;
183-
var req = get(url, function(res) {
183+
var get = feedUrl.indexOf('https') === 0 ? HTTPS.get : HTTP.get;
184+
var parsedUrl = url.parse(feedUrl);
185+
var req = get({
186+
hostname: parsedUrl.hostname,
187+
path: parsedUrl.path,
188+
headers: {'User-Agent': 'rss-parser'}
189+
}, function(res) {
184190
if (res.statusCode >= 300) return callback(new Error("Status code " + res.statusCode))
185191
res.setEncoding('utf8');
186192
res.on('data', function(chunk) {

0 commit comments

Comments
 (0)