api/url: replace user-agent argument with headers in redirect helpers

This commit is contained in:
Felix Vuong 🍂
2025-03-29 20:11:56 +07:00
committed by jj
parent b1bde25dee
commit a6240d0192
4 changed files with 11 additions and 20 deletions

View File

@@ -1,11 +1,11 @@
import { request } from 'undici';
const redirectStatuses = new Set([301, 302, 303, 307, 308]);
export async function getRedirectingURL(url, dispatcher, userAgent) {
export async function getRedirectingURL(url, dispatcher, headers) {
const location = await request(url, {
dispatcher,
method: 'HEAD',
headers: { 'user-agent': userAgent }
headers: headers
}).then(r => {
if (redirectStatuses.has(r.statusCode) && r.headers['location']) {
return r.headers['location'];