1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

Use immutable reference of service state. Update awc dns resolver. (#1905)

This commit is contained in:
fakeshadow
2021-02-06 17:00:40 -08:00
committed by GitHub
parent 20cf0094e5
commit 41bc04b1c4
65 changed files with 497 additions and 538 deletions

View File

@ -5,6 +5,9 @@
* `ClientRequest::insert_header` method which allows using typed headers. [#1869]
* `ClientRequest::append_header` method which allows using typed headers. [#1869]
### Changed
* Relax default timeout for `Connector` to 5 seconds(original 1 second). [#1905]
### Removed
* `ClientRequest::set`; use `ClientRequest::insert_header`. [#1869]
* `ClientRequest::set_header`; use `ClientRequest::insert_header`. [#1869]
@ -12,6 +15,7 @@
* `ClientRequest::header`; use `ClientRequest::append_header`. [#1869]
[#1869]: https://github.com/actix/actix-web/pull/1869
[#1905]: https://github.com/actix/actix-web/pull/1905
## 3.0.0-beta.1 - 2021-01-07

View File

@ -38,9 +38,9 @@ compress = ["actix-http/compress"]
[dependencies]
actix-codec = "0.4.0-beta.1"
actix-service = "2.0.0-beta.3"
actix-service = "2.0.0-beta.4"
actix-http = "3.0.0-beta.1"
actix-rt = "=2.0.0-beta.2"
actix-rt = "2"
base64 = "0.13"
bytes = "1"
@ -58,15 +58,12 @@ open-ssl = { version = "0.10", package = "openssl", optional = true }
rust-tls = { version = "0.19.0", package = "rustls", optional = true, features = ["dangerous_configuration"] }
[dev-dependencies]
# TODO: actix is temporary added as dev dep for actix-macro reason.
# Can be removed when it does not impact tests.
actix = "0.11.0-beta.1"
actix-web = { version = "4.0.0-beta.1", features = ["openssl"] }
actix-http = { version = "3.0.0-beta.1", features = ["openssl"] }
actix-http-test = { version = "3.0.0-beta.1", features = ["openssl"] }
actix-utils = "3.0.0-beta.1"
actix-server = "2.0.0-beta.2"
actix-tls = { version = "3.0.0-beta.2", features = ["openssl", "rustls"] }
actix-server = "2.0.0-beta.3"
actix-tls = { version = "3.0.0-beta.3", features = ["openssl", "rustls"] }
brotli2 = "0.3.2"
flate2 = "1.0.13"

View File

@ -21,7 +21,7 @@ use actix_rt::System;
use awc::Client;
fn main() {
System::new("test").block_on(async {
System::new().block_on(async {
let client = Client::default();
let res = client

View File

@ -1,4 +1,3 @@
use std::cell::RefCell;
use std::convert::TryFrom;
use std::fmt;
use std::rc::Rc;
@ -24,7 +23,7 @@ pub struct ClientBuilder {
conn_window_size: Option<u32>,
headers: HeaderMap,
timeout: Option<Duration>,
connector: Option<RefCell<Box<dyn Connect>>>,
connector: Option<Box<dyn Connect>>,
}
impl Default for ClientBuilder {
@ -56,7 +55,7 @@ impl ClientBuilder {
<T::Response as Connection>::Future: 'static,
T::Future: 'static,
{
self.connector = Some(RefCell::new(Box::new(ConnectorWrapper(connector))));
self.connector = Some(Box::new(ConnectorWrapper(connector)));
self
}
@ -182,9 +181,7 @@ impl ClientBuilder {
if let Some(val) = self.stream_window_size {
connector = connector.initial_window_size(val)
};
RefCell::new(
Box::new(ConnectorWrapper(connector.finish())) as Box<dyn Connect>
)
Box::new(ConnectorWrapper(connector.finish())) as _
};
let config = ClientConfig {
headers: self.headers,

View File

@ -20,14 +20,14 @@ pub(crate) struct ConnectorWrapper<T>(pub T);
pub(crate) trait Connect {
fn send_request(
&mut self,
&self,
head: RequestHead,
body: Body,
addr: Option<net::SocketAddr>,
) -> Pin<Box<dyn Future<Output = Result<ClientResponse, SendRequestError>>>>;
fn send_request_extra(
&mut self,
&self,
head: Rc<RequestHead>,
extra_headers: Option<HeaderMap>,
body: Body,
@ -36,7 +36,7 @@ pub(crate) trait Connect {
/// Send request, returns Response and Framed
fn open_tunnel(
&mut self,
&self,
head: RequestHead,
addr: Option<net::SocketAddr>,
) -> Pin<
@ -52,7 +52,7 @@ pub(crate) trait Connect {
/// Send request and extra headers, returns Response and Framed
fn open_tunnel_extra(
&mut self,
&self,
head: Rc<RequestHead>,
extra_headers: Option<HeaderMap>,
addr: Option<net::SocketAddr>,
@ -78,7 +78,7 @@ where
T::Future: 'static,
{
fn send_request(
&mut self,
&self,
head: RequestHead,
body: Body,
addr: Option<net::SocketAddr>,
@ -101,7 +101,7 @@ where
}
fn send_request_extra(
&mut self,
&self,
head: Rc<RequestHead>,
extra_headers: Option<HeaderMap>,
body: Body,
@ -126,7 +126,7 @@ where
}
fn open_tunnel(
&mut self,
&self,
head: RequestHead,
addr: Option<net::SocketAddr>,
) -> Pin<
@ -158,7 +158,7 @@ where
}
fn open_tunnel_extra(
&mut self,
&self,
head: Rc<RequestHead>,
extra_headers: Option<HeaderMap>,
addr: Option<net::SocketAddr>,

View File

@ -93,7 +93,6 @@
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
use std::cell::RefCell;
use std::convert::TryFrom;
use std::rc::Rc;
use std::time::Duration;
@ -145,7 +144,7 @@ use self::connect::{Connect, ConnectorWrapper};
pub struct Client(Rc<ClientConfig>);
pub(crate) struct ClientConfig {
pub(crate) connector: RefCell<Box<dyn Connect>>,
pub(crate) connector: Box<dyn Connect>,
pub(crate) headers: HeaderMap,
pub(crate) timeout: Option<Duration>,
}
@ -153,9 +152,7 @@ pub(crate) struct ClientConfig {
impl Default for Client {
fn default() -> Self {
Client(Rc::new(ClientConfig {
connector: RefCell::new(Box::new(ConnectorWrapper(
Connector::new().finish(),
))),
connector: Box::new(ConnectorWrapper(Connector::new().finish())),
headers: HeaderMap::new(),
timeout: Some(Duration::from_secs(5)),
}))

View File

@ -183,15 +183,13 @@ impl RequestSender {
where
B: Into<Body>,
{
let mut connector = config.connector.borrow_mut();
let fut = match self {
RequestSender::Owned(head) => {
connector.send_request(head, body.into(), addr)
}
RequestSender::Rc(head, extra_headers) => {
connector.send_request_extra(head, extra_headers, body.into(), addr)
config.connector.send_request(head, body.into(), addr)
}
RequestSender::Rc(head, extra_headers) => config
.connector
.send_request_extra(head, extra_headers, body.into(), addr),
};
SendClientRequest::new(fut, response_decompress, timeout.or(config.timeout))

View File

@ -325,11 +325,7 @@ impl WebsocketsRequest {
let max_size = self.max_size;
let server_mode = self.server_mode;
let fut = self
.config
.connector
.borrow_mut()
.open_tunnel(head, self.addr);
let fut = self.config.connector.open_tunnel(head, self.addr);
// set request timeout
let (head, framed) = if let Some(to) = self.config.timeout {

View File

@ -120,9 +120,7 @@ async fn test_timeout() {
});
let connector = awc::Connector::new()
.connector(actix_tls::connect::new_connector(
actix_tls::connect::start_default_resolver().await.unwrap(),
))
.connector(actix_tls::connect::default_connector())
.timeout(Duration::from_secs(15))
.finish();