mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-04 18:06:23 +02:00
Compare commits
22 Commits
session-v0
...
codegen-v0
Author | SHA1 | Date | |
---|---|---|---|
29a0fe76d5 | |||
7753b9da6d | |||
f1764bba43 | |||
c2d7db7e06 | |||
21418c7414 | |||
fe781345d5 | |||
a614be7cb5 | |||
1eb89b8375 | |||
aa626a1e72 | |||
7f12b754e9 | |||
3f196f469d | |||
35eb378585 | |||
6db625f55b | |||
801cc2ed5d | |||
ded1e86e7e | |||
babf48c550 | |||
d3e807f6e9 | |||
7746e785c1 | |||
4e141d7f5d | |||
12842871fe | |||
fc85ae4014 | |||
5826f39dbe |
20
CHANGES.md
20
CHANGES.md
@ -1,5 +1,25 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [1.0.0] - 2019-05-xx
|
||||||
|
|
||||||
|
### Add
|
||||||
|
|
||||||
|
* Add `ServiceRequest::set_payload()` method.
|
||||||
|
|
||||||
|
* Add `test::TestRequest::set_json()` convenience method to automatically
|
||||||
|
serialize data and set header in test requests.
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
* Drop an unnecessary `Option<_>` indirection around `ServerBuilder` from `HttpServer`. #863
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fix Logger request time format, and use rfc3339. #867
|
||||||
|
|
||||||
|
* Clear http requests pool on app service drop #860
|
||||||
|
|
||||||
|
|
||||||
## [1.0.0-rc] - 2019-05-18
|
## [1.0.0-rc] - 2019-05-18
|
||||||
|
|
||||||
### Add
|
### Add
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "1.0.0-rc"
|
version = "1.0.0"
|
||||||
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"
|
||||||
@ -73,7 +73,7 @@ actix-utils = "0.4.1"
|
|||||||
actix-router = "0.1.5"
|
actix-router = "0.1.5"
|
||||||
actix-rt = "0.2.2"
|
actix-rt = "0.2.2"
|
||||||
actix-web-codegen = "0.1.0"
|
actix-web-codegen = "0.1.0"
|
||||||
actix-http = "0.2.0"
|
actix-http = "0.2.2"
|
||||||
actix-server = "0.5.1"
|
actix-server = "0.5.1"
|
||||||
actix-server-config = "0.1.1"
|
actix-server-config = "0.1.1"
|
||||||
actix-threadpool = "0.1.0"
|
actix-threadpool = "0.1.0"
|
||||||
@ -100,9 +100,9 @@ openssl = { version="0.10", optional = true }
|
|||||||
rustls = { version = "0.15", optional = true }
|
rustls = { version = "0.15", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-http = { version = "0.2.0", features=["ssl", "brotli", "flate2-zlib"] }
|
actix-http = { version = "0.2.2", 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 = { version = "0.1.0-beta.4" }
|
actix-files = { version = "0.1.0" }
|
||||||
rand = "0.6"
|
rand = "0.6"
|
||||||
env_logger = "0.6"
|
env_logger = "0.6"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
11
MIGRATION.md
11
MIGRATION.md
@ -238,6 +238,17 @@
|
|||||||
|
|
||||||
* Actors support have been moved to `actix-web-actors` crate
|
* Actors support have been moved to `actix-web-actors` crate
|
||||||
|
|
||||||
|
* Custom Error
|
||||||
|
|
||||||
|
Instead of error_response method alone, ResponseError now provides two methods: error_response and render_response respectively. Where, error_response creates the error response and render_response returns the error response to the caller.
|
||||||
|
|
||||||
|
Simplest migration from 0.7 to 1.0 shall include below method to the custom implementation of ResponseError:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn render_response(&self) -> HttpResponse {
|
||||||
|
self.error_response()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 0.7.15
|
## 0.7.15
|
||||||
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.0] - 2019-05-25
|
||||||
|
|
||||||
|
* NamedFile last-modified check always fails due to nano-seconds
|
||||||
|
in file modified date #820
|
||||||
|
|
||||||
## [0.1.0-beta.4] - 2019-05-12
|
## [0.1.0-beta.4] - 2019-05-12
|
||||||
|
|
||||||
* Update actix-web to beta.4
|
* Update actix-web to beta.4
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-files"
|
name = "actix-files"
|
||||||
version = "0.1.0-beta.4"
|
version = "0.1.0"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Static files support for actix web."
|
description = "Static files support for actix web."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -18,7 +18,7 @@ name = "actix_files"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0.0-beta.5"
|
actix-web = "1.0.0-rc"
|
||||||
actix-service = "0.4.0"
|
actix-service = "0.4.0"
|
||||||
bitflags = "1"
|
bitflags = "1"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
@ -31,4 +31,4 @@ percent-encoding = "1.0"
|
|||||||
v_htmlescape = "0.4"
|
v_htmlescape = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-web = { version = "1.0.0-beta.5", features=["ssl"] }
|
actix-web = { version = "1.0.0-rc", features=["ssl"] }
|
||||||
|
@ -337,7 +337,12 @@ impl Responder for NamedFile {
|
|||||||
} else if let (Some(ref m), Some(header::IfUnmodifiedSince(ref since))) =
|
} else if let (Some(ref m), Some(header::IfUnmodifiedSince(ref since))) =
|
||||||
(last_modified, req.get_header())
|
(last_modified, req.get_header())
|
||||||
{
|
{
|
||||||
m > since
|
let t1: SystemTime = m.clone().into();
|
||||||
|
let t2: SystemTime = since.clone().into();
|
||||||
|
match (t1.duration_since(UNIX_EPOCH), t2.duration_since(UNIX_EPOCH)) {
|
||||||
|
(Ok(t1), Ok(t2)) => t1 > t2,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@ -350,7 +355,12 @@ impl Responder for NamedFile {
|
|||||||
} else if let (Some(ref m), Some(header::IfModifiedSince(ref since))) =
|
} else if let (Some(ref m), Some(header::IfModifiedSince(ref since))) =
|
||||||
(last_modified, req.get_header())
|
(last_modified, req.get_header())
|
||||||
{
|
{
|
||||||
m <= since
|
let t1: SystemTime = m.clone().into();
|
||||||
|
let t2: SystemTime = since.clone().into();
|
||||||
|
match (t1.duration_since(UNIX_EPOCH), t2.duration_since(UNIX_EPOCH)) {
|
||||||
|
(Ok(t1), Ok(t2)) => t1 <= t2,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,19 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.2] - 2019-05-29
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Parse incoming stream before closing stream on disconnect #868
|
||||||
|
|
||||||
|
|
||||||
|
## [0.2.1] - 2019-05-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Handle socket read disconnect
|
||||||
|
|
||||||
|
|
||||||
## [0.2.0] - 2019-05-12
|
## [0.2.0] - 2019-05-12
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-http"
|
name = "actix-http"
|
||||||
version = "0.2.0"
|
version = "0.2.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix http primitives"
|
description = "Actix http primitives"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -47,7 +47,7 @@ secure-cookies = ["ring"]
|
|||||||
actix-service = "0.4.0"
|
actix-service = "0.4.0"
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
actix-connect = "0.2.0"
|
actix-connect = "0.2.0"
|
||||||
actix-utils = "0.4.0"
|
actix-utils = "0.4.1"
|
||||||
actix-server-config = "0.1.1"
|
actix-server-config = "0.1.1"
|
||||||
actix-threadpool = "0.1.0"
|
actix-threadpool = "0.1.0"
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ time = "0.1.42"
|
|||||||
tokio-tcp = "0.1.3"
|
tokio-tcp = "0.1.3"
|
||||||
tokio-timer = "0.2.8"
|
tokio-timer = "0.2.8"
|
||||||
tokio-current-thread = "0.1"
|
tokio-current-thread = "0.1"
|
||||||
trust-dns-resolver = { version="0.11.0", default-features = false }
|
trust-dns-resolver = { version="0.11.1", default-features = false }
|
||||||
|
|
||||||
# for secure cookie
|
# for secure cookie
|
||||||
ring = { version = "0.14.6", optional = true }
|
ring = { version = "0.14.6", optional = true }
|
||||||
|
@ -583,6 +583,9 @@ where
|
|||||||
self.ka_timer = Some(Delay::new(interval));
|
self.ka_timer = Some(Delay::new(interval));
|
||||||
} else {
|
} else {
|
||||||
self.flags.insert(Flags::READ_DISCONNECT);
|
self.flags.insert(Flags::READ_DISCONNECT);
|
||||||
|
if let Some(mut payload) = self.payload.take() {
|
||||||
|
payload.set_error(PayloadError::Incomplete(None));
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -690,15 +693,20 @@ where
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// read socket into a buf
|
// read socket into a buf
|
||||||
if !inner.flags.contains(Flags::READ_DISCONNECT) {
|
let should_disconnect = if !inner.flags.contains(Flags::READ_DISCONNECT) {
|
||||||
if let Some(true) =
|
read_available(&mut inner.io, &mut inner.read_buf)?
|
||||||
read_available(&mut inner.io, &mut inner.read_buf)?
|
} else {
|
||||||
{
|
None
|
||||||
inner.flags.insert(Flags::READ_DISCONNECT)
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inner.poll_request()?;
|
inner.poll_request()?;
|
||||||
|
if let Some(true) = should_disconnect {
|
||||||
|
inner.flags.insert(Flags::READ_DISCONNECT);
|
||||||
|
if let Some(mut payload) = inner.payload.take() {
|
||||||
|
payload.feed_eof();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if inner.write_buf.remaining_mut() < LW_BUFFER_SIZE {
|
if inner.write_buf.remaining_mut() < LW_BUFFER_SIZE {
|
||||||
inner.write_buf.reserve(HW_BUFFER_SIZE);
|
inner.write_buf.reserve(HW_BUFFER_SIZE);
|
||||||
|
@ -9,6 +9,7 @@ use actix_service::{new_service_cfg, service_fn, NewService};
|
|||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::future::{self, ok, Future};
|
use futures::future::{self, ok, Future};
|
||||||
use futures::stream::{once, Stream};
|
use futures::stream::{once, Stream};
|
||||||
|
use regex::Regex;
|
||||||
use tokio_timer::sleep;
|
use tokio_timer::sleep;
|
||||||
|
|
||||||
use actix_http::body::Body;
|
use actix_http::body::Body;
|
||||||
@ -215,6 +216,56 @@ fn test_expect_continue_h1() {
|
|||||||
assert!(data.starts_with("HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200 OK\r\n"));
|
assert!(data.starts_with("HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200 OK\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_chunked_payload() {
|
||||||
|
let chunk_sizes = vec![ 32768, 32, 32768 ];
|
||||||
|
let total_size: usize = chunk_sizes.iter().sum();
|
||||||
|
|
||||||
|
let srv = TestServer::new(|| {
|
||||||
|
HttpService::build()
|
||||||
|
.h1(|mut request: Request| {
|
||||||
|
request.take_payload()
|
||||||
|
.map_err(|e| panic!(format!("Error reading payload: {}", e)))
|
||||||
|
.fold(0usize, |acc, chunk| {
|
||||||
|
future::ok::<_, ()>(acc + chunk.len())
|
||||||
|
})
|
||||||
|
.map(|req_size| {
|
||||||
|
Response::Ok().body(format!("size={}", req_size))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
let returned_size = {
|
||||||
|
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
|
||||||
|
let _ = stream.write_all(b"POST /test HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n");
|
||||||
|
|
||||||
|
for chunk_size in chunk_sizes.iter() {
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
let random_bytes: Vec<u8> = (0..*chunk_size).map(|_| rand::random::<u8>()).collect();
|
||||||
|
|
||||||
|
bytes.extend(format!("{:X}\r\n", chunk_size).as_bytes());
|
||||||
|
bytes.extend(&random_bytes[..]);
|
||||||
|
bytes.extend(b"\r\n");
|
||||||
|
let _ = stream.write_all(&bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = stream.write_all(b"0\r\n\r\n");
|
||||||
|
stream.shutdown(net::Shutdown::Write).unwrap();
|
||||||
|
|
||||||
|
let mut data = String::new();
|
||||||
|
let _ = stream.read_to_string(&mut data);
|
||||||
|
|
||||||
|
let re = Regex::new(r"size=(\d+)").unwrap();
|
||||||
|
let size: usize = match re.captures(&data) {
|
||||||
|
Some(caps) => caps.get(1).unwrap().as_str().parse().unwrap(),
|
||||||
|
None => panic!(format!("Failed to find size in HTTP Response: {}", data)),
|
||||||
|
};
|
||||||
|
size
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(returned_size, total_size);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_slow_request() {
|
fn test_slow_request() {
|
||||||
let srv = TestServer::new(|| {
|
let srv = TestServer::new(|| {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.1] - 2019-05-25
|
||||||
|
|
||||||
|
* Fix disconnect handling #834
|
||||||
|
|
||||||
## [0.1.0] - 2019-05-18
|
## [0.1.0] - 2019-05-18
|
||||||
|
|
||||||
* Release
|
* Release
|
||||||
|
|
||||||
## [0.1.0-beta.4] - 2019-05-12
|
## [0.1.0-beta.4] - 2019-05-12
|
||||||
|
|
||||||
* Handle cancellation of uploads #834 #736
|
* Handle cancellation of uploads #736
|
||||||
|
|
||||||
* Upgrade to actix-web 1.0.0-beta.4
|
* Upgrade to actix-web 1.0.0-beta.4
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-multipart"
|
name = "actix-multipart"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Multipart support for actix web framework."
|
description = "Multipart support for actix web framework."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -128,7 +128,7 @@ impl InnerMultipart {
|
|||||||
fn read_headers(
|
fn read_headers(
|
||||||
payload: &mut PayloadBuffer,
|
payload: &mut PayloadBuffer,
|
||||||
) -> Result<Option<HeaderMap>, MultipartError> {
|
) -> Result<Option<HeaderMap>, MultipartError> {
|
||||||
match payload.read_until(b"\r\n\r\n") {
|
match payload.read_until(b"\r\n\r\n")? {
|
||||||
None => {
|
None => {
|
||||||
if payload.eof {
|
if payload.eof {
|
||||||
Err(MultipartError::Incomplete)
|
Err(MultipartError::Incomplete)
|
||||||
@ -167,7 +167,7 @@ impl InnerMultipart {
|
|||||||
boundary: &str,
|
boundary: &str,
|
||||||
) -> Result<Option<bool>, MultipartError> {
|
) -> Result<Option<bool>, MultipartError> {
|
||||||
// TODO: need to read epilogue
|
// TODO: need to read epilogue
|
||||||
match payload.readline() {
|
match payload.readline()? {
|
||||||
None => {
|
None => {
|
||||||
if payload.eof {
|
if payload.eof {
|
||||||
Ok(Some(true))
|
Ok(Some(true))
|
||||||
@ -200,7 +200,7 @@ impl InnerMultipart {
|
|||||||
) -> Result<Option<bool>, MultipartError> {
|
) -> Result<Option<bool>, MultipartError> {
|
||||||
let mut eof = false;
|
let mut eof = false;
|
||||||
loop {
|
loop {
|
||||||
match payload.readline() {
|
match payload.readline()? {
|
||||||
Some(chunk) => {
|
Some(chunk) => {
|
||||||
if chunk.is_empty() {
|
if chunk.is_empty() {
|
||||||
return Err(MultipartError::Boundary);
|
return Err(MultipartError::Boundary);
|
||||||
@ -481,7 +481,7 @@ impl InnerField {
|
|||||||
if *size == 0 {
|
if *size == 0 {
|
||||||
Ok(Async::Ready(None))
|
Ok(Async::Ready(None))
|
||||||
} else {
|
} else {
|
||||||
match payload.read_max(*size) {
|
match payload.read_max(*size)? {
|
||||||
Some(mut chunk) => {
|
Some(mut chunk) => {
|
||||||
let len = cmp::min(chunk.len() as u64, *size);
|
let len = cmp::min(chunk.len() as u64, *size);
|
||||||
*size -= len;
|
*size -= len;
|
||||||
@ -512,7 +512,11 @@ impl InnerField {
|
|||||||
|
|
||||||
let len = payload.buf.len();
|
let len = payload.buf.len();
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
return Ok(Async::NotReady);
|
return if payload.eof {
|
||||||
|
Err(MultipartError::Incomplete)
|
||||||
|
} else {
|
||||||
|
Ok(Async::NotReady)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// check boundary
|
// check boundary
|
||||||
@ -597,7 +601,7 @@ impl InnerField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match payload.readline() {
|
match payload.readline()? {
|
||||||
None => Async::Ready(None),
|
None => Async::Ready(None),
|
||||||
Some(line) => {
|
Some(line) => {
|
||||||
if line.as_ref() != b"\r\n" {
|
if line.as_ref() != b"\r\n" {
|
||||||
@ -749,23 +753,31 @@ impl PayloadBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_max(&mut self, size: u64) -> Option<Bytes> {
|
fn read_max(&mut self, size: u64) -> Result<Option<Bytes>, MultipartError> {
|
||||||
if !self.buf.is_empty() {
|
if !self.buf.is_empty() {
|
||||||
let size = std::cmp::min(self.buf.len() as u64, size) as usize;
|
let size = std::cmp::min(self.buf.len() as u64, size) as usize;
|
||||||
Some(self.buf.split_to(size).freeze())
|
Ok(Some(self.buf.split_to(size).freeze()))
|
||||||
|
} else if self.eof {
|
||||||
|
Err(MultipartError::Incomplete)
|
||||||
} else {
|
} else {
|
||||||
None
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read until specified ending
|
/// Read until specified ending
|
||||||
pub fn read_until(&mut self, line: &[u8]) -> Option<Bytes> {
|
pub fn read_until(&mut self, line: &[u8]) -> Result<Option<Bytes>, MultipartError> {
|
||||||
twoway::find_bytes(&self.buf, line)
|
let res = twoway::find_bytes(&self.buf, line)
|
||||||
.map(|idx| self.buf.split_to(idx + line.len()).freeze())
|
.map(|idx| self.buf.split_to(idx + line.len()).freeze());
|
||||||
|
|
||||||
|
if res.is_none() && self.eof {
|
||||||
|
Err(MultipartError::Incomplete)
|
||||||
|
} else {
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read bytes until new line delimiter
|
/// Read bytes until new line delimiter
|
||||||
pub fn readline(&mut self) -> Option<Bytes> {
|
pub fn readline(&mut self) -> Result<Option<Bytes>, MultipartError> {
|
||||||
self.read_until(b"\n")
|
self.read_until(b"\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -991,7 +1003,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(payload.buf.len(), 0);
|
assert_eq!(payload.buf.len(), 0);
|
||||||
payload.poll_stream().unwrap();
|
payload.poll_stream().unwrap();
|
||||||
assert_eq!(None, payload.read_max(1));
|
assert_eq!(None, payload.read_max(1).unwrap());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1001,14 +1013,14 @@ mod tests {
|
|||||||
let (mut sender, payload) = Payload::create(false);
|
let (mut sender, payload) = Payload::create(false);
|
||||||
let mut payload = PayloadBuffer::new(payload);
|
let mut payload = PayloadBuffer::new(payload);
|
||||||
|
|
||||||
assert_eq!(None, payload.read_max(4));
|
assert_eq!(None, payload.read_max(4).unwrap());
|
||||||
sender.feed_data(Bytes::from("data"));
|
sender.feed_data(Bytes::from("data"));
|
||||||
sender.feed_eof();
|
sender.feed_eof();
|
||||||
payload.poll_stream().unwrap();
|
payload.poll_stream().unwrap();
|
||||||
|
|
||||||
assert_eq!(Some(Bytes::from("data")), payload.read_max(4));
|
assert_eq!(Some(Bytes::from("data")), payload.read_max(4).unwrap());
|
||||||
assert_eq!(payload.buf.len(), 0);
|
assert_eq!(payload.buf.len(), 0);
|
||||||
assert_eq!(None, payload.read_max(1));
|
assert!(payload.read_max(1).is_err());
|
||||||
assert!(payload.eof);
|
assert!(payload.eof);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1018,7 +1030,7 @@ mod tests {
|
|||||||
run_on(|| {
|
run_on(|| {
|
||||||
let (mut sender, payload) = Payload::create(false);
|
let (mut sender, payload) = Payload::create(false);
|
||||||
let mut payload = PayloadBuffer::new(payload);
|
let mut payload = PayloadBuffer::new(payload);
|
||||||
assert_eq!(None, payload.read_max(1));
|
assert_eq!(None, payload.read_max(1).unwrap());
|
||||||
sender.set_error(PayloadError::Incomplete(None));
|
sender.set_error(PayloadError::Incomplete(None));
|
||||||
payload.poll_stream().err().unwrap();
|
payload.poll_stream().err().unwrap();
|
||||||
})
|
})
|
||||||
@ -1035,10 +1047,10 @@ mod tests {
|
|||||||
payload.poll_stream().unwrap();
|
payload.poll_stream().unwrap();
|
||||||
assert_eq!(payload.buf.len(), 10);
|
assert_eq!(payload.buf.len(), 10);
|
||||||
|
|
||||||
assert_eq!(Some(Bytes::from("line1")), payload.read_max(5));
|
assert_eq!(Some(Bytes::from("line1")), payload.read_max(5).unwrap());
|
||||||
assert_eq!(payload.buf.len(), 5);
|
assert_eq!(payload.buf.len(), 5);
|
||||||
|
|
||||||
assert_eq!(Some(Bytes::from("line2")), payload.read_max(5));
|
assert_eq!(Some(Bytes::from("line2")), payload.read_max(5).unwrap());
|
||||||
assert_eq!(payload.buf.len(), 0);
|
assert_eq!(payload.buf.len(), 0);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1069,16 +1081,22 @@ mod tests {
|
|||||||
let (mut sender, payload) = Payload::create(false);
|
let (mut sender, payload) = Payload::create(false);
|
||||||
let mut payload = PayloadBuffer::new(payload);
|
let mut payload = PayloadBuffer::new(payload);
|
||||||
|
|
||||||
assert_eq!(None, payload.read_until(b"ne"));
|
assert_eq!(None, payload.read_until(b"ne").unwrap());
|
||||||
|
|
||||||
sender.feed_data(Bytes::from("line1"));
|
sender.feed_data(Bytes::from("line1"));
|
||||||
sender.feed_data(Bytes::from("line2"));
|
sender.feed_data(Bytes::from("line2"));
|
||||||
payload.poll_stream().unwrap();
|
payload.poll_stream().unwrap();
|
||||||
|
|
||||||
assert_eq!(Some(Bytes::from("line")), payload.read_until(b"ne"));
|
assert_eq!(
|
||||||
|
Some(Bytes::from("line")),
|
||||||
|
payload.read_until(b"ne").unwrap()
|
||||||
|
);
|
||||||
assert_eq!(payload.buf.len(), 6);
|
assert_eq!(payload.buf.len(), 6);
|
||||||
|
|
||||||
assert_eq!(Some(Bytes::from("1line2")), payload.read_until(b"2"));
|
assert_eq!(
|
||||||
|
Some(Bytes::from("1line2")),
|
||||||
|
payload.read_until(b"2").unwrap()
|
||||||
|
);
|
||||||
assert_eq!(payload.buf.len(), 0);
|
assert_eq!(payload.buf.len(), 0);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [1.0.0] - 2019-05-29
|
||||||
|
|
||||||
|
* Update actix-http and actix-web
|
||||||
|
|
||||||
## [0.1.0-alpha.3] - 2019-04-02
|
## [0.1.0-alpha.3] - 2019-04-02
|
||||||
|
|
||||||
* Update actix-http and actix-web
|
* Update actix-http and actix-web
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-actors"
|
name = "actix-web-actors"
|
||||||
version = "1.0.0-beta.4"
|
version = "1.0.0"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix actors support for actix web framework."
|
description = "Actix actors support for actix web framework."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -18,9 +18,9 @@ name = "actix_web_actors"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.8.2"
|
actix = "0.8.3"
|
||||||
actix-web = "1.0.0-beta.5"
|
actix-web = "1.0.0-rc"
|
||||||
actix-http = "0.2.0"
|
actix-http = "0.2.2"
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
futures = "0.1.25"
|
futures = "0.1.25"
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.1] - 2019-06-01
|
||||||
|
|
||||||
|
* Add syn "extra-traits" feature
|
||||||
|
|
||||||
## [0.1.0] - 2019-05-18
|
## [0.1.0] - 2019-05-18
|
||||||
|
|
||||||
* Release
|
* Release
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-codegen"
|
name = "actix-web-codegen"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
description = "Actix web proc macros"
|
description = "Actix web proc macros"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
@ -12,11 +12,11 @@ workspace = ".."
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "0.6"
|
quote = "0.6.12"
|
||||||
syn = { version = "0.15", features = ["full", "parsing"] }
|
syn = { version = "0.15.34", features = ["full", "parsing", "extra-traits"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-web = { version = "1.0.0-beta.5" }
|
actix-web = { version = "1.0.0-rc" }
|
||||||
actix-http = { version = "0.2.0", features=["ssl"] }
|
actix-http = { version = "0.2.2", features=["ssl"] }
|
||||||
actix-http-test = { version = "0.2.0", features=["ssl"] }
|
actix-http-test = { version = "0.2.0", features=["ssl"] }
|
||||||
futures = { version = "0.1" }
|
futures = { version = "0.1" }
|
||||||
|
1
actix-web-codegen/LICENSE-APACHE
Symbolic link
1
actix-web-codegen/LICENSE-APACHE
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../LICENSE-APACHE
|
1
actix-web-codegen/LICENSE-MIT
Symbolic link
1
actix-web-codegen/LICENSE-MIT
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../LICENSE-MIT
|
@ -183,7 +183,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Service to convert `Request` to a `ServiceRequest<S>`
|
/// Service to convert `Request` to a `ServiceRequest<S>`
|
||||||
pub struct AppInitService<T: Service, B>
|
pub struct AppInitService<T, B>
|
||||||
where
|
where
|
||||||
T: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
T: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
{
|
{
|
||||||
@ -215,19 +215,30 @@ where
|
|||||||
inner.path.get_mut().update(&head.uri);
|
inner.path.get_mut().update(&head.uri);
|
||||||
inner.path.reset();
|
inner.path.reset();
|
||||||
inner.head = head;
|
inner.head = head;
|
||||||
|
inner.payload = payload;
|
||||||
inner.app_data = self.data.clone();
|
inner.app_data = self.data.clone();
|
||||||
req
|
req
|
||||||
} else {
|
} else {
|
||||||
HttpRequest::new(
|
HttpRequest::new(
|
||||||
Path::new(Url::new(head.uri.clone())),
|
Path::new(Url::new(head.uri.clone())),
|
||||||
head,
|
head,
|
||||||
|
payload,
|
||||||
self.rmap.clone(),
|
self.rmap.clone(),
|
||||||
self.config.clone(),
|
self.config.clone(),
|
||||||
self.data.clone(),
|
self.data.clone(),
|
||||||
self.pool,
|
self.pool,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
self.service.call(ServiceRequest::from_parts(req, payload))
|
self.service.call(ServiceRequest::new(req))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, B> Drop for AppInitService<T, B>
|
||||||
|
where
|
||||||
|
T: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
|
{
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.pool.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,3 +419,37 @@ impl NewService for AppEntry {
|
|||||||
self.factory.borrow_mut().as_mut().unwrap().new_service(&())
|
self.factory.borrow_mut().as_mut().unwrap().new_service(&())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use actix_service::Service;
|
||||||
|
use std::sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{test, web, App, HttpResponse};
|
||||||
|
|
||||||
|
struct DropData(Arc<AtomicBool>);
|
||||||
|
|
||||||
|
impl Drop for DropData {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn drop_data() {
|
||||||
|
let data = Arc::new(AtomicBool::new(false));
|
||||||
|
{
|
||||||
|
let mut app = test::init_service(
|
||||||
|
App::new()
|
||||||
|
.data(DropData(data.clone()))
|
||||||
|
.service(web::resource("/test").to(|| HttpResponse::Ok())),
|
||||||
|
);
|
||||||
|
let req = test::TestRequest::with_uri("/test").to_request();
|
||||||
|
let _ = test::block_on(app.call(req)).unwrap();
|
||||||
|
}
|
||||||
|
assert!(data.load(Ordering::Relaxed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use actix_http::{Error, Payload, Response};
|
use actix_http::{Error, Response};
|
||||||
use actix_service::{NewService, Service};
|
use actix_service::{NewService, Service};
|
||||||
use futures::future::{ok, FutureResult};
|
use futures::future::{ok, FutureResult};
|
||||||
use futures::{try_ready, Async, Future, IntoFuture, Poll};
|
use futures::{try_ready, Async, Future, IntoFuture, Poll};
|
||||||
@ -331,15 +331,15 @@ where
|
|||||||
|
|
||||||
ExtractResponse {
|
ExtractResponse {
|
||||||
fut,
|
fut,
|
||||||
|
req,
|
||||||
fut_s: None,
|
fut_s: None,
|
||||||
req: Some((req, payload)),
|
|
||||||
service: self.service.clone(),
|
service: self.service.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExtractResponse<T: FromRequest, S: Service> {
|
pub struct ExtractResponse<T: FromRequest, S: Service> {
|
||||||
req: Option<(HttpRequest, Payload)>,
|
req: HttpRequest,
|
||||||
service: S,
|
service: S,
|
||||||
fut: <T::Future as IntoFuture>::Future,
|
fut: <T::Future as IntoFuture>::Future,
|
||||||
fut_s: Option<S::Future>,
|
fut_s: Option<S::Future>,
|
||||||
@ -362,12 +362,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
let item = try_ready!(self.fut.poll().map_err(|e| {
|
let item = try_ready!(self.fut.poll().map_err(|e| {
|
||||||
let (req, payload) = self.req.take().unwrap();
|
let req = ServiceRequest::new(self.req.clone());
|
||||||
let req = ServiceRequest::from_parts(req, payload);
|
|
||||||
(e.into(), req)
|
(e.into(), req)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.fut_s = Some(self.service.call((item, self.req.take().unwrap().0)));
|
self.fut_s = Some(self.service.call((item, self.req.clone())));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,7 @@ pub mod dev {
|
|||||||
};
|
};
|
||||||
pub use actix_router::{Path, ResourceDef, ResourcePath, Url};
|
pub use actix_router::{Path, ResourceDef, ResourcePath, Url};
|
||||||
pub use actix_server::Server;
|
pub use actix_server::Server;
|
||||||
|
pub use actix_service::{Service, Transform};
|
||||||
|
|
||||||
pub(crate) fn insert_slash(path: &str) -> String {
|
pub(crate) fn insert_slash(path: &str) -> String {
|
||||||
let mut path = path.to_owned();
|
let mut path = path.to_owned();
|
||||||
|
@ -53,7 +53,7 @@ use crate::HttpResponse;
|
|||||||
///
|
///
|
||||||
/// `%a` Remote IP-address (IP-address of proxy if using reverse proxy)
|
/// `%a` Remote IP-address (IP-address of proxy if using reverse proxy)
|
||||||
///
|
///
|
||||||
/// `%t` Time when the request was started to process
|
/// `%t` Time when the request was started to process (in rfc3339 format)
|
||||||
///
|
///
|
||||||
/// `%r` First line of request
|
/// `%r` First line of request
|
||||||
///
|
///
|
||||||
@ -417,10 +417,7 @@ impl FormatText {
|
|||||||
}
|
}
|
||||||
FormatText::UrlPath => *self = FormatText::Str(format!("{}", req.path())),
|
FormatText::UrlPath => *self = FormatText::Str(format!("{}", req.path())),
|
||||||
FormatText::RequestTime => {
|
FormatText::RequestTime => {
|
||||||
*self = FormatText::Str(format!(
|
*self = FormatText::Str(format!("{}", now.rfc3339()))
|
||||||
"{:?}",
|
|
||||||
now.strftime("[%d/%b/%Y:%H:%M:%S %z]").unwrap()
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
FormatText::RequestHeader(ref name) => {
|
FormatText::RequestHeader(ref name) => {
|
||||||
let s = if let Some(val) = req.headers().get(name) {
|
let s = if let Some(val) = req.headers().get(name) {
|
||||||
@ -547,4 +544,29 @@ mod tests {
|
|||||||
assert!(s.contains("200 1024"));
|
assert!(s.contains("200 1024"));
|
||||||
assert!(s.contains("ACTIX-WEB"));
|
assert!(s.contains("ACTIX-WEB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_request_time_format() {
|
||||||
|
let mut format = Format::new("%t");
|
||||||
|
let req = TestRequest::default().to_srv_request();
|
||||||
|
|
||||||
|
let now = time::now();
|
||||||
|
for unit in &mut format.0 {
|
||||||
|
unit.render_request(now, &req);
|
||||||
|
}
|
||||||
|
|
||||||
|
let resp = HttpResponse::build(StatusCode::OK).force_close().finish();
|
||||||
|
for unit in &mut format.0 {
|
||||||
|
unit.render_response(&resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
let render = |fmt: &mut Formatter| {
|
||||||
|
for unit in &format.0 {
|
||||||
|
unit.render(fmt, 1024, now)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
let s = format!("{}", FormatDisplay(&render));
|
||||||
|
assert!(s.contains(&format!("{}", now.rfc3339())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ pub struct HttpRequest(pub(crate) Rc<HttpRequestInner>);
|
|||||||
pub(crate) struct HttpRequestInner {
|
pub(crate) struct HttpRequestInner {
|
||||||
pub(crate) head: Message<RequestHead>,
|
pub(crate) head: Message<RequestHead>,
|
||||||
pub(crate) path: Path<Url>,
|
pub(crate) path: Path<Url>,
|
||||||
|
pub(crate) payload: Payload,
|
||||||
pub(crate) app_data: Rc<Extensions>,
|
pub(crate) app_data: Rc<Extensions>,
|
||||||
rmap: Rc<ResourceMap>,
|
rmap: Rc<ResourceMap>,
|
||||||
config: AppConfig,
|
config: AppConfig,
|
||||||
@ -31,6 +32,7 @@ impl HttpRequest {
|
|||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
path: Path<Url>,
|
path: Path<Url>,
|
||||||
head: Message<RequestHead>,
|
head: Message<RequestHead>,
|
||||||
|
payload: Payload,
|
||||||
rmap: Rc<ResourceMap>,
|
rmap: Rc<ResourceMap>,
|
||||||
config: AppConfig,
|
config: AppConfig,
|
||||||
app_data: Rc<Extensions>,
|
app_data: Rc<Extensions>,
|
||||||
@ -39,6 +41,7 @@ impl HttpRequest {
|
|||||||
HttpRequest(Rc::new(HttpRequestInner {
|
HttpRequest(Rc::new(HttpRequestInner {
|
||||||
head,
|
head,
|
||||||
path,
|
path,
|
||||||
|
payload,
|
||||||
rmap,
|
rmap,
|
||||||
config,
|
config,
|
||||||
app_data,
|
app_data,
|
||||||
@ -325,6 +328,10 @@ impl HttpRequestPool {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn clear(&self) {
|
||||||
|
self.0.borrow_mut().clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -64,7 +64,7 @@ where
|
|||||||
config: Arc<Mutex<Config>>,
|
config: Arc<Mutex<Config>>,
|
||||||
backlog: i32,
|
backlog: i32,
|
||||||
sockets: Vec<Socket>,
|
sockets: Vec<Socket>,
|
||||||
builder: Option<ServerBuilder>,
|
builder: ServerBuilder,
|
||||||
_t: PhantomData<(S, B)>,
|
_t: PhantomData<(S, B)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ where
|
|||||||
})),
|
})),
|
||||||
backlog: 1024,
|
backlog: 1024,
|
||||||
sockets: Vec::new(),
|
sockets: Vec::new(),
|
||||||
builder: Some(ServerBuilder::default()),
|
builder: ServerBuilder::default(),
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ where
|
|||||||
/// By default http server uses number of available logical cpu as threads
|
/// By default http server uses number of available logical cpu as threads
|
||||||
/// count.
|
/// count.
|
||||||
pub fn workers(mut self, num: usize) -> Self {
|
pub fn workers(mut self, num: usize) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().workers(num));
|
self.builder = self.builder.workers(num);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ where
|
|||||||
/// This method should be called before `bind()` method call.
|
/// This method should be called before `bind()` method call.
|
||||||
pub fn backlog(mut self, backlog: i32) -> Self {
|
pub fn backlog(mut self, backlog: i32) -> Self {
|
||||||
self.backlog = backlog;
|
self.backlog = backlog;
|
||||||
self.builder = Some(self.builder.take().unwrap().backlog(backlog));
|
self.builder = self.builder.backlog(backlog);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ where
|
|||||||
///
|
///
|
||||||
/// By default max connections is set to a 25k.
|
/// By default max connections is set to a 25k.
|
||||||
pub fn maxconn(mut self, num: usize) -> Self {
|
pub fn maxconn(mut self, num: usize) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().maxconn(num));
|
self.builder = self.builder.maxconn(num);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ where
|
|||||||
///
|
///
|
||||||
/// By default max connections is set to a 256.
|
/// By default max connections is set to a 256.
|
||||||
pub fn maxconnrate(mut self, num: usize) -> Self {
|
pub fn maxconnrate(mut self, num: usize) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().maxconnrate(num));
|
self.builder = self.builder.maxconnrate(num);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,13 +190,13 @@ where
|
|||||||
|
|
||||||
/// Stop actix system.
|
/// Stop actix system.
|
||||||
pub fn system_exit(mut self) -> Self {
|
pub fn system_exit(mut self) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().system_exit());
|
self.builder = self.builder.system_exit();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable signal handling
|
/// Disable signal handling
|
||||||
pub fn disable_signals(mut self) -> Self {
|
pub fn disable_signals(mut self) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().disable_signals());
|
self.builder = self.builder.disable_signals();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ where
|
|||||||
///
|
///
|
||||||
/// By default shutdown timeout sets to 30 seconds.
|
/// By default shutdown timeout sets to 30 seconds.
|
||||||
pub fn shutdown_timeout(mut self, sec: u64) -> Self {
|
pub fn shutdown_timeout(mut self, sec: u64) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().shutdown_timeout(sec));
|
self.builder = self.builder.shutdown_timeout(sec);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ where
|
|||||||
scheme: "http",
|
scheme: "http",
|
||||||
});
|
});
|
||||||
|
|
||||||
self.builder = Some(self.builder.take().unwrap().listen(
|
self.builder = self.builder.listen(
|
||||||
format!("actix-web-service-{}", addr),
|
format!("actix-web-service-{}", addr),
|
||||||
lst,
|
lst,
|
||||||
move || {
|
move || {
|
||||||
@ -250,8 +250,7 @@ where
|
|||||||
.client_timeout(c.client_timeout)
|
.client_timeout(c.client_timeout)
|
||||||
.finish(factory())
|
.finish(factory())
|
||||||
},
|
},
|
||||||
)?);
|
)?;
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,20 +259,19 @@ where
|
|||||||
///
|
///
|
||||||
/// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
pub fn listen_ssl(
|
pub fn listen_ssl(
|
||||||
mut self,
|
self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
builder: SslAcceptorBuilder,
|
builder: SslAcceptorBuilder,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
self.listen_ssl_inner(lst, openssl_acceptor(builder)?)?;
|
self.listen_ssl_inner(lst, openssl_acceptor(builder)?)
|
||||||
Ok(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ssl")]
|
#[cfg(feature = "ssl")]
|
||||||
fn listen_ssl_inner(
|
fn listen_ssl_inner(
|
||||||
&mut self,
|
mut self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
acceptor: SslAcceptor,
|
acceptor: SslAcceptor,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<Self> {
|
||||||
use actix_server::ssl::{OpensslAcceptor, SslError};
|
use actix_server::ssl::{OpensslAcceptor, SslError};
|
||||||
|
|
||||||
let acceptor = OpensslAcceptor::new(acceptor);
|
let acceptor = OpensslAcceptor::new(acceptor);
|
||||||
@ -285,7 +283,7 @@ where
|
|||||||
scheme: "https",
|
scheme: "https",
|
||||||
});
|
});
|
||||||
|
|
||||||
self.builder = Some(self.builder.take().unwrap().listen(
|
self.builder = self.builder.listen(
|
||||||
format!("actix-web-service-{}", addr),
|
format!("actix-web-service-{}", addr),
|
||||||
lst,
|
lst,
|
||||||
move || {
|
move || {
|
||||||
@ -300,8 +298,8 @@ where
|
|||||||
.map_init_err(|_| ()),
|
.map_init_err(|_| ()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)?);
|
)?;
|
||||||
Ok(())
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
@ -309,20 +307,19 @@ where
|
|||||||
///
|
///
|
||||||
/// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
pub fn listen_rustls(
|
pub fn listen_rustls(
|
||||||
mut self,
|
self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
config: RustlsServerConfig,
|
config: RustlsServerConfig,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
self.listen_rustls_inner(lst, config)?;
|
self.listen_rustls_inner(lst, config)
|
||||||
Ok(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
fn listen_rustls_inner(
|
fn listen_rustls_inner(
|
||||||
&mut self,
|
mut self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
mut config: RustlsServerConfig,
|
mut config: RustlsServerConfig,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<Self> {
|
||||||
use actix_server::ssl::{RustlsAcceptor, SslError};
|
use actix_server::ssl::{RustlsAcceptor, SslError};
|
||||||
|
|
||||||
let protos = vec!["h2".to_string().into(), "http/1.1".to_string().into()];
|
let protos = vec!["h2".to_string().into(), "http/1.1".to_string().into()];
|
||||||
@ -337,7 +334,7 @@ where
|
|||||||
scheme: "https",
|
scheme: "https",
|
||||||
});
|
});
|
||||||
|
|
||||||
self.builder = Some(self.builder.take().unwrap().listen(
|
self.builder = self.builder.listen(
|
||||||
format!("actix-web-service-{}", addr),
|
format!("actix-web-service-{}", addr),
|
||||||
lst,
|
lst,
|
||||||
move || {
|
move || {
|
||||||
@ -352,8 +349,8 @@ where
|
|||||||
.map_init_err(|_| ()),
|
.map_init_err(|_| ()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)?);
|
)?;
|
||||||
Ok(())
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The socket address to bind
|
/// The socket address to bind
|
||||||
@ -416,7 +413,7 @@ where
|
|||||||
let acceptor = openssl_acceptor(builder)?;
|
let acceptor = openssl_acceptor(builder)?;
|
||||||
|
|
||||||
for lst in sockets {
|
for lst in sockets {
|
||||||
self.listen_ssl_inner(lst, acceptor.clone())?;
|
self = self.listen_ssl_inner(lst, acceptor.clone())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
@ -433,7 +430,7 @@ where
|
|||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
let sockets = self.bind2(addr)?;
|
let sockets = self.bind2(addr)?;
|
||||||
for lst in sockets {
|
for lst in sockets {
|
||||||
self.listen_rustls_inner(lst, config.clone())?;
|
self = self.listen_rustls_inner(lst, config.clone())?;
|
||||||
}
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
@ -473,8 +470,8 @@ where
|
|||||||
/// sys.run() // <- Run actix system, this method starts all async processes
|
/// sys.run() // <- Run actix system, this method starts all async processes
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn start(mut self) -> Server {
|
pub fn start(self) -> Server {
|
||||||
self.builder.take().unwrap().start()
|
self.builder.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn new thread and start listening for incoming connections.
|
/// Spawn new thread and start listening for incoming connections.
|
||||||
|
@ -50,45 +50,46 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServiceRequest {
|
/// An service http request
|
||||||
req: HttpRequest,
|
///
|
||||||
payload: Payload,
|
/// ServiceRequest allows mutable access to request's internal structures
|
||||||
}
|
pub struct ServiceRequest(HttpRequest);
|
||||||
|
|
||||||
impl ServiceRequest {
|
impl ServiceRequest {
|
||||||
/// Construct service request from parts
|
/// Construct service request
|
||||||
pub(crate) fn from_parts(req: HttpRequest, payload: Payload) -> Self {
|
pub(crate) fn new(req: HttpRequest) -> Self {
|
||||||
ServiceRequest { req, payload }
|
ServiceRequest(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deconstruct request into parts
|
/// Deconstruct request into parts
|
||||||
pub fn into_parts(self) -> (HttpRequest, Payload) {
|
pub fn into_parts(mut self) -> (HttpRequest, Payload) {
|
||||||
(self.req, self.payload)
|
let pl = Rc::get_mut(&mut (self.0).0).unwrap().payload.take();
|
||||||
|
(self.0, pl)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create service response
|
/// Create service response
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_response<B, R: Into<Response<B>>>(self, res: R) -> ServiceResponse<B> {
|
pub fn into_response<B, R: Into<Response<B>>>(self, res: R) -> ServiceResponse<B> {
|
||||||
ServiceResponse::new(self.req, res.into())
|
ServiceResponse::new(self.0, res.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create service response for error
|
/// Create service response for error
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn error_response<B, E: Into<Error>>(self, err: E) -> ServiceResponse<B> {
|
pub fn error_response<B, E: Into<Error>>(self, err: E) -> ServiceResponse<B> {
|
||||||
let res: Response = err.into().into();
|
let res: Response = err.into().into();
|
||||||
ServiceResponse::new(self.req, res.into_body())
|
ServiceResponse::new(self.0, res.into_body())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method returns reference to the request head
|
/// This method returns reference to the request head
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn head(&self) -> &RequestHead {
|
pub fn head(&self) -> &RequestHead {
|
||||||
&self.req.head()
|
&self.0.head()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method returns reference to the request head
|
/// This method returns reference to the request head
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn head_mut(&mut self) -> &mut RequestHead {
|
pub fn head_mut(&mut self) -> &mut RequestHead {
|
||||||
self.req.head_mut()
|
self.0.head_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request's uri.
|
/// Request's uri.
|
||||||
@ -164,34 +165,39 @@ impl ServiceRequest {
|
|||||||
/// access the matched value for that segment.
|
/// access the matched value for that segment.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn match_info(&self) -> &Path<Url> {
|
pub fn match_info(&self) -> &Path<Url> {
|
||||||
self.req.match_info()
|
self.0.match_info()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
|
pub fn match_info_mut(&mut self) -> &mut Path<Url> {
|
||||||
self.req.match_info_mut()
|
self.0.match_info_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Service configuration
|
/// Service configuration
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn app_config(&self) -> &AppConfig {
|
pub fn app_config(&self) -> &AppConfig {
|
||||||
self.req.app_config()
|
self.0.app_config()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an application data stored with `App::data()` method during
|
/// Get an application data stored with `App::data()` method during
|
||||||
/// application configuration.
|
/// application configuration.
|
||||||
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
|
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
|
||||||
if let Some(st) = self.req.0.app_data.get::<Data<T>>() {
|
if let Some(st) = (self.0).0.app_data.get::<Data<T>>() {
|
||||||
Some(st.clone())
|
Some(st.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set request payload.
|
||||||
|
pub fn set_payload(&mut self, payload: Payload) {
|
||||||
|
Rc::get_mut(&mut (self.0).0).unwrap().payload = payload;
|
||||||
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Set new app data container
|
/// Set new app data container
|
||||||
pub fn set_data_container(&mut self, extensions: Rc<Extensions>) {
|
pub fn set_data_container(&mut self, extensions: Rc<Extensions>) {
|
||||||
Rc::get_mut(&mut self.req.0).unwrap().app_data = extensions;
|
Rc::get_mut(&mut (self.0).0).unwrap().app_data = extensions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,18 +219,18 @@ impl HttpMessage for ServiceRequest {
|
|||||||
/// Request extensions
|
/// Request extensions
|
||||||
#[inline]
|
#[inline]
|
||||||
fn extensions(&self) -> Ref<Extensions> {
|
fn extensions(&self) -> Ref<Extensions> {
|
||||||
self.req.extensions()
|
self.0.extensions()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutable reference to a the request's extensions
|
/// Mutable reference to a the request's extensions
|
||||||
#[inline]
|
#[inline]
|
||||||
fn extensions_mut(&self) -> RefMut<Extensions> {
|
fn extensions_mut(&self) -> RefMut<Extensions> {
|
||||||
self.req.extensions_mut()
|
self.0.extensions_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn take_payload(&mut self) -> Payload<Self::Stream> {
|
fn take_payload(&mut self) -> Payload<Self::Stream> {
|
||||||
std::mem::replace(&mut self.payload, Payload::None)
|
Rc::get_mut(&mut (self.0).0).unwrap().payload.take()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
52
src/test.rs
52
src/test.rs
@ -2,7 +2,7 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use actix_http::http::header::{Header, HeaderName, IntoHeaderValue};
|
use actix_http::http::header::{ContentType, Header, HeaderName, IntoHeaderValue};
|
||||||
use actix_http::http::{HttpTryFrom, Method, StatusCode, Uri, Version};
|
use actix_http::http::{HttpTryFrom, Method, StatusCode, Uri, Version};
|
||||||
use actix_http::test::TestRequest as HttpTestRequest;
|
use actix_http::test::TestRequest as HttpTestRequest;
|
||||||
use actix_http::{cookie::Cookie, Extensions, Request};
|
use actix_http::{cookie::Cookie, Extensions, Request};
|
||||||
@ -14,6 +14,7 @@ use bytes::{Bytes, BytesMut};
|
|||||||
use futures::future::{lazy, ok, Future, IntoFuture};
|
use futures::future::{lazy, ok, Future, IntoFuture};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
use serde::Serialize;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
pub use actix_http::test::TestBuffer;
|
pub use actix_http::test::TestBuffer;
|
||||||
@ -248,7 +249,7 @@ where
|
|||||||
/// .header(header::CONTENT_TYPE, "application/json")
|
/// .header(header::CONTENT_TYPE, "application/json")
|
||||||
/// .to_request();
|
/// .to_request();
|
||||||
///
|
///
|
||||||
/// let resp = call_service(&mut srv, req);
|
/// let resp = test::call_service(&mut app, req);
|
||||||
/// let result = test::read_body(resp);
|
/// let result = test::read_body(resp);
|
||||||
/// assert_eq!(result, Bytes::from_static(b"welcome!"));
|
/// assert_eq!(result, Bytes::from_static(b"welcome!"));
|
||||||
/// }
|
/// }
|
||||||
@ -477,6 +478,16 @@ impl TestRequest {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialize `data` to JSON and set it as the request payload. The `Content-Type` header is
|
||||||
|
/// set to `application/json`.
|
||||||
|
pub fn set_json<T: Serialize>(mut self, data: &T) -> Self {
|
||||||
|
let bytes =
|
||||||
|
serde_json::to_string(data).expect("Failed to serialize test data to json");
|
||||||
|
self.req.set_payload(bytes);
|
||||||
|
self.req.set(ContentType::json());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set application data. This is equivalent of `App::data()` method
|
/// Set application data. This is equivalent of `App::data()` method
|
||||||
/// for testing purpose.
|
/// for testing purpose.
|
||||||
pub fn data<T: 'static>(mut self, data: T) -> Self {
|
pub fn data<T: 'static>(mut self, data: T) -> Self {
|
||||||
@ -501,16 +512,15 @@ impl TestRequest {
|
|||||||
let (head, payload) = self.req.finish().into_parts();
|
let (head, payload) = self.req.finish().into_parts();
|
||||||
self.path.get_mut().update(&head.uri);
|
self.path.get_mut().update(&head.uri);
|
||||||
|
|
||||||
let req = HttpRequest::new(
|
ServiceRequest::new(HttpRequest::new(
|
||||||
self.path,
|
self.path,
|
||||||
head,
|
head,
|
||||||
|
payload,
|
||||||
Rc::new(self.rmap),
|
Rc::new(self.rmap),
|
||||||
AppConfig::new(self.config),
|
AppConfig::new(self.config),
|
||||||
Rc::new(self.app_data),
|
Rc::new(self.app_data),
|
||||||
HttpRequestPool::create(),
|
HttpRequestPool::create(),
|
||||||
);
|
))
|
||||||
|
|
||||||
ServiceRequest::from_parts(req, payload)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Complete request creation and generate `ServiceResponse` instance
|
/// Complete request creation and generate `ServiceResponse` instance
|
||||||
@ -520,12 +530,13 @@ impl TestRequest {
|
|||||||
|
|
||||||
/// Complete request creation and generate `HttpRequest` instance
|
/// Complete request creation and generate `HttpRequest` instance
|
||||||
pub fn to_http_request(mut self) -> HttpRequest {
|
pub fn to_http_request(mut self) -> HttpRequest {
|
||||||
let (head, _) = self.req.finish().into_parts();
|
let (head, payload) = self.req.finish().into_parts();
|
||||||
self.path.get_mut().update(&head.uri);
|
self.path.get_mut().update(&head.uri);
|
||||||
|
|
||||||
HttpRequest::new(
|
HttpRequest::new(
|
||||||
self.path,
|
self.path,
|
||||||
head,
|
head,
|
||||||
|
payload,
|
||||||
Rc::new(self.rmap),
|
Rc::new(self.rmap),
|
||||||
AppConfig::new(self.config),
|
AppConfig::new(self.config),
|
||||||
Rc::new(self.app_data),
|
Rc::new(self.app_data),
|
||||||
@ -541,6 +552,7 @@ impl TestRequest {
|
|||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
self.path,
|
self.path,
|
||||||
head,
|
head,
|
||||||
|
Payload::None,
|
||||||
Rc::new(self.rmap),
|
Rc::new(self.rmap),
|
||||||
AppConfig::new(self.config),
|
AppConfig::new(self.config),
|
||||||
Rc::new(self.app_data),
|
Rc::new(self.app_data),
|
||||||
@ -553,6 +565,7 @@ impl TestRequest {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use actix_http::httpmessage::HttpMessage;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
@ -657,6 +670,31 @@ mod tests {
|
|||||||
assert_eq!(&result.id, "12345");
|
assert_eq!(&result.id, "12345");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_request_response_json() {
|
||||||
|
let mut app = init_service(App::new().service(web::resource("/people").route(
|
||||||
|
web::post().to(|person: web::Json<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_json(&payload)
|
||||||
|
.to_request();
|
||||||
|
|
||||||
|
assert_eq!(req.content_type(), "application/json");
|
||||||
|
|
||||||
|
let result: Person = read_response_json(&mut app, req);
|
||||||
|
assert_eq!(&result.id, "12345");
|
||||||
|
assert_eq!(&result.name, "User name");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_async_with_block() {
|
fn test_async_with_block() {
|
||||||
fn async_with_block() -> impl Future<Item = HttpResponse, Error = Error> {
|
fn async_with_block() -> impl Future<Item = HttpResponse, Error = Error> {
|
||||||
|
Reference in New Issue
Block a user