feat(http): add optional serialization of common types via serde
				
					
				
			This is behind a Cargo feature to avoid forcing downstream users to depend on `serde`. It is needed for Servo IPC to work.
This commit is contained in:
		| @@ -7,6 +7,9 @@ use header::Headers; | ||||
| use version::HttpVersion; | ||||
| use version::HttpVersion::{Http10, Http11}; | ||||
|  | ||||
| #[cfg(feature = "serde-serialization")] | ||||
| use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||||
|  | ||||
| pub use self::message::{HttpMessage, RequestHead, ResponseHead, Protocol}; | ||||
|  | ||||
| pub mod h1; | ||||
| @@ -17,6 +20,21 @@ pub mod message; | ||||
| #[derive(Clone, PartialEq, Debug)] | ||||
| pub struct RawStatus(pub u16, pub Cow<'static, str>); | ||||
|  | ||||
| #[cfg(feature = "serde-serialization")] | ||||
| impl Serialize for RawStatus { | ||||
|     fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { | ||||
|         (self.0, self.1.clone().into_owned()).serialize(serializer) | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "serde-serialization")] | ||||
| impl Deserialize for RawStatus { | ||||
|     fn deserialize<D>(deserializer: &mut D) -> Result<RawStatus, D::Error> where D: Deserializer { | ||||
|         let representation: (u16, String) = try!(Deserialize::deserialize(deserializer)); | ||||
|         Ok(RawStatus(representation.0, Cow::Owned(representation.1))) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Checks if a connection should be kept alive. | ||||
| #[inline] | ||||
| pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user