41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
|
const { SmartRequest } = require('@push.rocks/smartrequest');
|
||
|
|
||
|
async function test() {
|
||
|
try {
|
||
|
const response = await SmartRequest.create()
|
||
|
.url('http://unix:/run/user/1000/docker.sock:/images/hello-world:latest/get')
|
||
|
.header('Host', 'docker.sock')
|
||
|
.get();
|
||
|
|
||
|
console.log('Response status:', response.status);
|
||
|
console.log('Response type:', typeof response);
|
||
|
|
||
|
const stream = response.streamNode();
|
||
|
console.log('Stream type:', typeof stream);
|
||
|
console.log('Has on method:', typeof stream.on);
|
||
|
|
||
|
if (stream) {
|
||
|
let chunks = 0;
|
||
|
stream.on('data', (chunk) => {
|
||
|
chunks++;
|
||
|
if (chunks <= 3) console.log('Got chunk', chunks, chunk.length);
|
||
|
});
|
||
|
stream.on('end', () => {
|
||
|
console.log('Stream ended, total chunks:', chunks);
|
||
|
process.exit(0);
|
||
|
});
|
||
|
stream.on('error', (err) => {
|
||
|
console.error('Stream error:', err);
|
||
|
process.exit(1);
|
||
|
});
|
||
|
} else {
|
||
|
console.log('No stream available');
|
||
|
}
|
||
|
} catch (error) {
|
||
|
console.error('Error:', error);
|
||
|
process.exit(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
test();
|