[PR #19119] add Accept-Ranges header for audio/video files #29076

Closed
opened 2026-02-21 20:44:49 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/19119

State: closed
Merged: Yes


Summary

Fixes #19116
This PR adds the Accept-Ranges: bytes header for audio/video files in the /files/<uuid:file_id>/file-preview endpoint. The change enables partial content requests (HTTP Range headers) to support progress bar scrubbing during playback.


Motivation & Context

  • Issue‌: Previously, audio/video responses lacked the Accept-Ranges header, preventing clients (e.g., browsers) from requesting partial content.
  • Impact‌: Users could not seek to specific positions during playback via the progress bar.
  • Solution‌: Explicitly set the Accept-Ranges header for supported media types to advertise range request support.

Key Changes

  1. Added MIME Type Check
    The server now checks if the file's MIME type matches a predefined list of audio/video formats. If supported, it adds the Accept-Ranges: bytes header.
    # Add Accept-Ranges header for audio/video files
    if upload_file.mime_type in [
        "audio/mpeg",
        "audio/wav",
        "audio/mp4",
        "audio/ogg",
        "audio/flac",
        "audio/aac",
        "video/mp4",
        "video/webm",
        "video/quicktime",
        "audio/x-m4a",
    ]:
        response.headers["Accept-Ranges"] = "bytes"
    
**Original Pull Request:** https://github.com/langgenius/dify/pull/19119 **State:** closed **Merged:** Yes --- ### &zwnj;**Summary**&zwnj; Fixes #19116 This PR adds the `Accept-Ranges: bytes` header for audio/video files in the `/files/<uuid:file_id>/file-preview` endpoint. The change enables partial content requests (HTTP `Range` headers) to support progress bar scrubbing during playback. --- ### &zwnj;**Motivation & Context**&zwnj; - &zwnj;**Issue**&zwnj;: Previously, audio/video responses lacked the `Accept-Ranges` header, preventing clients (e.g., browsers) from requesting partial content. - &zwnj;**Impact**&zwnj;: Users could not seek to specific positions during playback via the progress bar. - &zwnj;**Solution**&zwnj;: Explicitly set the `Accept-Ranges` header for supported media types to advertise range request support. --- ### &zwnj;**Key Changes**&zwnj; 1. &zwnj;**Added MIME Type Check**&zwnj; The server now checks if the file's MIME type matches a predefined list of audio/video formats. If supported, it adds the `Accept-Ranges: bytes` header. ```python # Add Accept-Ranges header for audio/video files if upload_file.mime_type in [ "audio/mpeg", "audio/wav", "audio/mp4", "audio/ogg", "audio/flac", "audio/aac", "video/mp4", "video/webm", "video/quicktime", "audio/x-m4a", ]: response.headers["Accept-Ranges"] = "bytes"
yindo added the pull-request label 2026-02-21 20:44:49 -05:00
yindo closed this issue 2026-02-21 20:44:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29076