diff --git a/lib/redmine.js b/lib/redmine.js index 5a4cfec..2730a92 100644 --- a/lib/redmine.js +++ b/lib/redmine.js @@ -10,8 +10,8 @@ /** * Module dependencies */ -var request = require('request'); var Url = require('url'); +var querystring = require('querystring'); //////////////////////////////////////////////////////////////////////////////////// /** @@ -39,7 +39,30 @@ function Redmine(host, config, port) { } var baseUrl = Url.format(host); - this._request = request.defaults({baseUrl: baseUrl}); + this._request = function (path, opts, callback) { + var fullpath = new Url.URL(baseUrl); + fullpath.pathname += path; + fullpath.search = querystring.stringify(opts.qs); + + var http = require(fullpath.protocol.replace(/:$/, '')); + var req = http.request(fullpath, opts, function (res) { + var body = []; + res.on('data', function (chunk){ + body.push(chunk); + }); + res.on('end', function () { + body = Buffer.concat(body); + if (opts.json) { + body = JSON.parse(body); + } + //console.debug(body); + callback(null, res, body); + }); + }); + req.on('error', function (err) { callback(err); }); + req.end(); + return req; + }; if (!config || !(config.apiKey || (config.username && config.password))) { throw new Error('You should provide an API key or username & password !'); diff --git a/package.json b/package.json index 023f00c..83e35af 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "author": "wayne@zanran.me", "license": "GPL-3.0", "dependencies": { - "debug": "^2.2.0", - "request": "^2.75.0" + "debug": "^2.2.0" }, "devDependencies": { "grunt": "^1.0.1",