diff options
| author | 8cy <[email protected]> | 2020-04-03 02:37:42 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:37:42 -0700 |
| commit | 60867fb030bae582082340ead7dbc7efdc2f5398 (patch) | |
| tree | 4c6a7356351be2e4914e15c4703172597c45656e /node_modules/http-basic/test/index.js | |
| parent | commenting (diff) | |
| download | s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip | |
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/http-basic/test/index.js')
| -rw-r--r-- | node_modules/http-basic/test/index.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/node_modules/http-basic/test/index.js b/node_modules/http-basic/test/index.js new file mode 100644 index 0000000..d5c8242 --- /dev/null +++ b/node_modules/http-basic/test/index.js @@ -0,0 +1,89 @@ +'use strict'; + +var assert = require('assert'); +var request = require('../'); + +request('GET', 'http://example.com', function (err, res) { + if (err) throw err; + + console.log('response A'); + assert(res.statusCode === 200); + res.body.resume(); +}); + +request('GET', 'http://example.com:80', function (err, res) { + if (err) throw err; + + console.log('response A1'); + assert(res.statusCode === 200); + res.body.resume(); +}); + + +request('GET', 'https://www.promisejs.org', function (err, res) { + if (err) throw err; + + console.log('response B'); + assert(res.statusCode === 200); + res.body.resume(); +}); + +request('GET', 'https://promisejs.org', {followRedirects: true}, function (err, res) { + if (err) throw err; + + console.log('response C'); + assert(res.statusCode === 200); + res.body.resume(); +}); + +var CACHED = 'https://www.promisejs.org/polyfills/promise-done-1.0.0.js'; + +request('GET', CACHED, {cache: 'memory'}, function (err, res) { + if (err) throw err; + + console.log('response D (populate cache)'); + assert(res.statusCode === 200); + res.body.on('data', function () {}); + res.body.on('end', function () { + request('GET', CACHED, {cache: 'memory'}, function (err, res) { + if (err) throw err; + + console.log('response E (from cache)'); + assert(res.fromCache === true); + assert(res.fromNotModified === false); + assert(res.statusCode === 200); + res.body.resume(); + }); + }); +}); + + + +request('GET', CACHED, {cache: 'file'}, function (err, res) { + if (err) throw err; + + console.log('response G (populate file cache)'); + assert(res.statusCode === 200); + res.body.on('data', function () {}); + res.body.on('end', function () { + setTimeout(function () { + request('GET', CACHED, {cache: 'file'}, function (err, res) { + if (err) throw err; + + console.log('response H (from file cache)'); + assert(res.fromCache === true); + assert(res.fromNotModified === false); + assert(res.statusCode === 200); + res.body.resume(); + }); + }, 1000); + }); +}); + +request('GET', 'https://api.github.com/repos/isaacs/npm', {allowRedirectHeaders: ['User-Agent'], followRedirects: true, headers: {'User-Agent': 'http-basic'}}, function (err, res) { + if (err) throw err; + + console.log('response I'); + assert(res.statusCode === 200); + res.body.resume(); +});
\ No newline at end of file |