Skip to content

Commit de8437b

Browse files
author
Ubuntu
committed
use http instead of request
1 parent d536479 commit de8437b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var Entities = require("entities");
22
var FS = require('fs');
33
var XML2JS = require('xml2js');
44

5-
var Request = require('request');
5+
var HTTP = require('http');
6+
var HTTPS = require('https');
67

78
var Parser = module.exports = {};
89

@@ -48,11 +49,19 @@ Parser.parseString = function(xml, callback) {
4849
}
4950

5051
Parser.parseURL = function(url, callback) {
51-
Request(url, function(err, resp, body) {
52-
if (err) return callback(err);
53-
if (resp.statusCode !== 200) return callback(new Error('Status code is: ' + resp.statusCode))
54-
return Parser.parseString(body, callback);
52+
var xml = '';
53+
var get = url.indexOf('https') === 0 ? HTTPS.get : HTTP.get;
54+
var req = get(url, function(res) {
55+
if (res.statusCode >= 300) return callback(new Error("Status code " + res.statusCode))
56+
res.setEncoding('utf8');
57+
res.on('data', function(chunk) {
58+
xml += chunk;
59+
});
60+
res.on('end', function() {
61+
return Parser.parseString(xml, callback);
62+
})
5563
})
64+
req.on('error', callback);
5665
}
5766

5867
Parser.parseFile = function(file, callback) {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
},
1515
"dependencies": {
1616
"entities": "^1.1.1",
17-
"request": "^2.67.0",
1817
"xml2js": "^0.4.15"
1918
},
2019
"directories": {

0 commit comments

Comments
 (0)