47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
|
import { SmartRequest } from '@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);
|
||
|
});
|
||
|
|
||
|
// Set a timeout in case stream doesn't end
|
||
|
setTimeout(() => {
|
||
|
console.log('Timeout after 5 seconds');
|
||
|
process.exit(1);
|
||
|
}, 5000);
|
||
|
} else {
|
||
|
console.log('No stream available');
|
||
|
}
|
||
|
} catch (error) {
|
||
|
console.error('Error:', error);
|
||
|
process.exit(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
test();
|