1 | 'use strict';
|
2 |
|
3 | const Client = require('..');
|
4 | const client = new Client();
|
5 |
|
6 | client
|
7 |
|
8 | .before((req, next) => {
|
9 | console.log('\n======================\nbefore:\n\n' + req.toString());
|
10 | next(null, req);
|
11 | })
|
12 |
|
13 | .after(parseBody)
|
14 | .after((res, next) => {
|
15 | console.log('\n======================\nafter:\n\n' + res.toString());
|
16 | next(null, res);
|
17 | })
|
18 |
|
19 | .get('http://httpbin.org/html')
|
20 |
|
21 | .then(
|
22 | res => console.log('\n======================\ndone:\n\n' + res.toString()),
|
23 | err => console.log(err)
|
24 | )
|
25 |
|
26 | ;
|
27 |
|
28 | function parseBody(res, next) {
|
29 | let body = '';
|
30 |
|
31 | res.body.on('data', function (data) {
|
32 | body += data.toString();
|
33 | });
|
34 |
|
35 | res.body.on('end', function () {
|
36 | res.body = body;
|
37 | next(null, res);
|
38 | });
|
39 |
|
40 | } |
\ | No newline at end of file |