mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
simplify Payload extractor
This commit is contained in:
@ -32,12 +32,4 @@ percent-encoding = "1.0"
|
||||
v_htmlescape = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "0.1.0"
|
||||
#actix-server = { version="0.2", features=["ssl"] }
|
||||
actix-web = { path="..", features=["ssl"] }
|
||||
actix-server = { git = "https://github.com/actix/actix-net.git", features=["ssl"] }
|
||||
actix-http = { git = "https://github.com/actix/actix-http.git", features=["ssl"] }
|
||||
actix-http-test = { git = "https://github.com/actix/actix-http.git", features=["ssl"] }
|
||||
rand = "0.6"
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
|
@ -1,5 +1,4 @@
|
||||
use actix_http::http::header::DispositionType;
|
||||
use actix_web::http::Method;
|
||||
use actix_web::http::{header::DispositionType, Method};
|
||||
use mime;
|
||||
|
||||
/// Describes `StaticFiles` configiration
|
||||
@ -11,11 +10,9 @@ use mime;
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// extern crate mime;
|
||||
/// extern crate actix_web;
|
||||
/// ```rust
|
||||
/// use actix_web::http::header::DispositionType;
|
||||
/// use actix_web::fs::{StaticFileConfig, NamedFile};
|
||||
/// use actix_files::{StaticFileConfig, NamedFile};
|
||||
///
|
||||
/// #[derive(Default)]
|
||||
/// struct MyConfig;
|
||||
@ -29,10 +26,10 @@ use mime;
|
||||
/// let file = NamedFile::open_with_config("foo.txt", MyConfig);
|
||||
/// ```
|
||||
pub trait StaticFileConfig: Default {
|
||||
///Describes mapping for mime type to content disposition header
|
||||
/// Describes mapping for mime type to content disposition header
|
||||
///
|
||||
///By default `IMAGE`, `TEXT` and `VIDEO` are mapped to Inline.
|
||||
///Others are mapped to Attachment
|
||||
/// By default `IMAGE`, `TEXT` and `VIDEO` are mapped to Inline.
|
||||
/// Others are mapped to Attachment
|
||||
fn content_disposition_map(typ: mime::Name) -> DispositionType {
|
||||
match typ {
|
||||
mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
|
||||
@ -40,30 +37,30 @@ pub trait StaticFileConfig: Default {
|
||||
}
|
||||
}
|
||||
|
||||
///Describes whether Actix should attempt to calculate `ETag`
|
||||
/// Describes whether Actix should attempt to calculate `ETag`
|
||||
///
|
||||
///Defaults to `true`
|
||||
/// Defaults to `true`
|
||||
fn is_use_etag() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
///Describes whether Actix should use last modified date of file.
|
||||
/// Describes whether Actix should use last modified date of file.
|
||||
///
|
||||
///Defaults to `true`
|
||||
/// Defaults to `true`
|
||||
fn is_use_last_modifier() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
///Describes allowed methods to access static resources.
|
||||
/// Describes allowed methods to access static resources.
|
||||
///
|
||||
///By default all methods are allowed
|
||||
/// By default all methods are allowed
|
||||
fn is_method_allowed(_method: &Method) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
///Default content disposition as described in
|
||||
///[StaticFileConfig](trait.StaticFileConfig.html)
|
||||
/// Default content disposition as described in
|
||||
/// [StaticFileConfig](trait.StaticFileConfig.html)
|
||||
#[derive(Default)]
|
||||
pub struct DefaultConfig;
|
||||
|
||||
|
@ -11,10 +11,9 @@ use std::os::unix::fs::MetadataExt;
|
||||
use mime;
|
||||
use mime_guess::guess_mime_type;
|
||||
|
||||
use actix_http::error::Error;
|
||||
use actix_http::http::header::{self, ContentDisposition, DispositionParam};
|
||||
use actix_web::http::header::{self, ContentDisposition, DispositionParam};
|
||||
use actix_web::http::{ContentEncoding, Method, StatusCode};
|
||||
use actix_web::{HttpMessage, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse, Responder};
|
||||
|
||||
use crate::config::{DefaultConfig, StaticFileConfig};
|
||||
use crate::range::HttpRange;
|
||||
@ -42,10 +41,8 @@ impl NamedFile {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// extern crate actix_web;
|
||||
///
|
||||
/// use actix_web::fs::NamedFile;
|
||||
/// ```rust
|
||||
/// use actix_files::NamedFile;
|
||||
/// use std::io::{self, Write};
|
||||
/// use std::env;
|
||||
/// use std::fs::File;
|
||||
@ -65,8 +62,8 @@ impl NamedFile {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// use actix_web::fs::NamedFile;
|
||||
/// ```rust
|
||||
/// use actix_files::NamedFile;
|
||||
///
|
||||
/// let file = NamedFile::open("foo.txt");
|
||||
/// ```
|
||||
@ -83,10 +80,8 @@ impl<C: StaticFileConfig> NamedFile<C> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// extern crate actix_web;
|
||||
///
|
||||
/// use actix_web::fs::{DefaultConfig, NamedFile};
|
||||
/// ```rust
|
||||
/// use actix_files::{DefaultConfig, NamedFile};
|
||||
/// use std::io::{self, Write};
|
||||
/// use std::env;
|
||||
/// use std::fs::File;
|
||||
@ -147,8 +142,8 @@ impl<C: StaticFileConfig> NamedFile<C> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// use actix_web::fs::{DefaultConfig, NamedFile};
|
||||
/// ```rust
|
||||
/// use actix_files::{DefaultConfig, NamedFile};
|
||||
///
|
||||
/// let file = NamedFile::open_with_config("foo.txt", DefaultConfig);
|
||||
/// ```
|
||||
@ -169,9 +164,9 @@ impl<C: StaticFileConfig> NamedFile<C> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// ```rust
|
||||
/// # use std::io;
|
||||
/// use actix_web::fs::NamedFile;
|
||||
/// use actix_files::NamedFile;
|
||||
///
|
||||
/// # fn path() -> io::Result<()> {
|
||||
/// let file = NamedFile::open("test.txt")?;
|
||||
|
Reference in New Issue
Block a user