Skip to main content

StreamingResponseExt

Trait StreamingResponseExt 

Source
pub trait StreamingResponseExt {
    // Required methods
    fn stream_file<P: AsRef<Path>>(
        path: P,
        cx: Cx,
        content_type: &[u8],
    ) -> Result<Response>;
    fn stream_file_with_config<P: AsRef<Path>>(
        path: P,
        cx: Cx,
        content_type: &[u8],
        config: StreamConfig,
    ) -> Result<Response>;
    fn stream_file_range<P: AsRef<Path>>(
        path: P,
        range: ByteRange,
        total_size: u64,
        cx: Cx,
        content_type: &[u8],
    ) -> Result<Response>;
    fn stream_file_range_with_config<P: AsRef<Path>>(
        path: P,
        range: ByteRange,
        total_size: u64,
        cx: Cx,
        content_type: &[u8],
        config: StreamConfig,
    ) -> Result<Response>;
}
Expand description

Extension trait for creating streaming response bodies.

Required Methods§

Source

fn stream_file<P: AsRef<Path>>( path: P, cx: Cx, content_type: &[u8], ) -> Result<Response>

Create a streaming response from a file.

§Arguments
  • path - Path to the file to stream
  • cx - Capability context
  • content_type - MIME type for the Content-Type header
§Errors

Returns an error if the file cannot be opened.

Source

fn stream_file_with_config<P: AsRef<Path>>( path: P, cx: Cx, content_type: &[u8], config: StreamConfig, ) -> Result<Response>

Create a streaming response from a file with custom config.

§Errors

Returns an error if the file cannot be opened.

Source

fn stream_file_range<P: AsRef<Path>>( path: P, range: ByteRange, total_size: u64, cx: Cx, content_type: &[u8], ) -> Result<Response>

Create a 206 Partial Content response for a byte range of a file.

This is used to handle HTTP Range requests for partial content delivery.

§Arguments
  • path - Path to the file
  • range - The validated byte range to serve
  • total_size - Total size of the file (for Content-Range header)
  • cx - Capability context
  • content_type - MIME type for the Content-Type header
§Errors

Returns an error if the file cannot be opened or seeked.

Source

fn stream_file_range_with_config<P: AsRef<Path>>( path: P, range: ByteRange, total_size: u64, cx: Cx, content_type: &[u8], config: StreamConfig, ) -> Result<Response>

Create a 206 Partial Content response with custom streaming config.

§Errors

Returns an error if the file cannot be opened or seeked.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl StreamingResponseExt for Response

Source§

fn stream_file<P: AsRef<Path>>( path: P, cx: Cx, content_type: &[u8], ) -> Result<Response>

Source§

fn stream_file_with_config<P: AsRef<Path>>( path: P, cx: Cx, content_type: &[u8], config: StreamConfig, ) -> Result<Response>

Source§

fn stream_file_range<P: AsRef<Path>>( path: P, range: ByteRange, total_size: u64, cx: Cx, content_type: &[u8], ) -> Result<Response>

Source§

fn stream_file_range_with_config<P: AsRef<Path>>( path: P, range: ByteRange, total_size: u64, cx: Cx, content_type: &[u8], config: StreamConfig, ) -> Result<Response>

Implementors§