AJ ONeal
3 years ago
6 changed files with 182 additions and 4 deletions
@ -0,0 +1,27 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
var request = require('../'); |
||||
|
|
||||
|
async function main() { |
||||
|
var tpath = '/tmp/google-index.html'; |
||||
|
var resp = await request({ |
||||
|
url: 'https://google.com', |
||||
|
encoding: null, |
||||
|
stream: tpath |
||||
|
}); |
||||
|
console.log('[Response Headers]'); |
||||
|
console.log(resp.toJSON().headers); |
||||
|
|
||||
|
//console.error(resp.headers, resp.body.byteLength);
|
||||
|
await resp.stream; |
||||
|
console.log('[Response Body] written to', tpath); |
||||
|
} |
||||
|
|
||||
|
main() |
||||
|
.then(function () { |
||||
|
console.log('Pass'); |
||||
|
}) |
||||
|
.catch(function (e) { |
||||
|
console.error('Fail'); |
||||
|
console.error(e.stack); |
||||
|
}); |
@ -0,0 +1,34 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
var request = require('../'); |
||||
|
|
||||
|
async function main() { |
||||
|
var tpath = '/tmp/google-index.html'; |
||||
|
var resp = await request({ |
||||
|
url: 'https://google.com', |
||||
|
encoding: null, |
||||
|
stream: true |
||||
|
}); |
||||
|
console.log('[Response Headers]'); |
||||
|
console.log(resp.toJSON().headers); |
||||
|
|
||||
|
resp.on('data', function (chunk) { |
||||
|
console.log('[Data]', chunk.byteLength); |
||||
|
}); |
||||
|
resp.on('end', function (chunk) { |
||||
|
console.log('[End]'); |
||||
|
}); |
||||
|
|
||||
|
//console.error(resp.headers, resp.body.byteLength);
|
||||
|
await resp.stream; |
||||
|
console.log('[Close]'); |
||||
|
} |
||||
|
|
||||
|
main() |
||||
|
.then(function () { |
||||
|
console.log('Pass'); |
||||
|
}) |
||||
|
.catch(function (e) { |
||||
|
console.error('Fail'); |
||||
|
console.error(e.stack); |
||||
|
}); |
@ -1,5 +1,5 @@ |
|||||
{ |
{ |
||||
"name": "@root/request", |
"name": "@root/request", |
||||
"version": "1.5.0", |
"version": "1.7.0", |
||||
"lockfileVersion": 1 |
"lockfileVersion": 1 |
||||
} |
} |
||||
|
Loading…
Reference in new issue