1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

Merge branch 'master' into master

This commit is contained in:
Nikolay Kim 2019-06-15 22:21:39 +06:00 committed by GitHub
commit 382d4ca216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 156 additions and 38 deletions

View File

@ -10,14 +10,20 @@
### Changes ### Changes
* Disable default feature `secure-cookies`. * Move cors middleware to `actix-cors` crate.
* Move identity middleware to `actix-identity` crate. * Move identity middleware to `actix-identity` crate.
* Disable default feature `secure-cookies`.
* Allow to test an app that uses async actors #897 * Allow to test an app that uses async actors #897
* Re-apply patch from #637 #894 * Re-apply patch from #637 #894
### Fixed
* HttpRequest::url_for is broken with nested scopes #915
## [1.0.0] - 2019-06-05 ## [1.0.0] - 2019-06-05

View File

@ -31,6 +31,7 @@ members = [
".", ".",
"awc", "awc",
"actix-http", "actix-http",
"actix-cors",
"actix-files", "actix-files",
"actix-framed", "actix-framed",
"actix-session", "actix-session",
@ -42,7 +43,7 @@ members = [
] ]
[features] [features]
default = ["brotli", "flate2-zlib", "client", "fail"] default = ["brotli", "flate2-zlib", "client", "fail", "depracated"]
# http client # http client
client = ["awc"] client = ["awc"]
@ -67,6 +68,9 @@ ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
# rustls # rustls
rust-tls = ["rustls", "actix-server/rust-tls"] rust-tls = ["rustls", "actix-server/rust-tls"]
# deprecated middlewares
depracated = ["actix-cors", "actix-identity"]
[dependencies] [dependencies]
actix-codec = "0.1.2" actix-codec = "0.1.2"
actix-service = "0.4.0" actix-service = "0.4.0"
@ -80,11 +84,15 @@ actix-server-config = "0.1.1"
actix-threadpool = "0.1.1" actix-threadpool = "0.1.1"
awc = { version = "0.2.1", optional = true } awc = { version = "0.2.1", optional = true }
# deprecated middlewares
actix-cors = { version = "0.1.0", optional = true }
actix-identity = { version = "0.1.0", optional = true }
bytes = "0.4" bytes = "0.4"
derive_more = "0.14" derive_more = "0.14"
encoding = "0.2" encoding = "0.2"
futures = "0.1.25" futures = "0.1.25"
hashbrown = "0.3.0" hashbrown = "0.3.1"
log = "0.4" log = "0.4"
mime = "0.3" mime = "0.3"
net2 = "0.2.33" net2 = "0.2.33"
@ -101,10 +109,9 @@ openssl = { version="0.10", optional = true }
rustls = { version = "0.15", optional = true } rustls = { version = "0.15", optional = true }
[dev-dependencies] [dev-dependencies]
actix = { version = "0.8.3" }
actix-http = { version = "0.2.3", features=["ssl", "brotli", "flate2-zlib"] } actix-http = { version = "0.2.3", features=["ssl", "brotli", "flate2-zlib"] }
actix-http-test = { version = "0.2.0", features=["ssl"] } actix-http-test = { version = "0.2.0", features=["ssl"] }
actix-files = "0.1.1"
actix = { version = "0.8.3" }
rand = "0.6" rand = "0.6"
env_logger = "0.6" env_logger = "0.6"
serde_derive = "1.0" serde_derive = "1.0"
@ -118,7 +125,7 @@ opt-level = 3
codegen-units = 1 codegen-units = 1
[patch.crates-io] [patch.crates-io]
actix-web = { path = "." } # actix-web = { path = "." }
actix-http = { path = "actix-http" } actix-http = { path = "actix-http" }
actix-http-test = { path = "test-server" } actix-http-test = { path = "test-server" }
actix-web-codegen = { path = "actix-web-codegen" } actix-web-codegen = { path = "actix-web-codegen" }

View File

@ -1,5 +1,19 @@
## 1.0.1 ## 1.0.1
* Cors middleware has been moved to `actix-cors` crate
instead of
```rust
use actix_web::middleware::cors::Cors;
```
use
```rust
use actix_cors::Cors;
```
* Identity middleware has been moved to `actix-identity` crate * Identity middleware has been moved to `actix-identity` crate
instead of instead of

5
actix-cors/CHANGES.md Normal file
View File

@ -0,0 +1,5 @@
# Changes
## [0.1.0] - 2019-06-15
* Move cors middleware to separate crate

23
actix-cors/Cargo.toml Normal file
View File

@ -0,0 +1,23 @@
[package]
name = "actix-cors"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Cross-origin resource sharing (CORS) for Actix applications."
readme = "README.md"
keywords = ["web", "framework"]
homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git"
documentation = "https://docs.rs/actix-cors/"
license = "MIT/Apache-2.0"
edition = "2018"
#workspace = ".."
[lib]
name = "actix_cors"
path = "src/lib.rs"
[dependencies]
actix-web = "1.0.0"
actix-service = "0.4.0"
derive_more = "0.14.1"
futures = "0.1.25"

1
actix-cors/LICENSE-APACHE Symbolic link
View File

@ -0,0 +1 @@
../LICENSE-APACHE

1
actix-cors/LICENSE-MIT Symbolic link
View File

@ -0,0 +1 @@
../LICENSE-MIT

9
actix-cors/README.md Normal file
View File

@ -0,0 +1,9 @@
# Identity service for actix web framework [![Build Status](https://travis-ci.org/actix/actix-web.svg?branch=master)](https://travis-ci.org/actix/actix-web) [![codecov](https://codecov.io/gh/actix/actix-web/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-web) [![crates.io](https://meritbadge.herokuapp.com/actix-identity)](https://crates.io/crates/actix-identity) [![Join the chat at https://gitter.im/actix/actix](https://badges.gitter.im/actix/actix.svg)](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
## Documentation & community resources
* [User Guide](https://actix.rs/docs/)
* [API Documentation](https://docs.rs/actix-identity/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-session](https://crates.io/crates/actix-identity)
* Minimum supported Rust version: 1.34 or later

View File

@ -7,7 +7,7 @@
//! # Example //! # Example
//! //!
//! ```rust //! ```rust
//! use actix_web::middleware::cors::Cors; //! use actix_cors::Cors;
//! use actix_web::{http, web, App, HttpRequest, HttpResponse, HttpServer}; //! use actix_web::{http, web, App, HttpRequest, HttpResponse, HttpServer};
//! //!
//! fn index(req: HttpRequest) -> &'static str { //! fn index(req: HttpRequest) -> &'static str {
@ -42,17 +42,15 @@ use std::iter::FromIterator;
use std::rc::Rc; use std::rc::Rc;
use actix_service::{IntoTransform, Service, Transform}; use actix_service::{IntoTransform, Service, Transform};
use actix_web::dev::{RequestHead, ServiceRequest, ServiceResponse};
use actix_web::error::{Error, ResponseError, Result};
use actix_web::http::header::{self, HeaderName, HeaderValue};
use actix_web::http::{self, HttpTryFrom, Method, StatusCode, Uri};
use actix_web::HttpResponse;
use derive_more::Display; use derive_more::Display;
use futures::future::{ok, Either, Future, FutureResult}; use futures::future::{ok, Either, Future, FutureResult};
use futures::Poll; use futures::Poll;
use crate::dev::RequestHead;
use crate::error::{Error, ResponseError, Result};
use crate::http::header::{self, HeaderName, HeaderValue};
use crate::http::{self, HttpTryFrom, Method, StatusCode, Uri};
use crate::service::{ServiceRequest, ServiceResponse};
use crate::HttpResponse;
/// A set of errors that can occur during processing CORS /// A set of errors that can occur during processing CORS
#[derive(Debug, Display)] #[derive(Debug, Display)]
pub enum CorsError { pub enum CorsError {
@ -152,11 +150,11 @@ impl<T> AllOrSome<T> {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use actix_cors::Cors;
/// use actix_web::http::header; /// use actix_web::http::header;
/// use actix_web::middleware::cors;
/// ///
/// # fn main() { /// # fn main() {
/// let cors = cors::Cors::new() /// let cors = Cors::new()
/// .allowed_origin("https://www.rust-lang.org/") /// .allowed_origin("https://www.rust-lang.org/")
/// .allowed_methods(vec!["GET", "POST"]) /// .allowed_methods(vec!["GET", "POST"])
/// .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT]) /// .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
@ -806,9 +804,9 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use actix_service::{IntoService, Transform}; use actix_service::{IntoService, Transform};
use actix_web::test::{self, block_on, TestRequest};
use super::*; use super::*;
use crate::test::{self, block_on, TestRequest};
impl Cors { impl Cors {
fn finish<F, S, B>(self, srv: F) -> CorsMiddleware<S> fn finish<F, S, B>(self, srv: F) -> CorsMiddleware<S>

View File

@ -1,8 +1,10 @@
# Changes # Changes
## [0.1.2] - 2019-06-06 ## [0.1.2] - 2019-06-13
* Fix ring dependency from actix-web default features for #741. * Content-Length is 0 for NamedFile HEAD request #914
* Fix ring dependency from actix-web default features for #741
## [0.1.1] - 2019-06-01 ## [0.1.1] - 2019-06-01

View File

@ -926,6 +926,29 @@ mod tests {
assert_eq!(bytes.freeze(), data); assert_eq!(bytes.freeze(), data);
} }
#[test]
fn test_head_content_length_headers() {
let mut srv = test::init_service(
App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
);
// Valid range header
let request = TestRequest::default()
.method(Method::HEAD)
.uri("/t%65st/tests/test.binary")
.to_request();
let response = test::call_service(&mut srv, request);
let contentlength = response
.headers()
.get(header::CONTENT_LENGTH)
.unwrap()
.to_str()
.unwrap();
assert_eq!(contentlength, "100");
}
#[test] #[test]
fn test_static_files_with_spaces() { fn test_static_files_with_spaces() {
let mut srv = test::init_service( let mut srv = test::init_service(

View File

@ -422,20 +422,16 @@ impl Responder for NamedFile {
return Ok(resp.status(StatusCode::NOT_MODIFIED).finish()); return Ok(resp.status(StatusCode::NOT_MODIFIED).finish());
} }
if *req.method() == Method::HEAD { let reader = ChunkedReadFile {
Ok(resp.finish()) offset,
} else { size: length,
let reader = ChunkedReadFile { file: Some(self.file),
offset, fut: None,
size: length, counter: 0,
file: Some(self.file), };
fut: None, if offset != 0 || length != self.md.len() {
counter: 0, return Ok(resp.status(StatusCode::PARTIAL_CONTENT).streaming(reader));
}; };
if offset != 0 || length != self.md.len() { Ok(resp.body(SizedStream::new(length, reader)))
return Ok(resp.status(StatusCode::PARTIAL_CONTENT).streaming(reader));
};
Ok(resp.body(SizedStream::new(length, reader)))
}
} }
} }

View File

@ -225,7 +225,6 @@ where
/// It is also possible to use static files as default service. /// It is also possible to use static files as default service.
/// ///
/// ```rust /// ```rust
/// use actix_files::Files;
/// use actix_web::{web, App, HttpResponse}; /// use actix_web::{web, App, HttpResponse};
/// ///
/// fn main() { /// fn main() {
@ -233,7 +232,7 @@ where
/// .service( /// .service(
/// web::resource("/index.html").to(|| HttpResponse::Ok())) /// web::resource("/index.html").to(|| HttpResponse::Ok()))
/// .default_service( /// .default_service(
/// Files::new("", "./static") /// web::to(|| HttpResponse::NotFound())
/// ); /// );
/// } /// }
/// ``` /// ```

View File

@ -2,7 +2,6 @@
mod compress; mod compress;
pub use self::compress::{BodyEncoding, Compress}; pub use self::compress::{BodyEncoding, Compress};
pub mod cors;
mod defaultheaders; mod defaultheaders;
pub mod errhandlers; pub mod errhandlers;
mod logger; mod logger;
@ -11,3 +10,17 @@ mod normalize;
pub use self::defaultheaders::DefaultHeaders; pub use self::defaultheaders::DefaultHeaders;
pub use self::logger::Logger; pub use self::logger::Logger;
pub use self::normalize::NormalizePath; pub use self::normalize::NormalizePath;
#[cfg(feature = "deprecated")]
#[deprecated(
since = "1.0.1",
note = "please use `actix_cors` instead. support will be removed in actix-web 1.0.2"
)]
pub use actix_cors as cors;
#[cfg(feature = "deprecated")]
#[deprecated(
since = "1.0.1",
note = "please use `actix_identity` instead. support will be removed in actix-web 1.0.2"
)]
pub use actix_identity as identity;

View File

@ -38,7 +38,8 @@ impl ResourceMap {
pub(crate) fn finish(&self, current: Rc<ResourceMap>) { pub(crate) fn finish(&self, current: Rc<ResourceMap>) {
for (_, nested) in &self.patterns { for (_, nested) in &self.patterns {
if let Some(ref nested) = nested { if let Some(ref nested) = nested {
*nested.parent.borrow_mut() = Some(current.clone()) *nested.parent.borrow_mut() = Some(current.clone());
nested.finish(nested.clone());
} }
} }
} }

View File

@ -1135,4 +1135,24 @@ mod tests {
let body = read_body(resp); let body = read_body(resp);
assert_eq!(body, &b"https://youtube.com/watch/xxxxxx"[..]); assert_eq!(body, &b"https://youtube.com/watch/xxxxxx"[..]);
} }
#[test]
fn test_url_for_nested() {
let mut srv = init_service(App::new().service(web::scope("/a").service(
web::scope("/b").service(web::resource("/c/{stuff}").name("c").route(
web::get().to(|req: HttpRequest| {
HttpResponse::Ok()
.body(format!("{}", req.url_for("c", &["12345"]).unwrap()))
}),
)),
)));
let req = TestRequest::with_uri("/a/b/c/test").to_request();
let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::OK);
let body = read_body(resp);
assert_eq!(
body,
Bytes::from_static(b"http://localhost:8080/a/b/c/12345")
);
}
} }