1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-02 00:02:02 +00:00

Merge branch 'master' into master

This commit is contained in:
Darin 2019-06-24 18:41:48 -04:00 committed by GitHub
commit 93855b889a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 178 additions and 103 deletions

View file

@ -1,6 +1,21 @@
# Changes
## [1.0.1] - 2019-06-xx
## [1.0.3] - unreleased
### Changed
* Use `encoding_rs` crate instead of unmaintained `encoding` crate
## [1.0.2] - 2019-06-17
### Changed
* Move cors middleware to `actix-cors` crate.
* Move identity middleware to `actix-identity` crate.
## [1.0.1] - 2019-06-17
### Add
@ -8,7 +23,7 @@
* Add `middleware::identity::RequestIdentity` trait to `get_identity` from `HttpMessage`.
### Changes
### Changed
* Move cors middleware to `actix-cors` crate.
@ -38,7 +53,7 @@
* Add macros for head, options, trace, connect and patch http methods
### Changes
### Changed
* Drop an unnecessary `Option<_>` indirection around `ServerBuilder` from `HttpServer`. #863
@ -56,7 +71,7 @@
* Add `Query<T>::from_query()` to extract parameters from a query string. #846
* `QueryConfig`, similar to `JsonConfig` for customizing error handling of query extractors.
### Changes
### Changed
* `JsonConfig` is now `Send + Sync`, this implies that `error_handler` must be `Send + Sync` too.
@ -71,7 +86,7 @@
* Allow to set/override app data on scope level
### Changes
### Changed
* `App::configure` take an `FnOnce` instead of `Fn`
* Upgrade actix-net crates

View file

@ -1,6 +1,6 @@
[package]
name = "actix-web"
version = "1.0.0"
version = "1.0.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
readme = "README.md"
@ -43,7 +43,7 @@ members = [
]
[features]
default = ["brotli", "flate2-zlib", "client", "fail", "depracated"]
default = ["brotli", "flate2-zlib", "client", "fail"]
# http client
client = ["awc"]
@ -68,31 +68,24 @@ ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
# rustls
rust-tls = ["rustls", "actix-server/rust-tls"]
# deprecated middlewares
depracated = ["actix-cors", "actix-identity"]
[dependencies]
actix-codec = "0.1.2"
actix-service = "0.4.0"
actix-service = "0.4.1"
actix-utils = "0.4.1"
actix-router = "0.1.5"
actix-rt = "0.2.2"
actix-web-codegen = "0.1.2"
actix-http = "0.2.3"
actix-http = "0.2.4"
actix-server = "0.5.1"
actix-server-config = "0.1.1"
actix-threadpool = "0.1.1"
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"
derive_more = "0.14"
encoding = "0.2"
derive_more = "0.15.0"
encoding_rs = "0.8"
futures = "0.1.25"
hashbrown = "0.3.1"
hashbrown = "0.5.0"
log = "0.4"
mime = "0.3"
net2 = "0.2.33"
@ -110,8 +103,8 @@ rustls = { version = "0.15", optional = true }
[dev-dependencies]
actix = { version = "0.8.3" }
actix-http = { version = "0.2.3", features=["ssl", "brotli", "flate2-zlib"] }
actix-http-test = { version = "0.2.0", features=["ssl"] }
actix-http = { version = "0.2.4", features=["ssl", "brotli", "flate2-zlib"] }
actix-http-test = { version = "0.2.2", features=["ssl"] }
rand = "0.6"
env_logger = "0.6"
serde_derive = "1.0"
@ -125,7 +118,7 @@ opt-level = 3
codegen-units = 1
[patch.crates-io]
# actix-web = { path = "." }
actix-web = { path = "." }
actix-http = { path = "actix-http" }
actix-http-test = { path = "test-server" }
actix-web-codegen = { path = "actix-web-codegen" }

View file

@ -31,6 +31,64 @@
## 1.0.0
* Extractor configuration. In version 1.0 this is handled with the new `Data` mechanism for both setting and retrieving the configuration
instead of
```rust
#[derive(Default)]
struct ExtractorConfig {
config: String,
}
impl FromRequest for YourExtractor {
type Config = ExtractorConfig;
type Result = Result<YourExtractor, Error>;
fn from_request(req: &HttpRequest, cfg: &Self::Config) -> Self::Result {
println!("use the config: {:?}", cfg.config);
...
}
}
App::new().resource("/route_with_config", |r| {
r.post().with_config(handler_fn, |cfg| {
cfg.0.config = "test".to_string();
})
})
```
use the HttpRequest to get the configuration like any other `Data` with `req.app_data::<C>()` and set it with the `data()` method on the `resource`
```rust
#[derive(Default)]
struct ExtractorConfig {
config: String,
}
impl FromRequest for YourExtractor {
type Error = Error;
type Future = Result<Self, Self::Error>;
type Config = ExtractorConfig;
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
let cfg = req.app_data::<ExtractorConfig>();
println!("config data?: {:?}", cfg.unwrap().role);
...
}
}
App::new().service(
resource("/route_with_config")
.data(ExtractorConfig {
config: "test".to_string(),
})
.route(post().to(handler_fn)),
)
```
* Resource registration. 1.0 version uses generalized resource
registration via `.service()` method.

View file

@ -1,5 +1,9 @@
# Changes
## [0.1.1] - unreleased
* Bump `derive_more` crate version to 0.15.0
## [0.1.0] - 2019-06-15
* Move cors middleware to separate crate

View file

@ -19,5 +19,5 @@ path = "src/lib.rs"
[dependencies]
actix-web = "1.0.0"
actix-service = "0.4.0"
derive_more = "0.14.1"
derive_more = "0.15.0"
futures = "0.1.25"

View file

@ -19,12 +19,12 @@ path = "src/lib.rs"
[dependencies]
actix-web = { version = "1.0.0", default-features = false }
actix-http = "0.2.3"
actix-service = "0.4.0"
actix-http = "0.2.4"
actix-service = "0.4.1"
bitflags = "1"
bytes = "0.4"
futures = "0.1.25"
derive_more = "0.14"
derive_more = "0.15.0"
log = "0.4"
mime = "0.3"
mime_guess = "2.0.0-alpha"

View file

@ -1,5 +1,18 @@
# Changes
## [0.2.5] - unreleased
### Changed
* Use `encoding_rs` crate instead of unmaintained `encoding` crate
## [0.2.4] - 2019-06-16
### Fixed
* Do not compress NoContent (204) responses #918
## [0.2.3] - 2019-06-02
### Added
@ -76,7 +89,7 @@
## [0.1.1] - 2019-04-19
### Changes
### Changed
* Cookie::max_age() accepts value in seconds

View file

@ -1,6 +1,6 @@
[package]
name = "actix-http"
version = "0.2.3"
version = "0.2.4"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix http primitives"
readme = "README.md"
@ -56,11 +56,11 @@ bitflags = "1.0"
bytes = "0.4"
byteorder = "1.2"
copyless = "0.1.2"
derive_more = "0.14"
derive_more = "0.15.0"
either = "1.5.2"
encoding = "0.2"
encoding_rs = "0.8"
futures = "0.1.25"
hashbrown = "0.3.0"
hashbrown = "0.5.0"
h2 = "0.1.16"
http = "0.1.17"
httparse = "1.3"

View file

@ -33,6 +33,7 @@ impl<B: MessageBody> Encoder<B> {
) -> ResponseBody<Encoder<B>> {
let can_encode = !(head.headers().contains_key(&CONTENT_ENCODING)
|| head.status == StatusCode::SWITCHING_PROTOCOLS
|| head.status == StatusCode::NO_CONTENT
|| encoding == ContentEncoding::Identity
|| encoding == ContentEncoding::Auto);

View file

@ -61,6 +61,7 @@ impl Response {
STATIC_RESP!(RangeNotSatisfiable, StatusCode::RANGE_NOT_SATISFIABLE);
STATIC_RESP!(ExpectationFailed, StatusCode::EXPECTATION_FAILED);
STATIC_RESP!(UnprocessableEntity, StatusCode::UNPROCESSABLE_ENTITY);
STATIC_RESP!(TooManyRequests, StatusCode::TOO_MANY_REQUESTS);
STATIC_RESP!(InternalServerError, StatusCode::INTERNAL_SERVER_ERROR);
STATIC_RESP!(NotImplemented, StatusCode::NOT_IMPLEMENTED);

View file

@ -1,9 +1,7 @@
use std::cell::{Ref, RefMut};
use std::str;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::EncodingRef;
use encoding_rs::{Encoding, UTF_8};
use http::header;
use mime::Mime;
@ -59,10 +57,12 @@ pub trait HttpMessage: Sized {
/// Get content type encoding
///
/// UTF-8 is used by default, If request charset is not set.
fn encoding(&self) -> Result<EncodingRef, ContentTypeError> {
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError> {
if let Some(mime_type) = self.mime_type()? {
if let Some(charset) = mime_type.get_param("charset") {
if let Some(enc) = encoding_from_whatwg_label(charset.as_str()) {
if let Some(enc) =
Encoding::for_label_no_replacement(charset.as_str().as_bytes())
{
Ok(enc)
} else {
Err(ContentTypeError::UnknownEncoding)
@ -166,8 +166,7 @@ where
#[cfg(test)]
mod tests {
use bytes::Bytes;
use encoding::all::ISO_8859_2;
use encoding::Encoding;
use encoding_rs::ISO_8859_2;
use mime;
use super::*;
@ -223,7 +222,7 @@ mod tests {
"application/json; charset=ISO-8859-2",
)
.finish();
assert_eq!(ISO_8859_2.name(), req.encoding().unwrap().name());
assert_eq!(ISO_8859_2, req.encoding().unwrap());
}
#[test]

View file

@ -19,9 +19,9 @@ path = "src/lib.rs"
[dependencies]
actix-web = { version = "1.0.0", default-features = false }
actix-service = "0.4.0"
actix-service = "0.4.1"
bytes = "0.4"
derive_more = "0.14"
derive_more = "0.15.0"
httparse = "1.3"
futures = "0.1.25"
log = "0.4"
@ -31,4 +31,4 @@ twoway = "0.2"
[dev-dependencies]
actix-rt = "0.2.2"
actix-http = "0.2.2"
actix-http = "0.2.4"

View file

@ -24,12 +24,12 @@ default = ["cookie-session"]
cookie-session = ["actix-web/secure-cookies"]
[dependencies]
actix-web = "1.0.0-rc"
actix-service = "0.4.0"
actix-web = "1.0.0"
actix-service = "0.4.1"
bytes = "0.4"
derive_more = "0.14"
derive_more = "0.15.0"
futures = "0.1.25"
hashbrown = "0.3.0"
hashbrown = "0.5.0"
serde = "1.0"
serde_json = "1.0"
time = "0.1.42"

View file

@ -19,8 +19,8 @@ path = "src/lib.rs"
[dependencies]
actix = "0.8.3"
actix-web = "1.0.0-rc"
actix-http = "0.2.2"
actix-web = "1.0.0"
actix-http = "0.2.4"
actix-codec = "0.1.2"
bytes = "0.4"
futures = "0.1.25"

View file

@ -16,7 +16,7 @@ quote = "0.6.12"
syn = { version = "0.15.34", features = ["full", "parsing", "extra-traits"] }
[dev-dependencies]
actix-web = { version = "1.0.0-rc" }
actix-http = { version = "0.2.2", features=["ssl"] }
actix-web = { version = "1.0.0" }
actix-http = { version = "0.2.4", features=["ssl"] }
actix-http-test = { version = "0.2.0", features=["ssl"] }
futures = { version = "0.1" }

View file

@ -40,11 +40,11 @@ flate2-rust = ["actix-http/flate2-rust"]
[dependencies]
actix-codec = "0.1.2"
actix-service = "0.4.0"
actix-http = "0.2.3"
actix-service = "0.4.1"
actix-http = "0.2.4"
base64 = "0.10.1"
bytes = "0.4"
derive_more = "0.14"
derive_more = "0.15.0"
futures = "0.1.25"
log =" 0.4"
mime = "0.3"
@ -58,8 +58,8 @@ openssl = { version="0.10", optional = true }
[dev-dependencies]
actix-rt = "0.2.2"
actix-web = { version = "1.0.0-rc", features=["ssl"] }
actix-http = { version = "0.2.3", features=["ssl"] }
actix-web = { version = "1.0.0", features=["ssl"] }
actix-http = { version = "0.2.4", features=["ssl"] }
actix-http-test = { version = "0.2.0", features=["ssl"] }
actix-utils = "0.4.1"
actix-server = { version = "0.5.1", features=["ssl"] }

View file

@ -73,7 +73,7 @@ impl<T> Data<T> {
Data(Arc::new(state))
}
/// Get referecnce to inner app data.
/// Get reference to inner app data.
pub fn get_ref(&self) -> &T {
self.0.as_ref()
}

View file

@ -10,17 +10,3 @@ mod normalize;
pub use self::defaultheaders::DefaultHeaders;
pub use self::logger::Logger;
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

@ -5,9 +5,7 @@ use std::{fmt, ops};
use actix_http::{Error, HttpMessage, Payload};
use bytes::BytesMut;
use encoding::all::UTF_8;
use encoding::types::{DecoderTrap, Encoding};
use encoding::EncodingRef;
use encoding_rs::{Encoding, UTF_8};
use futures::{Future, Poll, Stream};
use serde::de::DeserializeOwned;
@ -187,7 +185,7 @@ pub struct UrlEncoded<U> {
stream: Option<Decompress<Payload>>,
limit: usize,
length: Option<usize>,
encoding: EncodingRef,
encoding: &'static Encoding,
err: Option<UrlencodedError>,
fut: Option<Box<Future<Item = U, Error = UrlencodedError>>>,
}
@ -286,13 +284,14 @@ where
}
})
.and_then(move |body| {
if (encoding as *const Encoding) == UTF_8 {
if encoding == UTF_8 {
serde_urlencoded::from_bytes::<U>(&body)
.map_err(|_| UrlencodedError::Parse)
} else {
let body = encoding
.decode(&body, DecoderTrap::Strict)
.map_err(|_| UrlencodedError::Parse)?;
.decode_without_bom_handling_and_without_replacement(&body)
.map(|s| s.into_owned())
.ok_or(UrlencodedError::Parse)?;
serde_urlencoded::from_str::<U>(&body)
.map_err(|_| UrlencodedError::Parse)
}

View file

@ -4,8 +4,7 @@ use std::str;
use actix_http::error::{Error, ErrorBadRequest, PayloadError};
use actix_http::HttpMessage;
use bytes::{Bytes, BytesMut};
use encoding::all::UTF_8;
use encoding::types::{DecoderTrap, Encoding};
use encoding_rs::UTF_8;
use futures::future::{err, Either, FutureResult};
use futures::{Future, Poll, Stream};
use mime::Mime;
@ -208,15 +207,15 @@ impl FromRequest for String {
.limit(limit)
.from_err()
.and_then(move |body| {
let enc: *const Encoding = encoding as *const Encoding;
if enc == UTF_8 {
if encoding == UTF_8 {
Ok(str::from_utf8(body.as_ref())
.map_err(|_| ErrorBadRequest("Can not decode body"))?
.to_owned())
} else {
Ok(encoding
.decode(&body, DecoderTrap::Strict)
.map_err(|_| ErrorBadRequest("Can not decode body"))?)
.decode_without_bom_handling_and_without_replacement(&body)
.map(|s| s.into_owned())
.ok_or_else(|| ErrorBadRequest("Can not decode body"))?)
}
}),
))

View file

@ -1,9 +1,8 @@
use std::borrow::Cow;
use std::str;
use bytes::{Bytes, BytesMut};
use encoding::all::UTF_8;
use encoding::types::{DecoderTrap, Encoding};
use encoding::EncodingRef;
use encoding_rs::{Encoding, UTF_8};
use futures::{Async, Poll, Stream};
use crate::dev::Payload;
@ -16,7 +15,7 @@ pub struct Readlines<T: HttpMessage> {
buff: BytesMut,
limit: usize,
checked_buff: bool,
encoding: EncodingRef,
encoding: &'static Encoding,
err: Option<ReadlinesError>,
}
@ -87,15 +86,17 @@ where
if ind + 1 > self.limit {
return Err(ReadlinesError::LimitOverflow);
}
let enc: *const Encoding = self.encoding as *const Encoding;
let line = if enc == UTF_8 {
let line = if self.encoding == UTF_8 {
str::from_utf8(&self.buff.split_to(ind + 1))
.map_err(|_| ReadlinesError::EncodingError)?
.to_owned()
} else {
self.encoding
.decode(&self.buff.split_to(ind + 1), DecoderTrap::Strict)
.map_err(|_| ReadlinesError::EncodingError)?
.decode_without_bom_handling_and_without_replacement(
&self.buff.split_to(ind + 1),
)
.map(Cow::into_owned)
.ok_or(ReadlinesError::EncodingError)?
};
return Ok(Async::Ready(Some(line)));
}
@ -117,15 +118,17 @@ where
if ind + 1 > self.limit {
return Err(ReadlinesError::LimitOverflow);
}
let enc: *const Encoding = self.encoding as *const Encoding;
let line = if enc == UTF_8 {
let line = if self.encoding == UTF_8 {
str::from_utf8(&bytes.split_to(ind + 1))
.map_err(|_| ReadlinesError::EncodingError)?
.to_owned()
} else {
self.encoding
.decode(&bytes.split_to(ind + 1), DecoderTrap::Strict)
.map_err(|_| ReadlinesError::EncodingError)?
.decode_without_bom_handling_and_without_replacement(
&bytes.split_to(ind + 1),
)
.map(Cow::into_owned)
.ok_or(ReadlinesError::EncodingError)?
};
// extend buffer with rest of the bytes;
self.buff.extend_from_slice(&bytes);
@ -143,15 +146,15 @@ where
if self.buff.len() > self.limit {
return Err(ReadlinesError::LimitOverflow);
}
let enc: *const Encoding = self.encoding as *const Encoding;
let line = if enc == UTF_8 {
let line = if self.encoding == UTF_8 {
str::from_utf8(&self.buff)
.map_err(|_| ReadlinesError::EncodingError)?
.to_owned()
} else {
self.encoding
.decode(&self.buff, DecoderTrap::Strict)
.map_err(|_| ReadlinesError::EncodingError)?
.decode_without_bom_handling_and_without_replacement(&self.buff)
.map(Cow::into_owned)
.ok_or(ReadlinesError::EncodingError)?
};
self.buff.clear();
Ok(Async::Ready(Some(line)))

View file

@ -1,5 +1,9 @@
# Changes
## [0.2.2] - 2019-06-16
* Add .put() and .sput() methods
## [0.2.1] - 2019-06-05
* Add license files

View file

@ -1,6 +1,6 @@
[package]
name = "actix-http-test"
version = "0.2.1"
version = "0.2.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix http test server"
readme = "README.md"
@ -32,7 +32,7 @@ ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
[dependencies]
actix-codec = "0.1.2"
actix-rt = "0.2.2"
actix-service = "0.4.0"
actix-service = "0.4.1"
actix-server = "0.5.1"
actix-utils = "0.4.1"
awc = "0.2.1"
@ -55,5 +55,5 @@ tokio-timer = "0.2"
openssl = { version="0.10", optional = true }
[dev-dependencies]
actix-web = "1.0.0-rc"
actix-http = "0.2.3"
actix-web = "1.0.0"
actix-http = "0.2.4"