Client should validate request URI. (#181)

This patch adds checks for the request URI and rejects invalid URIs. In
the case of forwarding an HTTP 1.1 request with a path, an "http" pseudo
header is added to satisfy the HTTP/2.0 spec.

Closes #179
This commit is contained in:
Carl Lerche
2017-12-11 13:42:00 -06:00
committed by GitHub
parent 71888acea5
commit 9378846da8
10 changed files with 164 additions and 53 deletions

View File

@@ -63,6 +63,7 @@ pub struct Continuation {
headers: Iter,
}
// TODO: These fields shouldn't be `pub`
#[derive(Debug, Default, Eq, PartialEq)]
pub struct Pseudo {
// Request
@@ -405,10 +406,6 @@ impl Pseudo {
pub fn request(method: Method, uri: Uri) -> Self {
let parts = uri::Parts::from(uri);
fn to_string(src: Bytes) -> String<Bytes> {
unsafe { String::from_utf8_unchecked(src) }
}
let path = parts
.path_and_query
.map(|v| v.into())
@@ -426,7 +423,7 @@ impl Pseudo {
//
// TODO: Scheme must be set...
if let Some(scheme) = parts.scheme {
pseudo.set_scheme(to_string(scheme.into()));
pseudo.set_scheme(scheme);
}
// If the URI includes an authority component, add it to the pseudo
@@ -448,8 +445,8 @@ impl Pseudo {
}
}
pub fn set_scheme(&mut self, scheme: String<Bytes>) {
self.scheme = Some(scheme);
pub fn set_scheme(&mut self, scheme: uri::Scheme) {
self.scheme = Some(to_string(scheme.into()));
}
pub fn set_authority(&mut self, authority: String<Bytes>) {
@@ -457,6 +454,10 @@ impl Pseudo {
}
}
fn to_string(src: Bytes) -> String<Bytes> {
unsafe { String::from_utf8_unchecked(src) }
}
// ===== impl Iter =====
impl Iterator for Iter {