Handle :scheme and :path in CONNECT
If the :method is CONNECT the :scheme and :path pseudo-header fields MUST be omitted
This commit is contained in:
committed by
Sean McArthur
parent
9af48b08c7
commit
f7b3cf6d29
@@ -121,7 +121,7 @@ use crate::proto::{self, Config, Prioritized};
|
|||||||
use crate::{FlowControl, PingPong, RecvStream, SendStream};
|
use crate::{FlowControl, PingPong, RecvStream, SendStream};
|
||||||
|
|
||||||
use bytes::{Buf, Bytes};
|
use bytes::{Buf, Bytes};
|
||||||
use http::{HeaderMap, Request, Response};
|
use http::{HeaderMap, Method, Request, Response};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
@@ -1357,7 +1357,9 @@ impl proto::Peer for Peer {
|
|||||||
|
|
||||||
b = b.version(Version::HTTP_2);
|
b = b.version(Version::HTTP_2);
|
||||||
|
|
||||||
|
let is_connect;
|
||||||
if let Some(method) = pseudo.method {
|
if let Some(method) = pseudo.method {
|
||||||
|
is_connect = method == Method::CONNECT;
|
||||||
b = b.method(method);
|
b = b.method(method);
|
||||||
} else {
|
} else {
|
||||||
malformed!("malformed headers: missing method");
|
malformed!("malformed headers: missing method");
|
||||||
@@ -1385,8 +1387,11 @@ impl proto::Peer for Peer {
|
|||||||
})?);
|
})?);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A :scheme is always required.
|
// A :scheme is required, except CONNECT.
|
||||||
if let Some(scheme) = pseudo.scheme {
|
if let Some(scheme) = pseudo.scheme {
|
||||||
|
if is_connect {
|
||||||
|
malformed!(":scheme in CONNECT");
|
||||||
|
}
|
||||||
let maybe_scheme = scheme.parse();
|
let maybe_scheme = scheme.parse();
|
||||||
let scheme = maybe_scheme.or_else(|why| {
|
let scheme = maybe_scheme.or_else(|why| {
|
||||||
malformed!(
|
malformed!(
|
||||||
@@ -1402,11 +1407,15 @@ impl proto::Peer for Peer {
|
|||||||
if parts.authority.is_some() {
|
if parts.authority.is_some() {
|
||||||
parts.scheme = Some(scheme);
|
parts.scheme = Some(scheme);
|
||||||
}
|
}
|
||||||
} else {
|
} else if !is_connect {
|
||||||
malformed!("malformed headers: missing scheme");
|
malformed!("malformed headers: missing scheme");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(path) = pseudo.path {
|
if let Some(path) = pseudo.path {
|
||||||
|
if is_connect {
|
||||||
|
malformed!(":path in CONNECT");
|
||||||
|
}
|
||||||
|
|
||||||
// This cannot be empty
|
// This cannot be empty
|
||||||
if path.is_empty() {
|
if path.is_empty() {
|
||||||
malformed!("malformed headers: missing path");
|
malformed!("malformed headers: missing path");
|
||||||
|
|||||||
Reference in New Issue
Block a user