From 815e34f32ded77f73145fb0373a060b22636f689 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 7 Apr 2019 23:39:45 -0700 Subject: [PATCH] upgrade to alpha4 --- actix_redis/Cargo.toml | 2 +- actix_todo/Cargo.toml | 6 +-- async_db/Cargo.toml | 2 +- async_ex1/Cargo.toml | 2 +- basics/Cargo.toml | 6 +-- cookie-auth/Cargo.toml | 2 +- cookie-session/Cargo.toml | 4 +- diesel/Cargo.toml | 2 +- error_handling/Cargo.toml | 2 +- form/Cargo.toml | 2 +- hello-world/Cargo.toml | 2 +- http-full-proxy/Cargo.toml | 2 +- http-proxy/Cargo.toml | 2 +- json/Cargo.toml | 2 +- juniper/Cargo.toml | 2 +- middleware/Cargo.toml | 4 +- multipart/Cargo.toml | 3 +- multipart/src/main.rs | 65 ++++++++++++++++++-------- protobuf/Cargo.toml | 2 +- r2d2/Cargo.toml | 2 +- redis-session/Cargo.toml | 4 +- rustls/Cargo.toml | 4 +- simple-auth-server/Cargo.toml | 4 +- simple-auth-server/src/auth_handler.rs | 8 ++-- state/Cargo.toml | 2 +- static_index/Cargo.toml | 4 +- template_askama/Cargo.toml | 3 +- template_tera/Cargo.toml | 2 +- template_yarte/Cargo.toml | 4 +- tls/Cargo.toml | 2 +- web-cors/backend/Cargo.toml | 2 +- websocket-chat/Cargo.toml | 6 +-- websocket-tcp-chat/Cargo.toml | 4 +- websocket/Cargo.toml | 4 +- 34 files changed, 97 insertions(+), 72 deletions(-) diff --git a/actix_redis/Cargo.toml b/actix_redis/Cargo.toml index 38a2daa..7229262 100644 --- a/actix_redis/Cargo.toml +++ b/actix_redis/Cargo.toml @@ -7,7 +7,7 @@ workspace = ".." [dependencies] actix = "0.8.0-alpha.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" actix-redis = { git="https://github.com/actix/actix-redis.git" } futures = "0.1.23" redis-async = "0.4.0" diff --git a/actix_todo/Cargo.toml b/actix_todo/Cargo.toml index e1e0925..6e3acb9 100644 --- a/actix_todo/Cargo.toml +++ b/actix_todo/Cargo.toml @@ -6,9 +6,9 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" -actix-session = "0.1.0-alpha.3" +actix-web = "1.0.0-alpha.4" +actix-files = "0.1.0-alpha.4" +actix-session = "0.1.0-alpha.4" dotenv = "0.13.0" env_logger = "0.5.10" futures = "0.1.22" diff --git a/async_db/Cargo.toml b/async_db/Cargo.toml index 70e2962..8063ead 100644 --- a/async_db/Cargo.toml +++ b/async_db/Cargo.toml @@ -7,7 +7,7 @@ workspace = ".." [dependencies] actix-rt = "0.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" dotenv = "0.10" env_logger = "0.5" diff --git a/async_ex1/Cargo.toml b/async_ex1/Cargo.toml index 69bcdc0..a87eec9 100644 --- a/async_ex1/Cargo.toml +++ b/async_ex1/Cargo.toml @@ -7,7 +7,7 @@ workspace = ".." [dependencies] actix-rt = "0.2" -actix-web = { version="1.0.0-alpha.3", features=["ssl"] } +actix-web = { version="1.0.0-alpha.4", features=["ssl"] } futures = "0.1" serde = "1.0.43" diff --git a/basics/Cargo.toml b/basics/Cargo.toml index 93ad360..e16db24 100644 --- a/basics/Cargo.toml +++ b/basics/Cargo.toml @@ -7,9 +7,9 @@ edition = "2018" [dependencies] actix-rt = "0.2" -actix-web = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" -actix-session = "0.1.0-alpha.3" +actix-web = "1.0.0-alpha.4" +actix-files = "0.1.0-alpha.4" +actix-session = "0.1.0-alpha.4" futures = "0.1.25" env_logger = "0.5" diff --git a/cookie-auth/Cargo.toml b/cookie-auth/Cargo.toml index ef75a84..66d02b6 100644 --- a/cookie-auth/Cargo.toml +++ b/cookie-auth/Cargo.toml @@ -6,5 +6,5 @@ edition = "2018" workspace = ".." [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" env_logger = "0.6" diff --git a/cookie-session/Cargo.toml b/cookie-session/Cargo.toml index 466e2c6..2a76fa6 100644 --- a/cookie-session/Cargo.toml +++ b/cookie-session/Cargo.toml @@ -6,8 +6,8 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" -actix-session = "0.1.0-alpha.3" +actix-web = "1.0.0-alpha.4" +actix-session = "0.1.0-alpha.4" futures = "0.1" time = "0.1" diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 2064383..5c534ce 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -6,7 +6,7 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" bytes = "0.4" env_logger = "0.6" diff --git a/error_handling/Cargo.toml b/error_handling/Cargo.toml index 71e013a..9e0b003 100644 --- a/error_handling/Cargo.toml +++ b/error_handling/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" workspace = ".." [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" derive_more = "0.14.0" futures = "0.1.23" diff --git a/form/Cargo.toml b/form/Cargo.toml index f8386ad..1f98368 100644 --- a/form/Cargo.toml +++ b/form/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" workspace = ".." [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" serde = "1.0" serde_derive = "1.0" diff --git a/hello-world/Cargo.toml b/hello-world/Cargo.toml index 879693a..733faa5 100644 --- a/hello-world/Cargo.toml +++ b/hello-world/Cargo.toml @@ -6,5 +6,5 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" env_logger = "0.6" diff --git a/http-full-proxy/Cargo.toml b/http-full-proxy/Cargo.toml index 0030fad..593b1a5 100644 --- a/http-full-proxy/Cargo.toml +++ b/http-full-proxy/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] actix-rt = "0.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" clap = "2.32.0" futures = "0.1.25" diff --git a/http-proxy/Cargo.toml b/http-proxy/Cargo.toml index cbca064..9afc29e 100644 --- a/http-proxy/Cargo.toml +++ b/http-proxy/Cargo.toml @@ -15,7 +15,7 @@ path = "src/server.rs" [dependencies] actix-rt = "0.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" env_logger = "0.5" futures = "0.1" diff --git a/json/Cargo.toml b/json/Cargo.toml index 3cd3d86..eab6ddb 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -6,7 +6,7 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" bytes = "0.4" futures = "0.1" diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index e4161a0..71f410c 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -6,7 +6,7 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" env_logger = "0.6" futures = "0.1" serde = "1.0" diff --git a/middleware/Cargo.toml b/middleware/Cargo.toml index 33fe3a3..e6d9cc3 100644 --- a/middleware/Cargo.toml +++ b/middleware/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" workspace = ".." [dependencies] -actix-service = "0.3.3" -actix-web = "1.0.0-alpha.3" +actix-service = "0.3.6" +actix-web = "1.0.0-alpha.4" futures = "0.1.25" env_logger = "0.6" \ No newline at end of file diff --git a/multipart/Cargo.toml b/multipart/Cargo.toml index 1246fdd..a622393 100644 --- a/multipart/Cargo.toml +++ b/multipart/Cargo.toml @@ -10,7 +10,8 @@ name = "multipart" path = "src/main.rs" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" +actix-multipart = { git="https://github.com/actix/actix-web.git" } env_logger = "0.6" futures = "0.1.25" diff --git a/multipart/src/main.rs b/multipart/src/main.rs index 5ff785c..73d111f 100644 --- a/multipart/src/main.rs +++ b/multipart/src/main.rs @@ -1,16 +1,18 @@ use std::cell::Cell; -use std::fs; +use std::fs::{self, File}; use std::io::Write; +use std::path::Path; +use actix_multipart::{Field, Item, Multipart, MultipartError}; use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer}; -use futures::future::{err, Either}; +use futures::future::{err, ok, Either}; use futures::{Future, Stream}; pub struct AppState { pub counter: Cell, } -pub fn save_file(field: web::MultipartField) -> impl Future { +pub fn save_file(field: Field) -> impl Future { let file_path_string = "upload.png"; let mut file = match fs::File::create(file_path_string) { Ok(file) => file, @@ -24,7 +26,7 @@ pub fn save_file(field: web::MultipartField) -> impl Future impl Future Box> { +pub fn handle_multipart_item(item: Item) -> Box> { match item { - web::MultipartItem::Field(field) => Box::new(save_file(field).into_stream()), - web::MultipartItem::Nested(mp) => Box::new( + Item::Field(field) => Box::new(save_file(field).into_stream()), + Item::Nested(mp) => Box::new( mp.map_err(error::ErrorInternalServerError) .map(handle_multipart_item) .flatten(), @@ -48,21 +48,46 @@ pub fn handle_multipart_item( } pub fn upload( - multipart: web::Multipart, + multipart: Multipart, counter: web::Data>, ) -> impl Future { - counter.set(counter.get() + 1); - println!("{:?}", counter.get()); - multipart - .map_err(error::ErrorInternalServerError) - .map(handle_multipart_item) - .flatten() + .from_err::() + .take(1) .collect() - .map(|sizes| HttpResponse::Ok().json(sizes)) - .map_err(|e| { - println!("failed: {}", e); - e + .map(|v| v.into_iter().next().expect("wat")) + .and_then(|item| match item { + Item::Field(field) => { + if let Some(disp) = field.content_disposition() { + if let Some(disp_fn) = disp.get_filename() { + if let Some(ext) = Path::new(&disp_fn).extension() { + let fname = format!("{}.{}", 10, ext.to_string_lossy()); + let pth = Path::new("./").join(&fname); + if let Ok(mut ff) = File::create(&pth) { + return Either::A( + field + .from_err::() + .map(move |c| ff.write_all(&c)) + .fold((), |_, _| Ok::<_, Error>(())) + //.finish() + .and_then(move |_| { + ok(HttpResponse::Created().body(format!( + "{{\"path\": \"{}\"}}", + fname + ))) + }) + .or_else(|_| { + ok(HttpResponse::InternalServerError() + .finish()) + }), + ); + } + } + } + } + Either::B(ok(HttpResponse::BadRequest().finish())) + } + Item::Nested(_) => Either::B(ok(HttpResponse::BadRequest().finish())), }) } diff --git a/protobuf/Cargo.toml b/protobuf/Cargo.toml index d71ec8a..a20640b 100644 --- a/protobuf/Cargo.toml +++ b/protobuf/Cargo.toml @@ -13,4 +13,4 @@ derive_more = "0.14" prost = "0.2.0" prost-derive = "0.2.0" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" diff --git a/r2d2/Cargo.toml b/r2d2/Cargo.toml index a911f39..86e70e3 100644 --- a/r2d2/Cargo.toml +++ b/r2d2/Cargo.toml @@ -7,7 +7,7 @@ workspace = ".." [dependencies] actix-rt = "0.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" futures = "0.1" env_logger = "0.6" diff --git a/redis-session/Cargo.toml b/redis-session/Cargo.toml index 44b567c..fc347f8 100644 --- a/redis-session/Cargo.toml +++ b/redis-session/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] actix = "0.8.0-alpha.2" -actix-web = "1.0.0-alpha.3" -actix-session = "0.1.0-alpha.3" +actix-web = "1.0.0-alpha.4" +actix-session = "0.1.0-alpha.4" actix-redis = { git = "https://github.com/actix/actix-redis.git", features = ["web"] } env_logger = "0.6" diff --git a/rustls/Cargo.toml b/rustls/Cargo.toml index a1f3025..6abb015 100644 --- a/rustls/Cargo.toml +++ b/rustls/Cargo.toml @@ -12,5 +12,5 @@ path = "src/main.rs" [dependencies] env_logger = "0.5" rustls = "0.15" -actix-web = { version = "1.0.0-alpha.3", features=["rust-tls"] } -actix-files = "0.1.0-alpha.2" +actix-web = { version = "1.0.0-alpha.4", features=["rust-tls"] } +actix-files = "0.1.0-alpha.4" diff --git a/simple-auth-server/Cargo.toml b/simple-auth-server/Cargo.toml index 6bd3a66..fe59c1f 100644 --- a/simple-auth-server/Cargo.toml +++ b/simple-auth-server/Cargo.toml @@ -8,8 +8,8 @@ workspace = ".." [dependencies] actix = { version = "0.8.0-alpha.2", features = ["http"] } actix-rt = "0.2.2" -actix-web = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" +actix-web = "1.0.0-alpha.4" +actix-files = "0.1.0-alpha.4" bcrypt = "0.2.1" chrono = { version = "0.4.6", features = ["serde"] } diff --git a/simple-auth-server/src/auth_handler.rs b/simple-auth-server/src/auth_handler.rs index 13eb147..0a433e5 100644 --- a/simple-auth-server/src/auth_handler.rs +++ b/simple-auth-server/src/auth_handler.rs @@ -1,6 +1,6 @@ use actix::{Handler, Message}; -use actix_web::{dev::ServiceFromRequest, Error}; -use actix_web::{middleware::identity::Identity, FromRequest, HttpRequest}; +use actix_web::{dev::Payload, Error, HttpRequest}; +use actix_web::{middleware::identity::Identity, FromRequest}; use bcrypt::verify; use diesel::prelude::*; @@ -50,8 +50,8 @@ impl

FromRequest

for LoggedUser { type Error = Error; type Future = Result; - fn from_request(req: &mut ServiceFromRequest

) -> Self::Future { - if let Some(identity) = Identity::from_request(req)?.identity() { + fn from_request(req: &HttpRequest, pl: &mut Payload

) -> Self::Future { + if let Some(identity) = Identity::from_request(req, pl)?.identity() { let user: SlimUser = decode_token(&identity)?; return Ok(user as LoggedUser); } diff --git a/state/Cargo.toml b/state/Cargo.toml index f13f4f2..894d49d 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -6,6 +6,6 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" futures = "0.1.25" env_logger = "0.6" diff --git a/static_index/Cargo.toml b/static_index/Cargo.toml index a7e8847..196e112 100644 --- a/static_index/Cargo.toml +++ b/static_index/Cargo.toml @@ -9,5 +9,5 @@ edition = "2018" futures = "0.1" env_logger = "0.5" -actix-web = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" +actix-web = "1.0.0-alpha.4" +actix-files = "0.1.0-alpha.4" diff --git a/template_askama/Cargo.toml b/template_askama/Cargo.toml index 6f53dfa..09fc9e8 100644 --- a/template_askama/Cargo.toml +++ b/template_askama/Cargo.toml @@ -6,8 +6,7 @@ workspace = ".." edition = "2018" [dependencies] -#askama = { version = "0.8", features = ["with-actix-web"] } -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" env_logger = "0.6" askama = "0.8" diff --git a/template_tera/Cargo.toml b/template_tera/Cargo.toml index bb4df6b..700f4f8 100644 --- a/template_tera/Cargo.toml +++ b/template_tera/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" [dependencies] env_logger = "0.6" tera = "0.11" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" diff --git a/template_yarte/Cargo.toml b/template_yarte/Cargo.toml index 9ef98b5..f7645bc 100644 --- a/template_yarte/Cargo.toml +++ b/template_yarte/Cargo.toml @@ -12,7 +12,7 @@ env_logger = "0.6" yarte = { version = "0.2", features=["with-actix-web"] } -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" [build-dependencies] yarte = { version = "0.2", features=["with-actix-web"] } @@ -20,4 +20,4 @@ yarte = { version = "0.2", features=["with-actix-web"] } [dev-dependencies] bytes = "0.4" actix-http-test = "0.1.0-alpha.3" -actix-http = "0.1.0-alpha.3" +actix-http = "0.1.0-alpha.4" diff --git a/tls/Cargo.toml b/tls/Cargo.toml index c1ef14a..65302c6 100644 --- a/tls/Cargo.toml +++ b/tls/Cargo.toml @@ -11,6 +11,6 @@ path = "src/main.rs" [dependencies] actix-rt = "0.2" -actix-web = { version="1.0.0-alpha.3", features=["ssl"] } +actix-web = { version="1.0.0-alpha.4", features=["ssl"] } env_logger = "0.6" openssl = { version="0.10" } diff --git a/web-cors/backend/Cargo.toml b/web-cors/backend/Cargo.toml index f1794a5..1930906 100644 --- a/web-cors/backend/Cargo.toml +++ b/web-cors/backend/Cargo.toml @@ -6,7 +6,7 @@ workspace = "../../" edition = "2018" [dependencies] -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/websocket-chat/Cargo.toml b/websocket-chat/Cargo.toml index 34b389e..e59f220 100644 --- a/websocket-chat/Cargo.toml +++ b/websocket-chat/Cargo.toml @@ -11,9 +11,9 @@ path = "src/main.rs" [dependencies] actix = "0.8.0-alpha.2" -actix-web = "1.0.0-alpha.3" -actix-web-actors = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" +actix-web = "1.0.0-alpha.4" +actix-web-actors = "1.0.0-alpha.2" +actix-files = "0.1.0-alpha.4" rand = "0.6" bytes = "0.4" diff --git a/websocket-tcp-chat/Cargo.toml b/websocket-tcp-chat/Cargo.toml index 40f25f5..b812bfa 100644 --- a/websocket-tcp-chat/Cargo.toml +++ b/websocket-tcp-chat/Cargo.toml @@ -15,9 +15,9 @@ path = "src/client.rs" [dependencies] actix = "0.8.0-alpha.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" actix-web-actors = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" +actix-files = "0.1.0-alpha.4" rand = "0.6" bytes = "0.4" diff --git a/websocket/Cargo.toml b/websocket/Cargo.toml index e3b9d15..1c67978 100644 --- a/websocket/Cargo.toml +++ b/websocket/Cargo.toml @@ -15,9 +15,9 @@ path = "src/main.rs" [dependencies] actix = "0.8.0-alpha.2" -actix-web = "1.0.0-alpha.3" +actix-web = "1.0.0-alpha.4" actix-web-actors = "1.0.0-alpha.3" -actix-files = "0.1.0-alpha.2" +actix-files = "0.1.0-alpha.4" env_logger = "0.6" futures = "0.1" bytes = "0.4" \ No newline at end of file