diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..24ffae674 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,20 @@ +{ + "bitwise":false, + "boss":true, + "expr":true, + "camelcase":false, + "curly":false, + "eqeqeq":true, + "freeze":true, + "immed":true, + "indent":2, + "latedef":"nofunc", + "laxbreak":true, + "laxcomma":true, + "newcap":true, + "noarg":true, + "node":true, + "strict": true, + "trailing":true, + "undef":true +} \ No newline at end of file diff --git a/lib/http.js b/lib/http.js index 4a76d7f82..a12ebcba5 100644 --- a/lib/http.js +++ b/lib/http.js @@ -3,51 +3,54 @@ * MIT Licensed */ -var url = require('url'), - req = require('request'); +"use strict"; + +var url = require('url'); +var req = require('request'); var VERSION = "0.2.0"; exports.request = function(rurl, data, callback, exheaders, exoptions) { - var curl = url.parse(rurl); - var secure = curl.protocol == 'https:'; - var host = curl.hostname; - var port = parseInt(curl.port || (secure ? 443 : 80)); - var path = [curl.pathname || '/', curl.search || '', curl.hash || ''].join(''); - var method = data ? "POST" : "GET"; - var headers = { - "User-Agent": "node-soap/" + VERSION, - "Accept" : "text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8", - "Accept-Encoding": "none", - "Accept-Charset": "utf-8", - "Connection": "close", - "Host" : host - }; - - if (typeof data == 'string') { - headers["Content-Length"] = Buffer.byteLength(data, 'utf8');; - headers["Content-Type"] = "application/x-www-form-urlencoded"; - } + var curl = url.parse(rurl); + var secure = curl.protocol === 'https:'; + var host = curl.hostname; + var port = parseInt(curl.port || (secure ? 443 : 80)); + var path = [curl.pathname || '/', curl.search || '', curl.hash || ''].join(''); + var method = data ? "POST" : "GET"; + var headers = { + "User-Agent": "node-soap/" + VERSION, + "Accept" : "text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8", + "Accept-Encoding": "none", + "Accept-Charset": "utf-8", + "Connection": "close", + "Host" : host + }; + var attr; + + if (typeof data === 'string') { + headers["Content-Length"] = Buffer.byteLength(data, 'utf8'); + headers["Content-Type"] = "application/x-www-form-urlencoded"; + } - exheaders = exheaders || {}; - for (var attr in exheaders) { headers[attr] = exheaders[attr]; } + exheaders = exheaders || {}; + for (attr in exheaders) { headers[attr] = exheaders[attr]; } - var options = { - uri: curl, - method: method, - headers: headers - }; + var options = { + uri: curl, + method: method, + headers: headers + }; - exoptions = exoptions || {}; - for (var attr in exoptions) { options[attr] = exoptions[attr]; } - - var request = req(options, function (error, res, body) { - if (error) { - callback(error); - } else { - request.on('error', callback); - callback(null, res, body); - } - }); - request.end(data); -} + exoptions = exoptions || {}; + for (attr in exoptions) { options[attr] = exoptions[attr]; } + + var request = req(options, function (error, res, body) { + if (error) { + callback(error); + } else { + request.on('error', callback); + callback(null, res, body); + } + }); + request.end(data); +}; diff --git a/package.json b/package.json index ef9f54508..e4d67ba48 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,9 @@ "lib": "./lib" }, "scripts": { - "test": "mocha -R spec -u exports test/*-test.js" + "mocha": "mocha -R spec -u exports test/*-test.js", + "jshint" : "jshint lib/http.js", + "test": "npm run-script jshint && npm run-script mocha" }, "keywords": [ "soap" @@ -31,6 +33,7 @@ } ], "devDependencies": { - "mocha": "~1.17.0" + "mocha": "~1.17.0", + "jshint": "~2.4.2" } }