pub struct FileBody {
pub source: FileSource,
pub content_type: Option<String>,
pub file_name: Option<String>,
pub disposition: Disposition,
pub enable_range_processing: bool,
pub last_modified: Option<SystemTime>,
pub entity_tag: Option<String>,
}Expand description
A file response — the rust-webx counterpart of ASP.NET Core’s
File(...) / PhysicalFile(...) / Results.File(...).
The host streams the content and fills in the HTTP metadata:
Content-Length— exact when it is known (path, seekable stream)ETag/Last-Modified— derived from the file, or supplied viaFileBody::entity_tag/FileBody::last_modifiedfor streamsAccept-RangesandRangehandling (206/416) — when the source can seek andFileBody::enable_range_processingis left onIf-Range,If-None-Match,If-Modified-Since(304)
Build one with FileBody::path, FileBody::stream or
FileBody::seekable_stream, then hand it to
crate::route::scan::ResponseData::with_file.
Fields§
§source: FileSourceWhere the bytes come from.
content_type: Option<String>Media type. When None the host infers it from the path extension, or
falls back to application/octet-stream for streams.
file_name: Option<String>Name used in Content-Disposition.
disposition: DispositionWhether the content should be shown inline or downloaded.
enable_range_processing: boolWhether Range requests should be served (default true).
Turn it off to force a single full response — useful when range requests would multiply backend reads.
last_modified: Option<SystemTime>Last-Modified to advertise.
Derived from the file for FileSource::Path; required for a stream if
you want If-Modified-Since to work.
entity_tag: Option<String>ETag to advertise.
Derived from size and mtime for FileSource::Path; required for a
stream if you want If-None-Match to work.
Implementations§
Source§impl FileBody
impl FileBody
Sourcepub fn path(path: impl Into<PathBuf>) -> Self
pub fn path(path: impl Into<PathBuf>) -> Self
Send the file at path — ASP.NET Core’s PhysicalFile(...).
Sourcepub fn stream(reader: impl AsyncRead + Send + Unpin + 'static) -> Self
pub fn stream(reader: impl AsyncRead + Send + Unpin + 'static) -> Self
Send an async reader of unknown length — ASP.NET Core’s File(Stream, ...).
The response uses chunked transfer encoding and does not serve Range.
If you know the length and can seek, use FileBody::seekable_stream so
clients can resume and cache.
Sourcepub fn seekable_stream(
reader: impl AsyncRead + AsyncSeek + Send + Unpin + 'static,
len: u64,
) -> Self
pub fn seekable_stream( reader: impl AsyncRead + AsyncSeek + Send + Unpin + 'static, len: u64, ) -> Self
Send an async reader of known length that supports seeking.
This is the stream form that keeps every HTTP nicety: exact
Content-Length, Range/206, and — with FileBody::entity_tag —
conditional requests.
Sourcepub fn content_type(self, content_type: impl Into<String>) -> Self
pub fn content_type(self, content_type: impl Into<String>) -> Self
Override the media type instead of deriving it from the extension.
Sourcepub fn download_name(self, file_name: impl Into<String>) -> Self
pub fn download_name(self, file_name: impl Into<String>) -> Self
Send the file as a download named file_name.
Sourcepub fn inline_name(self, file_name: impl Into<String>) -> Self
pub fn inline_name(self, file_name: impl Into<String>) -> Self
Send the file inline under file_name.
Sourcepub fn enable_range_processing(self, enabled: bool) -> Self
pub fn enable_range_processing(self, enabled: bool) -> Self
Enable or disable Range processing.
Sourcepub fn last_modified(self, last_modified: SystemTime) -> Self
pub fn last_modified(self, last_modified: SystemTime) -> Self
Advertise an explicit Last-Modified.
Sourcepub fn entity_tag(self, entity_tag: impl Into<String>) -> Self
pub fn entity_tag(self, entity_tag: impl Into<String>) -> Self
Advertise an explicit ETag.
Include the quotes: "abc123". A strong tag lets clients resume with
If-Range.
Sourcepub fn is_range_capable(&self) -> bool
pub fn is_range_capable(&self) -> bool
Whether this source can seek, and therefore serve byte ranges.