max_http_version to accept http::Version

This commit is contained in:
Maksym Vorobiov 2020-03-05 15:39:49 +02:00
parent 7a677eafce
commit de187c0d16
2 changed files with 12 additions and 11 deletions

View File

@ -164,13 +164,14 @@ where
}
/// Maximum supported http major version
/// When supplied 1 both HTTP/1.0 and HTTP/1.1 will be allowed
pub fn max_http_version(mut self, val: u8) -> Self {
self.ssl = Connector::build_ssl(if val == 1 {
vec![b"http/1.1".to_vec()]
} else {
vec![b"h2".to_vec(), b"http/1.1".to_vec()]
});
/// Supported versions http/1.1, http/2
pub fn max_http_version(mut self, val: http::Version) -> Self {
let versions = match val {
http::Version::HTTP_11 => vec![b"http/1.1".to_vec()],
http::Version::HTTP_2 => vec![b"h2".to_vec(), b"http/1.1".to_vec()],
_ => unimplemented!("actix-http:client: supported versions http/1.1, http/2"),
};
self.ssl = Connector::build_ssl(versions);
self
}

View File

@ -5,7 +5,7 @@ use std::rc::Rc;
use std::time::Duration;
use actix_http::client::{Connect as HttpConnect, ConnectError, Connection, Connector};
use actix_http::http::{header, Error as HttpError, HeaderMap, HeaderName};
use actix_http::http::{header, Error as HttpError, HeaderMap, HeaderName, self};
use actix_service::Service;
use crate::connect::{ConnectorWrapper, Connect};
@ -19,7 +19,7 @@ pub struct ClientBuilder {
default_headers: bool,
allow_redirects: bool,
max_redirects: usize,
max_http_version: Option<u8>,
max_http_version: Option<http::Version>,
stream_window_size: Option<u32>,
conn_window_size: Option<u32>,
headers: HeaderMap,
@ -84,8 +84,8 @@ impl ClientBuilder {
}
/// Maximum supported http major version
/// When supplied 1 both HTTP/1.0 and HTTP/1.1 will be allowed
pub fn max_http_version(mut self, val: u8) -> Self {
/// Supported versions http/1.1, http/2
pub fn max_http_version(mut self, val: http::Version) -> Self {
self.max_http_version = Some(val);
self
}