cleartext backend request will be http1.1
This commit is contained in:
parent
c5c7847b92
commit
e76ac95062
5 changed files with 16 additions and 13 deletions
|
|
@ -51,7 +51,7 @@ upstream = [
|
||||||
{ location = 'www.yahoo.com', tls = true },
|
{ location = 'www.yahoo.com', tls = true },
|
||||||
{ location = 'www.yahoo.co.jp', tls = true },
|
{ location = 'www.yahoo.co.jp', tls = true },
|
||||||
]
|
]
|
||||||
upstream_options = ["override_host", "convert_to_http2"]
|
upstream_options = ["override_host", "convert_https_to_2"]
|
||||||
|
|
||||||
# Non-default destination in "localhost" app, which is routed by "path"
|
# Non-default destination in "localhost" app, which is routed by "path"
|
||||||
[[apps.localhost.reverse_proxy]]
|
[[apps.localhost.reverse_proxy]]
|
||||||
|
|
@ -69,7 +69,7 @@ upstream = [
|
||||||
upstream_options = [
|
upstream_options = [
|
||||||
"override_host",
|
"override_host",
|
||||||
"upgrade_insecure_requests",
|
"upgrade_insecure_requests",
|
||||||
"convert_to_http11",
|
"convert_https_to_11",
|
||||||
]
|
]
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ use crate::error::*;
|
||||||
pub enum UpstreamOption {
|
pub enum UpstreamOption {
|
||||||
OverrideHost,
|
OverrideHost,
|
||||||
UpgradeInsecureRequests,
|
UpgradeInsecureRequests,
|
||||||
ConvertToHttp11,
|
ConvertHttpsTo11,
|
||||||
ConvertToHttp2,
|
ConvertHttpsTo2,
|
||||||
// TODO: Adds more options for heder override
|
// TODO: Adds more options for heder override
|
||||||
}
|
}
|
||||||
impl TryFrom<&str> for UpstreamOption {
|
impl TryFrom<&str> for UpstreamOption {
|
||||||
|
|
@ -14,8 +14,8 @@ impl TryFrom<&str> for UpstreamOption {
|
||||||
match val {
|
match val {
|
||||||
"override_host" => Ok(Self::OverrideHost),
|
"override_host" => Ok(Self::OverrideHost),
|
||||||
"upgrade_insecure_requests" => Ok(Self::UpgradeInsecureRequests),
|
"upgrade_insecure_requests" => Ok(Self::UpgradeInsecureRequests),
|
||||||
"convert_to_http11" => Ok(Self::ConvertToHttp11),
|
"convert_https_to_11" => Ok(Self::ConvertHttpsTo11),
|
||||||
"convert_to_http2" => Ok(Self::ConvertToHttp2),
|
"convert_https_to_2" => Ok(Self::ConvertHttpsTo2),
|
||||||
_ => Err(RpxyError::Other(anyhow!("Unsupported header option"))),
|
_ => Err(RpxyError::Other(anyhow!("Unsupported header option"))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,8 +227,8 @@ fn get_reverse_proxy(rp_settings: &[ReverseProxyOption]) -> std::result::Result<
|
||||||
ensure!(
|
ensure!(
|
||||||
upstream
|
upstream
|
||||||
.iter()
|
.iter()
|
||||||
.all(|(_, elem)| !(elem.opts.contains(&UpstreamOption::ConvertToHttp11)
|
.all(|(_, elem)| !(elem.opts.contains(&UpstreamOption::ConvertHttpsTo11)
|
||||||
&& elem.opts.contains(&UpstreamOption::ConvertToHttp2))),
|
&& elem.opts.contains(&UpstreamOption::ConvertHttpsTo2))),
|
||||||
"either one of force_http11 or force_http2 can be enabled"
|
"either one of force_http11 or force_http2 can be enabled"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::{backend::UpstreamGroup, error::*, globals::Globals, log::*, utils::S
|
||||||
use hyper::{
|
use hyper::{
|
||||||
client::connect::Connect,
|
client::connect::Connect,
|
||||||
header::{self, HeaderValue},
|
header::{self, HeaderValue},
|
||||||
|
http::uri::Scheme,
|
||||||
Body, Client, Request, Response, StatusCode, Uri, Version,
|
Body, Client, Request, Response, StatusCode, Uri, Version,
|
||||||
};
|
};
|
||||||
use std::{env, net::SocketAddr, sync::Arc};
|
use std::{env, net::SocketAddr, sync::Arc};
|
||||||
|
|
@ -289,10 +290,12 @@ where
|
||||||
.insert(header::CONNECTION, HeaderValue::from_str("upgrade")?);
|
.insert(header::CONNECTION, HeaderValue::from_str("upgrade")?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If not specified (force_httpXX_upstream) and https, version is preserved except for http/3
|
||||||
apply_upstream_options_to_request_line(req, upstream_group)?;
|
apply_upstream_options_to_request_line(req, upstream_group)?;
|
||||||
|
// Maybe workaround: Change version to http/1.1 when destination scheme is http
|
||||||
// if not specified (force_httpXX_upstream), version is preserved except for http/3
|
if req.version() != Version::HTTP_11 && upstream_chosen.uri.scheme() == Some(&Scheme::HTTP) {
|
||||||
if req.version() == Version::HTTP_3 {
|
*req.version_mut() = Version::HTTP_11;
|
||||||
|
} else if req.version() == Version::HTTP_3 {
|
||||||
debug!("HTTP/3 is currently unsupported for request to upstream. Use HTTP/2.");
|
debug!("HTTP/3 is currently unsupported for request to upstream. Use HTTP/2.");
|
||||||
*req.version_mut() = Version::HTTP_2;
|
*req.version_mut() = Version::HTTP_2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ use hyper::{header, Request};
|
||||||
pub(super) fn apply_upstream_options_to_request_line<B>(req: &mut Request<B>, upstream: &UpstreamGroup) -> Result<()> {
|
pub(super) fn apply_upstream_options_to_request_line<B>(req: &mut Request<B>, upstream: &UpstreamGroup) -> Result<()> {
|
||||||
for opt in upstream.opts.iter() {
|
for opt in upstream.opts.iter() {
|
||||||
match opt {
|
match opt {
|
||||||
UpstreamOption::ConvertToHttp11 => *req.version_mut() = hyper::Version::HTTP_11,
|
UpstreamOption::ConvertHttpsTo11 => *req.version_mut() = hyper::Version::HTTP_11,
|
||||||
UpstreamOption::ConvertToHttp2 => *req.version_mut() = hyper::Version::HTTP_2,
|
UpstreamOption::ConvertHttpsTo2 => *req.version_mut() = hyper::Version::HTTP_2,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue