Skip to main content

FileResult

Struct FileResult 

Source
pub struct FileResult { /* private fields */ }
Expand description

A file response — ASP.NET Core’s PhysicalFile(...) / File(...) / Results.File(...).

The host streams the source and fills in the HTTP metadata: Content-Length, ETag / Last-Modified validators, Accept-Ranges and Range handling (206 / 416), plus conditional requests (304). Files opened from a path derive their validators from size and mtime; streams become conditional when an entity_tag or last_modified is supplied.

Implementations§

Source§

impl FileResult

Source

pub fn path(path: impl Into<PathBuf>) -> FileResult

Send the file at path (ASP.NET Core’s PhysicalFile).

Source

pub fn stream(reader: impl AsyncRead + Send + Unpin + 'static) -> FileResult

Send an async reader of unknown length (chunked, no Range).

Source

pub fn seekable_stream( reader: impl AsyncRead + AsyncSeek + Send + Unpin + 'static, len: u64, ) -> FileResult

Send an async reader of known length that supports seeking, so clients can resume and cache (Content-Length, Range).

Source

pub fn with_body(body: FileBody) -> FileResult

Send a fully-specified FileBody.

Source

pub fn content_type(self, content_type: impl Into<String>) -> FileResult

Override the media type instead of deriving it from the extension.

Source

pub fn download_name(self, file_name: impl Into<String>) -> FileResult

Send the file as a download named file_name.

Source

pub fn inline_name(self, file_name: impl Into<String>) -> FileResult

Present the file inline under file_name.

Source

pub fn enable_range_processing(self, enabled: bool) -> FileResult

Enable or disable Range processing for the file source.

Source

pub fn last_modified(self, last_modified: SystemTime) -> FileResult

Advertise an explicit Last-Modified (required for a stream to support If-Modified-Since).

Source

pub fn entity_tag(self, entity_tag: impl Into<String>) -> FileResult

Advertise an explicit ETag (required for a stream to support If-None-Match).

Source

pub fn status(self, status: u16) -> FileResult

Override the HTTP status.

Source

pub fn header( self, key: impl Into<String>, value: impl Into<String>, ) -> FileResult

Add a response header.

Trait Implementations§

Source§

impl IActionResult for FileResult

Source§

fn execute<'life0, 'async_trait>( self: Box<FileResult>, ctx: &'life0 mut dyn IHttpContext, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, FileResult: 'async_trait,

Write this result into the response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more