cobalt/src/modules/stream/internal.js

24 lines
664 B
JavaScript
Raw Normal View History

2024-04-26 12:53:50 +01:00
import { request } from 'undici'
export async function internalStream(streamInfo, res) {
try {
const req = await request(streamInfo.url, {
headers: streamInfo.headers,
signal: streamInfo.controller.signal,
maxRedirections: 16
});
res.status(req.statusCode);
for (const [ name, value ] of Object.entries(req.headers))
res.setHeader(name, value)
if (req.statusCode < 200 || req.statusCode > 299)
return res.destroy();
req.body.pipe(res);
req.body.on('error', () => res.destroy());
} catch {
streamInfo.controller.abort();
}
}