mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-16 21:29:58 +00:00
24 lines
664 B
JavaScript
24 lines
664 B
JavaScript
|
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();
|
||
|
}
|
||
|
}
|