limit upgrade only for http1.1 request
This commit is contained in:
parent
d85d7e6c39
commit
1c1b50d213
3 changed files with 13 additions and 4 deletions
|
|
@ -143,6 +143,12 @@ where
|
||||||
|
|
||||||
// Upgrade in request header
|
// Upgrade in request header
|
||||||
let upgrade_in_request = extract_upgrade(req.headers());
|
let upgrade_in_request = extract_upgrade(req.headers());
|
||||||
|
if upgrade_in_request.is_some() && req.version() != http::Version::HTTP_11 {
|
||||||
|
return Err(HttpError::FailedToUpgrade(format!(
|
||||||
|
"Unsupported HTTP version: {:?}",
|
||||||
|
req.version()
|
||||||
|
)));
|
||||||
|
}
|
||||||
// let request_upgraded = req.extensions_mut().remove::<hyper::upgrade::OnUpgrade>();
|
// let request_upgraded = req.extensions_mut().remove::<hyper::upgrade::OnUpgrade>();
|
||||||
let req_on_upgrade = hyper::upgrade::on(&mut req);
|
let req_on_upgrade = hyper::upgrade::on(&mut req);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,8 +177,11 @@ where
|
||||||
.headers_mut()
|
.headers_mut()
|
||||||
.insert(header::CONNECTION, HeaderValue::from_static("upgrade"));
|
.insert(header::CONNECTION, HeaderValue::from_static("upgrade"));
|
||||||
}
|
}
|
||||||
|
if upgrade.is_none() {
|
||||||
|
// can update request line i.e., http version, only if not upgrade (http 1.1)
|
||||||
update_request_line(req, upstream_chosen, upstream_candidates)?;
|
update_request_line(req, upstream_chosen, upstream_candidates)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(context)
|
Ok(context)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ pub(crate) type HttpResult<T> = std::result::Result<T, HttpError>;
|
||||||
/// Describes things that can go wrong in the forwarder
|
/// Describes things that can go wrong in the forwarder
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum HttpError {
|
pub enum HttpError {
|
||||||
#[error("No host is give nin request header")]
|
// #[error("No host is give in request header")]
|
||||||
NoHostInRequestHeader,
|
// NoHostInRequestHeader,
|
||||||
#[error("Invalid host in request header")]
|
#[error("Invalid host in request header")]
|
||||||
InvalidHostInRequestHeader,
|
InvalidHostInRequestHeader,
|
||||||
#[error("SNI and Host header mismatch")]
|
#[error("SNI and Host header mismatch")]
|
||||||
|
|
@ -43,7 +43,7 @@ pub enum HttpError {
|
||||||
impl From<HttpError> for StatusCode {
|
impl From<HttpError> for StatusCode {
|
||||||
fn from(e: HttpError) -> StatusCode {
|
fn from(e: HttpError) -> StatusCode {
|
||||||
match e {
|
match e {
|
||||||
HttpError::NoHostInRequestHeader => StatusCode::BAD_REQUEST,
|
// HttpError::NoHostInRequestHeader => StatusCode::BAD_REQUEST,
|
||||||
HttpError::InvalidHostInRequestHeader => StatusCode::BAD_REQUEST,
|
HttpError::InvalidHostInRequestHeader => StatusCode::BAD_REQUEST,
|
||||||
HttpError::SniHostInconsistency => StatusCode::MISDIRECTED_REQUEST,
|
HttpError::SniHostInconsistency => StatusCode::MISDIRECTED_REQUEST,
|
||||||
HttpError::NoMatchingBackendApp => StatusCode::SERVICE_UNAVAILABLE,
|
HttpError::NoMatchingBackendApp => StatusCode::SERVICE_UNAVAILABLE,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue