Merge branch 'master' into feat/client_default_headermap

This commit is contained in:
Rob Ede 2021-03-26 14:12:07 +00:00 committed by GitHub
commit d84d442f2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 22 deletions

View File

@ -55,7 +55,6 @@ base64 = "0.13"
bitflags = "1.2"
bytes = "1"
bytestring = "1"
cfg-if = "1"
cookie = { version = "0.14.1", features = ["percent-encode"], optional = true }
derive_more = "0.99.5"
encoding_rs = "0.8"

View File

@ -174,7 +174,13 @@ impl H2ConnectionInner {
/// Cancel spawned connection task on drop.
impl Drop for H2ConnectionInner {
fn drop(&mut self) {
self.handle.abort();
if self
.sender
.send_request(http::Request::new(()), true)
.is_err()
{
self.handle.abort();
}
}
}
@ -398,9 +404,18 @@ where
#[cfg(test)]
mod test {
use std::net;
use std::{
future::Future,
net,
pin::Pin,
task::{Context, Poll},
time::{Duration, Instant},
};
use actix_rt::net::TcpStream;
use actix_rt::{
net::TcpStream,
time::{interval, Interval},
};
use super::*;
@ -424,9 +439,36 @@ mod test {
drop(conn);
match sender.ready().await {
Ok(_) => panic!("connection should be gone and can not be ready"),
Err(e) => assert!(e.is_io()),
};
struct DropCheck {
sender: h2::client::SendRequest<Bytes>,
interval: Interval,
start_from: Instant,
}
impl Future for DropCheck {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
match futures_core::ready!(this.sender.poll_ready(cx)) {
Ok(()) => {
if this.start_from.elapsed() > Duration::from_secs(10) {
panic!("connection should be gone and can not be ready");
} else {
let _ = this.interval.poll_tick(cx);
Poll::Pending
}
}
Err(_) => Poll::Ready(()),
}
}
}
DropCheck {
sender,
interval: interval(Duration::from_millis(100)),
start_from: Instant::now(),
}
.await;
}
}

View File

@ -5,10 +5,12 @@
* Add `Client::headers` to get default mut reference of `HeaderMap` of client object. [#2114]
### Changed
* `ConnectorService` type is renamed to `BoxConnectorService` [#2081]
* `ConnectorService` type is renamed to `BoxConnectorService`. [#2081]
* Fix http/https encoding when enabling `compress` feature. [#2116]
[#2081]: https://github.com/actix/actix-web/pull/2081
[#2114]: https://github.com/actix/actix-web/pull/2114
[#2116]: https://github.com/actix/actix-web/pull/2116
## 3.0.0-beta.3 - 2021-03-08

View File

@ -51,7 +51,6 @@ actix-rt = { version = "2.1", default-features = false }
base64 = "0.13"
bytes = "1"
cfg-if = "1.0"
derive_more = "0.99.5"
futures-core = { version = "0.3.7", default-features = false }
itoa = "0.4"

View File

@ -21,15 +21,10 @@ use crate::frozen::FrozenClientRequest;
use crate::sender::{PrepForSendingError, RequestSender, SendClientRequest};
use crate::ClientConfig;
cfg_if::cfg_if! {
if #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] {
const HTTPS_ENCODING: &str = "br, gzip, deflate";
} else if #[cfg(feature = "compress")] {
const HTTPS_ENCODING: &str = "br";
} else {
const HTTPS_ENCODING: &str = "identity";
}
}
#[cfg(feature = "compress")]
const HTTPS_ENCODING: &str = "br, gzip, deflate";
#[cfg(not(feature = "compress"))]
const HTTPS_ENCODING: &str = "br";
/// An HTTP Client request builder
///
@ -521,11 +516,11 @@ impl ClientRequest {
.unwrap_or(true);
if https {
slf = slf.insert_header_if_none((header::ACCEPT_ENCODING, HTTPS_ENCODING))
slf = slf.insert_header_if_none((header::ACCEPT_ENCODING, HTTPS_ENCODING));
} else {
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
#[cfg(feature = "compress")]
{
slf = slf.insert_header_if_none((header::ACCEPT_ENCODING, "gzip, deflate"))
slf = slf.insert_header_if_none((header::ACCEPT_ENCODING, "gzip, deflate"));
}
};
}