Skip to content

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fpereiro committed Jun 28, 2018
1 parent 25ee2a1 commit 51749f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
29 changes: 17 additions & 12 deletions hitit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Written by Federico Pereiro (fpereiro@gmail.com) and released into the public do
function () {return dale.do ({
string: ['tag', 'host', 'method', 'path'],
integer: ['port', 'delay', 'timeout'],
boolean: ['https', 'rejectUnauthorized'],
boolean: ['https', 'rejectUnauthorized', 'raw'],
function: 'apres',
headers: 'object'
}, function (keys, type) {
Expand Down Expand Up @@ -92,28 +92,33 @@ Written by Federico Pereiro (fpereiro@gmail.com) and released into the public do
path: o.path,
rejectUnauthorized: ! o.rejectUnauthorized === false
}, function (response) {
response.setEncoding ('utf8');
response.body = '';
if (! o.raw) {
response.setEncoding ('utf8');
response.body = '';
}
else response.body = [];

response.on ('data', function (buffer) {
response.body += buffer.toString ();
! o.raw ? response.body += buffer.toString () : response.body.push (buffer);
});

response.on ('end', function () {
var rdata = {
code: response.statusCode,
headers: response.headers,
body: response.body,
body: ! o.raw ? response.body : Buffer.concat (response.body),
time: [startTime, Date.now ()],
request: o
}
var parsed;
if ((response.headers ['content-type'] || '').match (/^application\/json/)) {
parsed = teishi.p (response.body);
if (parsed === false) return cb (dale.obj (0, rdata, function () {
return ['error', 'Invalid JSON!'];
}));
rdata.body = parsed;
if (! o.raw) {
var parsed;
if ((response.headers ['content-type'] || '').match (/^application\/json/)) {
parsed = teishi.p (response.body);
if (parsed === false) return cb (dale.obj (0, rdata, function () {
return ['error', 'Invalid JSON!'];
}));
rdata.body = parsed;
}
}

if (o.code !== '*' && rdata.code !== (o.code || 200)) return cb (rdata);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hitit",
"version": "1.2.0",
"version": "1.2.1",
"description": "Minimalistic tool for API testing.",
"dependencies": {
"dale": "4.3.1",
Expand Down
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hitit is a minimalistic tool for testing an HTTP(S) API. It is a stopgap until I

## Current status of the project

The current version of hitit, v1.2.0, is considered to be *somewhat stable* and *somewhat complete*. [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, v1.2.1, is considered to be *mostly stable* and *mostly complete*. [Suggestions](https://github.com/fpereiro/hitit/issues) and [patches](https://github.com/fpereiro/hitit/pulls) are welcome. Future changes planned are:

- Support for concurrent testing (a.k.a stress testing).

Expand Down Expand Up @@ -40,6 +40,7 @@ To do a single request, use `h.one`. This function takes three arguments: `state
- `timeout`: optional integer that will abort the request after `body.timeout` seconds elapse of socket inactivity. Defaults to `60`.
- `https`: optional boolean. If true, `https` will be used instead of `http`.
- `rejectUnauthorized`: optional boolean. If `false`, insecure `https` will be accepted by default (this is useful when you're testing with a self-signed certificate).
- `raw`: optional boolean. If true, the response's body will be returned as a raw buffer.

`state` must also be an object. It serves two purposes: #1 keep state between requests; and #2 have default values for some request parameters. Regarding keeping state between requests, you can assign any key in this object for your own purposes, *as long as is none of the keys that `options` can have*. If you assign a key that is one of the `options` keys (for example, `host`), if `options.host` is `undefined`, `state.host` will be considered as the `host`. This is what enables #2.

Expand Down Expand Up @@ -92,7 +93,7 @@ In this case, notice that `host` and `port` are not defined and must hence be pa

## Source code

The complete source code is contained in `hitit.js`. It is about 230 lines long.
The complete source code is contained in `hitit.js`. It is about 240 lines long.

## License

Expand Down

0 comments on commit 51749f1

Please sign in to comment.