From de187c0d16d2a50c405327e13d6b8078eacd7a8f Mon Sep 17 00:00:00 2001 From: Maksym Vorobiov Date: Thu, 5 Mar 2020 15:39:49 +0200 Subject: [PATCH] max_http_version to accept http::Version --- actix-http/src/client/connector.rs | 15 ++++++++------- awc/src/builder.rs | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/actix-http/src/client/connector.rs b/actix-http/src/client/connector.rs index 2d9bc2967..adb88bbed 100644 --- a/actix-http/src/client/connector.rs +++ b/actix-http/src/client/connector.rs @@ -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 } diff --git a/awc/src/builder.rs b/awc/src/builder.rs index eddbd5374..2b2e5df9f 100644 --- a/awc/src/builder.rs +++ b/awc/src/builder.rs @@ -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, + max_http_version: Option, stream_window_size: Option, conn_window_size: Option, 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 }