mirror of https://github.com/fafhrd91/actix-web
Applying comments
This commit is contained in:
parent
598858de26
commit
b8f8e62fba
|
@ -22,6 +22,7 @@ actix-web = { path=".." }
|
||||||
actix-http = { git = "https://github.com/actix/actix-http.git" }
|
actix-http = { git = "https://github.com/actix/actix-http.git" }
|
||||||
actix-service = "0.3.3"
|
actix-service = "0.3.3"
|
||||||
|
|
||||||
|
bitflags = "1"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
derive_more = "0.14"
|
derive_more = "0.14"
|
||||||
|
|
|
@ -211,6 +211,7 @@ fn directory_listing(
|
||||||
|
|
||||||
type MimeOverride = Fn(&mime::Name) -> DispositionType;
|
type MimeOverride = Fn(&mime::Name) -> DispositionType;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
/// Static files handling
|
/// Static files handling
|
||||||
///
|
///
|
||||||
/// `Files` service must be registered with `App::service()` method.
|
/// `Files` service must be registered with `App::service()` method.
|
||||||
|
@ -283,7 +284,7 @@ impl<S: 'static> Files<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specifies mime override callback
|
/// Specifies mime override callback
|
||||||
pub fn mime_override<F>(mut self, f: F) -> Self where for<'r, 's> F: Fn(&mime::Name) -> DispositionType + 'static {
|
pub fn mime_override<F>(mut self, f: F) -> Self where F: Fn(&mime::Name) -> DispositionType + 'static {
|
||||||
self.mime_override = Some(Rc::new(f));
|
self.mime_override = Some(Rc::new(f));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -302,7 +303,7 @@ impl<S: 'static> Files<S> {
|
||||||
///
|
///
|
||||||
///Default is true.
|
///Default is true.
|
||||||
pub fn use_etag(mut self, value: bool) -> Self {
|
pub fn use_etag(mut self, value: bool) -> Self {
|
||||||
self.file_flags.use_etag = value;
|
self.file_flags.set(named::Flags::ETAG, value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +312,7 @@ impl<S: 'static> Files<S> {
|
||||||
///
|
///
|
||||||
///Default is true.
|
///Default is true.
|
||||||
pub fn use_last_modified(mut self, value: bool) -> Self {
|
pub fn use_last_modified(mut self, value: bool) -> Self {
|
||||||
self.file_flags.use_last_modified = value;
|
self.file_flags.set(named::Flags::LAST_MD, value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
|
||||||
|
use bitflags::bitflags;
|
||||||
use mime;
|
use mime;
|
||||||
use mime_guess::guess_mime_type;
|
use mime_guess::guess_mime_type;
|
||||||
|
|
||||||
|
@ -17,18 +18,16 @@ use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse, Responder};
|
||||||
use crate::range::HttpRange;
|
use crate::range::HttpRange;
|
||||||
use crate::ChunkedReadFile;
|
use crate::ChunkedReadFile;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
bitflags! {
|
||||||
pub(crate) struct Flags {
|
pub(crate) struct Flags: u32 {
|
||||||
pub use_etag: bool,
|
const ETAG = 0b00000001;
|
||||||
pub use_last_modified: bool,
|
const LAST_MD = 0b00000010;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Flags {
|
impl Default for Flags {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Flags::all()
|
||||||
use_etag: true,
|
|
||||||
use_last_modified: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +187,7 @@ impl NamedFile {
|
||||||
///
|
///
|
||||||
///Default is true.
|
///Default is true.
|
||||||
pub fn use_etag(mut self, value: bool) -> Self {
|
pub fn use_etag(mut self, value: bool) -> Self {
|
||||||
self.flags.use_etag = value;
|
self.flags.set(Flags::ETAG, value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +196,7 @@ impl NamedFile {
|
||||||
///
|
///
|
||||||
///Default is true.
|
///Default is true.
|
||||||
pub fn use_last_modified(mut self, value: bool) -> Self {
|
pub fn use_last_modified(mut self, value: bool) -> Self {
|
||||||
self.flags.use_last_modified = value;
|
self.flags.set(Flags::LAST_MD, value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,8 +317,8 @@ impl Responder for NamedFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let etag = if self.flags.use_etag { self.etag() } else { None };
|
let etag = if self.flags.contains(Flags::ETAG) { self.etag() } else { None };
|
||||||
let last_modified = if self.flags.use_last_modified {
|
let last_modified = if self.flags.contains(Flags::LAST_MD) {
|
||||||
self.last_modified()
|
self.last_modified()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in New Issue