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:
		| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user