@@ -23,6 +23,7 @@ use actix_web::{
23
23
use bitflags:: bitflags;
24
24
use derive_more:: { Deref , DerefMut } ;
25
25
use futures_core:: future:: LocalBoxFuture ;
26
+ use mime:: Mime ;
26
27
use mime_guess:: from_path;
27
28
28
29
use crate :: { encoding:: equiv_utf8_text, range:: HttpRange } ;
@@ -76,8 +77,8 @@ pub struct NamedFile {
76
77
pub ( crate ) md : Metadata ,
77
78
pub ( crate ) flags : Flags ,
78
79
pub ( crate ) status_code : StatusCode ,
79
- pub ( crate ) content_type : mime :: Mime ,
80
- pub ( crate ) content_disposition : header :: ContentDisposition ,
80
+ pub ( crate ) content_type : Mime ,
81
+ pub ( crate ) content_disposition : ContentDisposition ,
81
82
pub ( crate ) encoding : Option < ContentEncoding > ,
82
83
}
83
84
@@ -238,13 +239,13 @@ impl NamedFile {
238
239
Self :: from_file ( file, path)
239
240
}
240
241
241
- /// Returns reference to the underlying `File` object.
242
+ /// Returns reference to the underlying file object.
242
243
#[ inline]
243
244
pub fn file ( & self ) -> & File {
244
245
& self . file
245
246
}
246
247
247
- /// Retrieve the path of this file.
248
+ /// Returns the filesystem path to this file.
248
249
///
249
250
/// # Examples
250
251
/// ```
@@ -262,6 +263,48 @@ impl NamedFile {
262
263
self . path . as_path ( )
263
264
}
264
265
266
+ /// Returns the time the file was last modified.
267
+ ///
268
+ /// Returns `None` only on unsupported platforms; see [`std::fs::Metadata::modified()`].
269
+ /// Therefore, it is usually safe to unwrap this.
270
+ #[ inline]
271
+ pub fn modified ( & self ) -> Option < SystemTime > {
272
+ self . modified
273
+ }
274
+
275
+ /// Returns the filesystem metadata associated with this file.
276
+ #[ inline]
277
+ pub fn metadata ( & self ) -> & Metadata {
278
+ & self . md
279
+ }
280
+
281
+ /// Returns the `Content-Type` header that will be used when serving this file.
282
+ #[ inline]
283
+ pub fn content_type ( & self ) -> & Mime {
284
+ & self . content_type
285
+ }
286
+
287
+ /// Returns the `Content-Disposition` that will be used when serving this file.
288
+ #[ inline]
289
+ pub fn content_disposition ( & self ) -> & ContentDisposition {
290
+ & self . content_disposition
291
+ }
292
+
293
+ /// Returns the `Content-Encoding` that will be used when serving this file.
294
+ ///
295
+ /// A return value of `None` indicates that the content is not already using a compressed
296
+ /// representation and may be subject to compression downstream.
297
+ #[ inline]
298
+ pub fn content_encoding ( & self ) -> Option < ContentEncoding > {
299
+ self . encoding
300
+ }
301
+
302
+ /// Returns the status code for serving this file.
303
+ #[ inline]
304
+ pub fn status_code ( & self ) -> & StatusCode {
305
+ & self . status_code
306
+ }
307
+
265
308
/// Set response **Status Code**
266
309
pub fn set_status_code ( mut self , status : StatusCode ) -> Self {
267
310
self . status_code = status;
@@ -271,7 +314,7 @@ impl NamedFile {
271
314
/// Set the MIME Content-Type for serving this file. By default the Content-Type is inferred
272
315
/// from the filename extension.
273
316
#[ inline]
274
- pub fn set_content_type ( mut self , mime_type : mime :: Mime ) -> Self {
317
+ pub fn set_content_type ( mut self , mime_type : Mime ) -> Self {
275
318
self . content_type = mime_type;
276
319
self
277
320
}
@@ -284,7 +327,7 @@ impl NamedFile {
284
327
/// filename is taken from the path provided in the `open` method after converting it to UTF-8
285
328
/// (using `to_string_lossy`).
286
329
#[ inline]
287
- pub fn set_content_disposition ( mut self , cd : header :: ContentDisposition ) -> Self {
330
+ pub fn set_content_disposition ( mut self , cd : ContentDisposition ) -> Self {
288
331
self . content_disposition = cd;
289
332
self . flags . insert ( Flags :: CONTENT_DISPOSITION ) ;
290
333
self
0 commit comments