mirror of https://github.com/fafhrd91/actix-web
commit
af32a06cba
|
@ -9,6 +9,7 @@ guide/build/
|
||||||
*.pid
|
*.pid
|
||||||
*.sock
|
*.sock
|
||||||
*~
|
*~
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
using `App::data`. [#1610]
|
using `App::data`. [#1610]
|
||||||
* `web::Path` now has a public representation: `web::Path(pub T)` that enables
|
* `web::Path` now has a public representation: `web::Path(pub T)` that enables
|
||||||
destructuring. [#1594]
|
destructuring. [#1594]
|
||||||
|
* `ServiceRequest::app_data` allows retrieval of non-Data data without splitting into parts to
|
||||||
|
access `HttpRequest` which already allows this. [#1618]
|
||||||
* MSRV is now 1.42.0.
|
* MSRV is now 1.42.0.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -14,6 +16,7 @@
|
||||||
[#1594]: https://github.com/actix/actix-web/pull/1594
|
[#1594]: https://github.com/actix/actix-web/pull/1594
|
||||||
[#1609]: https://github.com/actix/actix-web/pull/1609
|
[#1609]: https://github.com/actix/actix-web/pull/1609
|
||||||
[#1610]: https://github.com/actix/actix-web/pull/1610
|
[#1610]: https://github.com/actix/actix-web/pull/1610
|
||||||
|
[#1618]: https://github.com/actix/actix-web/pull/1610
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0-beta.1 - 2020-07-13
|
## 3.0.0-beta.1 - 2020-07-13
|
||||||
|
|
|
@ -124,6 +124,10 @@ actix-files = { path = "actix-files" }
|
||||||
actix-multipart = { path = "actix-multipart" }
|
actix-multipart = { path = "actix-multipart" }
|
||||||
awc = { path = "awc" }
|
awc = { path = "awc" }
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "client"
|
||||||
|
required-features = ["rustls"]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "server"
|
name = "server"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
|
### Fixed
|
||||||
|
* Memory leak of `client::pool::ConnectorPoolSupport`. [#1626]
|
||||||
|
|
||||||
|
[#1626]: https://github.com/actix/actix-web/pull/1626
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-beta.2 - 2020-07-21
|
## [2.0.0-beta.2] - 2020-07-21
|
||||||
### Fixed
|
### Fixed
|
||||||
* Potential UB in h1 decoder using uninitialized memory. [#1614]
|
* Potential UB in h1 decoder using uninitialized memory. [#1614]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::cell::RefCell;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::Rc;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
@ -65,8 +65,8 @@ where
|
||||||
|
|
||||||
// start support future
|
// start support future
|
||||||
actix_rt::spawn(ConnectorPoolSupport {
|
actix_rt::spawn(ConnectorPoolSupport {
|
||||||
connector: connector_rc.clone(),
|
connector: Rc::clone(&connector_rc),
|
||||||
inner: Rc::downgrade(&inner_rc),
|
inner: Rc::clone(&inner_rc),
|
||||||
});
|
});
|
||||||
|
|
||||||
ConnectionPool(connector_rc, inner_rc)
|
ConnectionPool(connector_rc, inner_rc)
|
||||||
|
@ -82,6 +82,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, Io> Drop for ConnectionPool<T, Io> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
// wake up the ConnectorPoolSupport when dropping so it can exit properly.
|
||||||
|
self.1.borrow().waker.wake();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T, Io> Service for ConnectionPool<T, Io>
|
impl<T, Io> Service for ConnectionPool<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + Unpin + 'static,
|
Io: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||||
|
@ -421,7 +428,7 @@ where
|
||||||
Io: AsyncRead + AsyncWrite + Unpin + 'static,
|
Io: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||||
{
|
{
|
||||||
connector: T,
|
connector: T,
|
||||||
inner: Weak<RefCell<Inner<Io>>>,
|
inner: Rc<RefCell<Inner<Io>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, Io> Future for ConnectorPoolSupport<T, Io>
|
impl<T, Io> Future for ConnectorPoolSupport<T, Io>
|
||||||
|
@ -435,55 +442,57 @@ where
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let this = self.project();
|
let this = self.project();
|
||||||
|
|
||||||
if let Some(this_inner) = this.inner.upgrade() {
|
if Rc::strong_count(this.inner) == 1 {
|
||||||
let mut inner = this_inner.as_ref().borrow_mut();
|
// If we are last copy of Inner<Io> it means the ConnectionPool is already gone
|
||||||
inner.waker.register(cx.waker());
|
// and we are safe to exit.
|
||||||
|
return Poll::Ready(());
|
||||||
|
}
|
||||||
|
|
||||||
// check waiters
|
let mut inner = this.inner.borrow_mut();
|
||||||
loop {
|
inner.waker.register(cx.waker());
|
||||||
let (key, token) = {
|
|
||||||
if let Some((key, token)) = inner.waiters_queue.get_index(0) {
|
|
||||||
(key.clone(), *token)
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if inner.waiters.get(token).unwrap().is_none() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
match inner.acquire(&key, cx) {
|
// check waiters
|
||||||
Acquire::NotAvailable => break,
|
loop {
|
||||||
Acquire::Acquired(io, created) => {
|
let (key, token) = {
|
||||||
let tx = inner.waiters.get_mut(token).unwrap().take().unwrap().1;
|
if let Some((key, token)) = inner.waiters_queue.get_index(0) {
|
||||||
if let Err(conn) = tx.send(Ok(IoConnection::new(
|
(key.clone(), *token)
|
||||||
io,
|
} else {
|
||||||
created,
|
break;
|
||||||
Some(Acquired(key.clone(), Some(this_inner.clone()))),
|
|
||||||
))) {
|
|
||||||
let (io, created) = conn.unwrap().into_inner();
|
|
||||||
inner.release_conn(&key, io, created);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Acquire::Available => {
|
|
||||||
let (connect, tx) =
|
|
||||||
inner.waiters.get_mut(token).unwrap().take().unwrap();
|
|
||||||
OpenWaitingConnection::spawn(
|
|
||||||
key.clone(),
|
|
||||||
tx,
|
|
||||||
this_inner.clone(),
|
|
||||||
this.connector.call(connect),
|
|
||||||
inner.config.clone(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let _ = inner.waiters_queue.swap_remove_index(0);
|
};
|
||||||
|
if inner.waiters.get(token).unwrap().is_none() {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Pending
|
match inner.acquire(&key, cx) {
|
||||||
} else {
|
Acquire::NotAvailable => break,
|
||||||
Poll::Ready(())
|
Acquire::Acquired(io, created) => {
|
||||||
|
let tx = inner.waiters.get_mut(token).unwrap().take().unwrap().1;
|
||||||
|
if let Err(conn) = tx.send(Ok(IoConnection::new(
|
||||||
|
io,
|
||||||
|
created,
|
||||||
|
Some(Acquired(key.clone(), Some(this.inner.clone()))),
|
||||||
|
))) {
|
||||||
|
let (io, created) = conn.unwrap().into_inner();
|
||||||
|
inner.release_conn(&key, io, created);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Acquire::Available => {
|
||||||
|
let (connect, tx) =
|
||||||
|
inner.waiters.get_mut(token).unwrap().take().unwrap();
|
||||||
|
OpenWaitingConnection::spawn(
|
||||||
|
key.clone(),
|
||||||
|
tx,
|
||||||
|
this.inner.clone(),
|
||||||
|
this.connector.call(connect),
|
||||||
|
inner.config.clone(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let _ = inner.waiters_queue.swap_remove_index(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Poll::Pending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
# do not track rendered graphs
|
||||||
|
*.png
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Actix Ecosystem Dependency Graphs
|
||||||
|
|
||||||
|
See rendered versions of these dot graphs [on the wiki](https://github.com/actix/actix-web/wiki/Dependency-Graph).
|
||||||
|
|
||||||
|
## Rendering
|
||||||
|
|
||||||
|
Dot graphs were rendered using the `dot` command from [GraphViz](https://www.graphviz.org/doc/info/command.html):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
for f in $(ls docs/graphs/*.dot | xargs); do dot $f -Tpng -o${f:r}.png; done
|
||||||
|
```
|
|
@ -0,0 +1,25 @@
|
||||||
|
digraph {
|
||||||
|
subgraph cluster_net {
|
||||||
|
label="actix/actix-net";
|
||||||
|
"actix-codec"
|
||||||
|
"actix-connect"
|
||||||
|
"actix-macros"
|
||||||
|
"actix-rt"
|
||||||
|
"actix-server"
|
||||||
|
"actix-service"
|
||||||
|
"actix-testing"
|
||||||
|
"actix-threadpool"
|
||||||
|
"actix-tls"
|
||||||
|
"actix-tracing"
|
||||||
|
"actix-utils"
|
||||||
|
"actix-router"
|
||||||
|
}
|
||||||
|
|
||||||
|
"actix-utils" -> { "actix-service" "actix-rt" "actix-codec" }
|
||||||
|
"actix-tracing" -> { "actix-service" }
|
||||||
|
"actix-tls" -> { "actix-service" "actix-codec" "actix-utils" "actix-rt" }
|
||||||
|
"actix-testing" -> { "actix-rt" "actix-macros" "actix-server" "actix-service" }
|
||||||
|
"actix-server" -> { "actix-service" "actix-rt" "actix-codec" "actix-utils" }
|
||||||
|
"actix-rt" -> { "actix-macros" "actix-threadpool" }
|
||||||
|
"actix-connect" -> { "actix-service" "actix-codec" "actix-utils" "actix-rt" }
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
digraph {
|
||||||
|
subgraph cluster_web {
|
||||||
|
label="actix/actix-web"
|
||||||
|
"awc"
|
||||||
|
"actix-web"
|
||||||
|
"actix-files"
|
||||||
|
"actix-http"
|
||||||
|
"actix-multipart"
|
||||||
|
"actix-web-actors"
|
||||||
|
"actix-web-codegen"
|
||||||
|
}
|
||||||
|
|
||||||
|
"actix-web" -> { "actix-codec" "actix-service" "actix-utils" "actix-router" "actix-rt" "actix-server" "actix-testing" "actix-macros" "actix-threadpool" "actix-tls" "actix-web-codegen" "actix-http" "awc" }
|
||||||
|
"awc" -> { "actix-codec" "actix-service" "actix-http" "actix-rt" }
|
||||||
|
"actix-web-actors" -> { "actix" "actix-web" "actix-http" "actix-codec" }
|
||||||
|
"actix-multipart" -> { "actix-web" "actix-service" "actix-utils" }
|
||||||
|
"actix-http" -> { "actix-service" "actix-codec" "actix-connect" "actix-utils" "actix-rt" "actix-threadpool" }
|
||||||
|
"actix-http" -> { "actix" "actix-tls" }[color=blue] // optional
|
||||||
|
"actix-files" -> { "actix-web" "actix-http" }
|
||||||
|
|
||||||
|
// net
|
||||||
|
|
||||||
|
"actix-utils" -> { "actix-service" "actix-rt" "actix-codec" }
|
||||||
|
"actix-tracing" -> { "actix-service" }
|
||||||
|
"actix-tls" -> { "actix-service" "actix-codec" "actix-utils" "actix-rt" }
|
||||||
|
"actix-testing" -> { "actix-rt" "actix-macros" "actix-server" "actix-service" }
|
||||||
|
"actix-server" -> { "actix-service" "actix-rt" "actix-codec" "actix-utils" }
|
||||||
|
"actix-rt" -> { "actix-macros" "actix-threadpool" }
|
||||||
|
"actix-connect" -> { "actix-service" "actix-codec" "actix-utils" "actix-rt" }
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
digraph {
|
||||||
|
subgraph cluster_web {
|
||||||
|
label="actix/actix-web"
|
||||||
|
"awc"
|
||||||
|
"actix-web"
|
||||||
|
"actix-files"
|
||||||
|
"actix-http"
|
||||||
|
"actix-multipart"
|
||||||
|
"actix-web-actors"
|
||||||
|
"actix-web-codegen"
|
||||||
|
}
|
||||||
|
|
||||||
|
"actix-web" -> { "actix-web-codegen" "actix-http" "awc" }
|
||||||
|
"awc" -> { "actix-http" }
|
||||||
|
"actix-web-actors" -> { "actix" "actix-web" "actix-http" }
|
||||||
|
"actix-multipart" -> { "actix-web" }
|
||||||
|
"actix-http" -> { "actix" }[color=blue] // optional
|
||||||
|
"actix-files" -> { "actix-web" "actix-http" }
|
||||||
|
}
|
|
@ -12,7 +12,6 @@ use actix_router::{IntoPattern, Path, Resource, ResourceDef, Url};
|
||||||
use actix_service::{IntoServiceFactory, ServiceFactory};
|
use actix_service::{IntoServiceFactory, ServiceFactory};
|
||||||
|
|
||||||
use crate::config::{AppConfig, AppService};
|
use crate::config::{AppConfig, AppService};
|
||||||
use crate::data::Data;
|
|
||||||
use crate::dev::insert_slash;
|
use crate::dev::insert_slash;
|
||||||
use crate::guard::Guard;
|
use crate::guard::Guard;
|
||||||
use crate::info::ConnectionInfo;
|
use crate::info::ConnectionInfo;
|
||||||
|
@ -226,12 +225,11 @@ impl ServiceRequest {
|
||||||
self.0.app_config()
|
self.0.app_config()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an application data stored with `App::data()` method during
|
/// Counterpart to [`HttpRequest::app_data`](../struct.HttpRequest.html#method.app_data).
|
||||||
/// application configuration.
|
pub fn app_data<T: 'static>(&self) -> Option<&T> {
|
||||||
pub fn app_data<T: 'static>(&self) -> Option<Data<T>> {
|
|
||||||
for container in (self.0).0.app_data.iter().rev() {
|
for container in (self.0).0.app_data.iter().rev() {
|
||||||
if let Some(data) = container.get::<Data<T>>() {
|
if let Some(data) = container.get::<T>() {
|
||||||
return Some(Data::clone(&data));
|
return Some(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,6 +593,28 @@ mod tests {
|
||||||
let resp = srv.call(req).await.unwrap();
|
let resp = srv.call(req).await.unwrap();
|
||||||
assert_eq!(resp.status(), http::StatusCode::NOT_FOUND);
|
assert_eq!(resp.status(), http::StatusCode::NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_service_data() {
|
||||||
|
let mut srv = init_service(
|
||||||
|
App::new()
|
||||||
|
.data(42u32)
|
||||||
|
.service(web::service("/test").name("test").finish(
|
||||||
|
|req: ServiceRequest| {
|
||||||
|
assert_eq!(
|
||||||
|
req.app_data::<web::Data<u32>>().unwrap().as_ref(),
|
||||||
|
&42
|
||||||
|
);
|
||||||
|
ok(req.into_response(HttpResponse::Ok().finish()))
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let req = TestRequest::with_uri("/test").to_request();
|
||||||
|
let resp = srv.call(req).await.unwrap();
|
||||||
|
assert_eq!(resp.status(), http::StatusCode::OK);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fmt_debug() {
|
fn test_fmt_debug() {
|
||||||
let req = TestRequest::get()
|
let req = TestRequest::get()
|
||||||
|
|
Loading…
Reference in New Issue