diff --git a/hitit.js b/hitit.js index 4601f60..ba870bb 100644 --- a/hitit.js +++ b/hitit.js @@ -1,5 +1,5 @@ /* -hitit - v0.1.2 +hitit - v0.2.0 Written by Federico Pereiro (fpereiro@gmail.com) and released into the public domain. @@ -12,6 +12,7 @@ Please refer to readme.md to read the annotated source (but not yet!). var fs = require ('fs'); var http = require ('http'); + var https = require ('https'); var dale = require ('dale'); var teishi = require ('teishi'); @@ -39,14 +40,17 @@ Please refer to readme.md to read the annotated source (but not yet!). ['options.code', o.code, [undefined, 0, -1].concat (dale.do (http.STATUS_CODES, function (v, k) {return parseInt (k)})), teishi.test.equal, 'oneOf'], ['options.apres', o.apres, ['undefined', 'function'], 'oneOf'], ['options.apres', o.delay, ['undefined', 'integer'], 'oneOf'], + ['options.https', o.https, ['undefined', 'boolean'], 'oneOf'], + ['options.rejectUnauthorized', o.https, ['undefined', 'boolean'], 'oneOf'], ['state', state, 'object'], ]}, ['cb', cb, 'function'] ], function (error) { - cb ({ + if (type (cb) === 'function') cb ({ code: -2, error: error }); + else log (error); })) return; var resolve = function (w) { @@ -70,9 +74,12 @@ Please refer to readme.md to read the annotated source (but not yet!). method: resolve (o.method) || resolve (state.method), headers: o.headers, path: resolve (o.path), + rejectUnauthorized: ! o.rejectUnauthorized === false }; - var request = http.request (opt, function (response) { + var protocol = o.https ? https : http; + + var request = protocol.request (opt, function (response) { response.setEncoding ('utf8'); response.body = ''; diff --git a/package.json b/package.json index 71f02e6..31cb197 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hitit", - "version": "0.1.2", + "version": "0.2.0", "description": "Minimalistic tool for API testing.", "dependencies": { "dale": "4.1.0", diff --git a/readme.md b/readme.md index bf053d7..659aaa2 100644 --- a/readme.md +++ b/readme.md @@ -4,12 +4,11 @@ hitit is a minimalistic tool for testing an HTTP API. ## Current status of the project -The current version of hitit, v0.1.2, is considered to be *unstable* and *incomplete*. [Suggestions](https://github.com/fpereiro/hitit/issues) and [patches](https://github.com/fpereiro/hitit/pulls) are welcome. Future changes planned are: +The current version of hitit, v0.2.0, is considered to be *unstable* and *incomplete*. [Suggestions](https://github.com/fpereiro/hitit/issues) and [patches](https://github.com/fpereiro/hitit/pulls) are welcome. Future changes planned are: - Support for `multipart` uploads and downloads. - Support for concurrent testing (a.k.a stress testing). - Basic profiling. -- HTTPS support. ## Installation @@ -22,7 +21,7 @@ To install, type `npm i hitit`. ## Source code -The complete source code is contained in `hitit.js`. It is about 180 lines long. +The complete source code is contained in `hitit.js`. It is about 190 lines long. Annotated source code will be forthcoming when the library stabilizes.