Improves remote image download protocol handling

Ensures correct protocol (HTTP/HTTPS) is used when downloading
remote images by using the parsed URL object for the request.

This fixes potential issues where the protocol might be incorrectly
determined, especially when dealing with case-insensitive URL schemes.
This commit is contained in:
AlexKucera committed 2025-11-05 08:33:48 +01:00
1 parent a9f436f972
commit 35a5249607
1 file changed
+4 -3
+4 -3
View File
@@ -105,12 +105,13 @@ export class EmbedProcessor {
const outputPath = path.join(tempDir, finalFileName);
// Select appropriate protocol
const protocol = imageUrl.startsWith('https') ? https : http;
// Select appropriate protocol based on parsed URL (handles case-insensitive schemes)
const protocol = urlObj.protocol === 'https:' ? https : http;
console.log(`Export: Downloading remote image: ${imageUrl}`);
const request = protocol.get(imageUrl, (response) => {
// Use parsed URL object for the request to ensure correct protocol handling
const request = protocol.get(urlObj, (response) => {
// Handle redirects
if (response.statusCode === 301 || response.statusCode === 302) {
const redirectUrl = response.headers.location;