Content-Length duplicated in headers for media files from s3 buckets

(#430) Bug Awaiting confirmation media self-hosting

Thread

Comment by @treminaor
RexSystem 1 vote originally by @treminaor on GitHub OP
Here's the fix:

1. packages/media_proxy/src/lib/HttpUtils.tsx

Removed manual Content-Length headers from media responses. Before:
if (range) {
    const length = range.end - range.start + 1;
    ctx.status(206);
    ctx.header('Content-Length', length.toString());
    ctx.header('Content-Range', `bytes ${range.start}-${range.end}/${size}`);
} else {
    ctx.header('Content-Length', size.toString());
}
After:
if (range) {
    const length = range.end - range.start + 1;
    ctx.status(206);
    ctx.header('Content-Range', `bytes ${range.start}-${range.end}/${size}`);
} else {
}

2. packages/s3/src/s3/ObjectController.tsx

Partially removed manual Content-Length handling in the normal non-range GET path. From the current snippet, the non-range branch no longer sets Content-Length, but the range branch still does. Current relevant block:
if (result.contentRange) {
    headers['Content-Range'] = result.contentRange;
    headers['Content-Length'] = String(
        parseInt(result.contentRange.split('/')[0]!.split('-')[1]!, 10) -
            parseInt(result.contentRange.split('/')[0]!.split('-')[0]!.split(' ')[1]!, 10) +
            1,
    );
    ctx.status(206);
} else {
}
So the normal image GET path is fixed, but range responses may still need cleanup later.