Merge branch 'master' into dpypin/freeze-client-request

This commit is contained in:
Dmitry Pypin 2019-08-28 14:07:36 -07:00
commit 2b8ce83028
11 changed files with 57 additions and 13 deletions

View File

@ -1,6 +1,6 @@
# Changes # Changes
## [1.0.6] - 2019-xx-xx ## [1.0.6] - 2019-08-28
### Added ### Added
@ -8,10 +8,17 @@
* Form immplements Responder, returning a `application/x-www-form-urlencoded` response * Form immplements Responder, returning a `application/x-www-form-urlencoded` response
* Add `into_inner` to `Data`
* Add `test::TestRequest::set_form()` convenience method to automatically serialize data and set
the header in test requests.
### Changed ### Changed
* `Query` payload made `pub`. Allows user to pattern-match the payload. * `Query` payload made `pub`. Allows user to pattern-match the payload.
* Enable `rust-tls` feature for client #1045
* Update serde_urlencoded to 0.6.1 * Update serde_urlencoded to 0.6.1
* Update url to 2.1 * Update url to 2.1

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-web" name = "actix-web"
version = "1.0.5" version = "1.0.6"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
readme = "README.md" readme = "README.md"
@ -66,7 +66,7 @@ fail = ["actix-http/fail"]
ssl = ["openssl", "actix-server/ssl", "awc/ssl"] ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
# rustls # rustls
rust-tls = ["rustls", "actix-server/rust-tls"] rust-tls = ["rustls", "actix-server/rust-tls", "awc/rust-tls"]
# unix domain sockets support # unix domain sockets support
uds = ["actix-server/uds"] uds = ["actix-server/uds"]

View File

@ -1,4 +1,4 @@
# 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) # Cors Middleware 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-cors)](https://crates.io/crates/actix-cors) [![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 ## Documentation & community resources

View File

@ -269,9 +269,9 @@ where
.map(|protos| protos.windows(2).any(|w| w == H2)) .map(|protos| protos.windows(2).any(|w| w == H2))
.unwrap_or(false); .unwrap_or(false);
if h2 { if h2 {
(Box::new(sock) as Box<Io>, Protocol::Http2) (Box::new(sock) as Box<dyn Io>, Protocol::Http2)
} else { } else {
(Box::new(sock) as Box<Io>, Protocol::Http1) (Box::new(sock) as Box<dyn Io>, Protocol::Http1)
} }
}), }),
), ),
@ -288,9 +288,9 @@ where
.map(|protos| protos.windows(2).any(|w| w == H2)) .map(|protos| protos.windows(2).any(|w| w == H2))
.unwrap_or(false); .unwrap_or(false);
if h2 { if h2 {
(Box::new(sock) as Box<Io>, Protocol::Http2) (Box::new(sock) as Box<dyn Io>, Protocol::Http2)
} else { } else {
(Box::new(sock) as Box<Io>, Protocol::Http1) (Box::new(sock) as Box<dyn Io>, Protocol::Http1)
} }
}), }),
), ),

View File

@ -1072,7 +1072,7 @@ mod tests {
#[test] #[test]
fn test_error_casting() { fn test_error_casting() {
let err = PayloadError::Overflow; let err = PayloadError::Overflow;
let resp_err: &ResponseError = &err; let resp_err: &dyn ResponseError = &err;
let err = resp_err.downcast_ref::<PayloadError>().unwrap(); let err = resp_err.downcast_ref::<PayloadError>().unwrap();
assert_eq!(err.to_string(), "A payload reached size limit."); assert_eq!(err.to_string(), "A payload reached size limit.");
let not_err = resp_err.downcast_ref::<ContentTypeError>(); let not_err = resp_err.downcast_ref::<ContentTypeError>();

View File

@ -1,6 +1,6 @@
# Changes # Changes
## [0.1.3] - 2019-06-06 ## [0.1.3] - 2019-08-18
* Fix ring dependency from actix-web default features for #741. * Fix ring dependency from actix-web default features for #741.

View File

@ -77,6 +77,11 @@ impl<T> Data<T> {
pub fn get_ref(&self) -> &T { pub fn get_ref(&self) -> &T {
self.0.as_ref() self.0.as_ref()
} }
/// Convert to the internal Arc<T>
pub fn into_inner(self) -> Arc<T> {
self.0
}
} }
impl<T> Deref for Data<T> { impl<T> Deref for Data<T> {

View File

@ -151,5 +151,4 @@ mod tests {
let res = block_on(normalize.call(req)).unwrap(); let res = block_on(normalize.call(req)).unwrap();
assert!(res.status().is_success()); assert!(res.status().is_success());
} }
} }

View File

@ -763,5 +763,4 @@ mod tests {
let resp = call_service(&mut srv, req); let resp = call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::NO_CONTENT); assert_eq!(resp.status(), StatusCode::NO_CONTENT);
} }
} }

View File

@ -478,6 +478,16 @@ impl TestRequest {
self self
} }
/// Serialize `data` to a URL encoded form and set it as the request payload. The `Content-Type`
/// header is set to `application/x-www-form-urlencoded`.
pub fn set_form<T: Serialize>(mut self, data: &T) -> Self {
let bytes = serde_urlencoded::to_string(data)
.expect("Failed to serialize test data as a urlencoded form");
self.req.set_payload(bytes);
self.req.set(ContentType::form_url_encoded());
self
}
/// Serialize `data` to JSON and set it as the request payload. The `Content-Type` header is /// Serialize `data` to JSON and set it as the request payload. The `Content-Type` header is
/// set to `application/json`. /// set to `application/json`.
pub fn set_json<T: Serialize>(mut self, data: &T) -> Self { pub fn set_json<T: Serialize>(mut self, data: &T) -> Self {
@ -670,6 +680,31 @@ mod tests {
assert_eq!(&result.id, "12345"); assert_eq!(&result.id, "12345");
} }
#[test]
fn test_request_response_form() {
let mut app = init_service(App::new().service(web::resource("/people").route(
web::post().to(|person: web::Form<Person>| {
HttpResponse::Ok().json(person.into_inner())
}),
)));
let payload = Person {
id: "12345".to_string(),
name: "User name".to_string(),
};
let req = TestRequest::post()
.uri("/people")
.set_form(&payload)
.to_request();
assert_eq!(req.content_type(), "application/x-www-form-urlencoded");
let result: Person = read_response_json(&mut app, req);
assert_eq!(&result.id, "12345");
assert_eq!(&result.name, "User name");
}
#[test] #[test]
fn test_request_response_json() { fn test_request_response_json() {
let mut app = init_service(App::new().service(web::resource("/people").route( let mut app = init_service(App::new().service(web::resource("/people").route(

View File

@ -482,5 +482,4 @@ mod tests {
use crate::responder::tests::BodyTest; use crate::responder::tests::BodyTest;
assert_eq!(resp.body().bin_ref(), b"hello=world&counter=123"); assert_eq!(resp.body().bin_ref(), b"hello=world&counter=123");
} }
} }