diff --git a/CHANGES.md b/CHANGES.md index 5f3d519a7..1f34b7977 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,10 +10,12 @@ ### Changes -* Disable default feature `secure-cookies`. +* Move cors middleware to `actix-cors` crate. * Move identity middleware to `actix-identity` crate. +* Disable default feature `secure-cookies`. + * Allow to test an app that uses async actors #897 * Re-apply patch from #637 #894 diff --git a/Cargo.toml b/Cargo.toml index 871ed7451..56a42bf97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ members = [ ".", "awc", "actix-http", + "actix-cors", "actix-files", "actix-framed", "actix-session", @@ -80,6 +81,8 @@ actix-server-config = "0.1.1" actix-threadpool = "0.1.1" awc = { version = "0.2.1", optional = true } +# actix-cors = "0.1."{ path="./actix-cors" } + bytes = "0.4" derive_more = "0.14" encoding = "0.2" diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md new file mode 100644 index 000000000..1e842f37e --- /dev/null +++ b/actix-cors/CHANGES.md @@ -0,0 +1,5 @@ +# Changes + +## [0.1.0] - 2019-06-15 + +* Move cors middleware to separate crate diff --git a/actix-cors/Cargo.toml b/actix-cors/Cargo.toml new file mode 100644 index 000000000..a62cc664d --- /dev/null +++ b/actix-cors/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "actix-cors" +version = "0.1.0" +authors = ["Nikolay Kim "] +description = "Cross-origin resource sharing (CORS) for Actix applications." +readme = "README.md" +keywords = ["http", "web", "framework", "async", "futures"] +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" + +[dev-dependencies] +actix-rt = "0.2.2" +#actix-http = "0.2.3" +#bytes = "0.4" \ No newline at end of file diff --git a/actix-cors/LICENSE-APACHE b/actix-cors/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/actix-cors/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/actix-cors/LICENSE-MIT b/actix-cors/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/actix-cors/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/actix-cors/README.md b/actix-cors/README.md new file mode 100644 index 000000000..60b615c76 --- /dev/null +++ b/actix-cors/README.md @@ -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 diff --git a/src/middleware/cors.rs b/actix-cors/src/lib.rs similarity index 98% rename from src/middleware/cors.rs rename to actix-cors/src/lib.rs index f731f49bd..5d0d013e3 100644 --- a/src/middleware/cors.rs +++ b/actix-cors/src/lib.rs @@ -7,7 +7,7 @@ //! # Example //! //! ```rust -//! use actix_web::middleware::cors::Cors; +//! use actix_cors::Cors; //! use actix_web::{http, web, App, HttpRequest, HttpResponse, HttpServer}; //! //! fn index(req: HttpRequest) -> &'static str { @@ -42,17 +42,15 @@ use std::iter::FromIterator; use std::rc::Rc; 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 futures::future::{ok, Either, Future, FutureResult}; 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 #[derive(Debug, Display)] pub enum CorsError { @@ -152,11 +150,11 @@ impl AllOrSome { /// # Example /// /// ```rust +/// use actix_cors::Cors; /// use actix_web::http::header; -/// use actix_web::middleware::cors; /// /// # fn main() { -/// let cors = cors::Cors::new() +/// let cors = Cors::new() /// .allowed_origin("https://www.rust-lang.org/") /// .allowed_methods(vec!["GET", "POST"]) /// .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT]) @@ -806,9 +804,9 @@ where #[cfg(test)] mod tests { use actix_service::{IntoService, Transform}; + use actix_web::test::{self, block_on, TestRequest}; use super::*; - use crate::test::{self, block_on, TestRequest}; impl Cors { fn finish(self, srv: F) -> CorsMiddleware diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 99c6cb457..f0b90e773 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -2,7 +2,6 @@ mod compress; pub use self::compress::{BodyEncoding, Compress}; -pub mod cors; mod defaultheaders; pub mod errhandlers; mod logger; @@ -11,3 +10,6 @@ mod normalize; pub use self::defaultheaders::DefaultHeaders; pub use self::logger::Logger; pub use self::normalize::NormalizePath; + +// +// use actix_cors as cors;