This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Add hyper::Uri support #21
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,15 @@ doctest = false | |
|
||
[dependencies] | ||
cookie = {version = "0.6", default-features = false} | ||
hyper = "0.10" | ||
mime = "0.2" | ||
hyper = { version = "0.11", features = ["raw_status"] } | ||
mime = "0.3" | ||
serde = "1.0" | ||
serde_bytes = "0.10" | ||
time = "0.1" | ||
|
||
[dev-dependencies] | ||
serde_test = "1.0" | ||
time = "0.1" | ||
|
||
[replace] | ||
"hyper:0.11.2" = { git = "https://github.com/hyperium/hyper.git" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this here? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
//! * `cookie::Cookie` | ||
//! * `hyper::header::ContentType` | ||
//! * `hyper::header::Headers` | ||
//! * `hyper::http::RawStatus` | ||
//! * `hyper::method::Method` | ||
//! * `hyper::RawStatus` | ||
//! * `hyper::Method` | ||
//! * `hyper::Uri` | ||
//! * `mime::Mime` | ||
//! * `time::Tm` | ||
//! | ||
|
@@ -62,15 +63,17 @@ extern crate time; | |
|
||
use cookie::Cookie; | ||
use hyper::header::{ContentType, Headers}; | ||
use hyper::http::RawStatus; | ||
use hyper::method::Method; | ||
use hyper::RawStatus; | ||
use hyper::Method; | ||
use hyper::Uri; | ||
use mime::Mime; | ||
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
use serde_bytes::{ByteBuf, Bytes}; | ||
use serde::de::{self, MapAccess, SeqAccess, Visitor}; | ||
use serde::ser::{SerializeMap, SerializeSeq}; | ||
use std::cmp; | ||
use std::fmt; | ||
use std::str::FromStr; | ||
use std::ops::{Deref, DerefMut}; | ||
use std::str; | ||
use time::{Tm, strptime}; | ||
|
@@ -412,7 +415,7 @@ impl<'a> Serialize for Ser<'a, Headers> { | |
for header in self.v.iter() { | ||
let name = header.name(); | ||
let value = self.v.get_raw(name).unwrap(); | ||
serializer.serialize_entry(name, &Value(value, self.pretty))?; | ||
serializer.serialize_entry(name, &Value(&value.iter().map(|v| v.to_vec()).collect::<Vec<Vec<u8>>>(), self.pretty))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need to allocate a new |
||
} | ||
serializer.end() | ||
} | ||
|
@@ -466,7 +469,7 @@ impl<'de> Deserialize<'de> for De<Mime> { | |
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> | ||
where E: de::Error, | ||
{ | ||
v.parse::<Mime>().map(De::new).map_err(|()| { | ||
v.parse::<Mime>().map(De::new).map_err(|_| { | ||
E::custom("could not parse mime type") | ||
}) | ||
} | ||
|
@@ -534,3 +537,37 @@ impl<'a> Serialize for Ser<'a, Tm> { | |
serializer.serialize_str(&self.v.rfc3339().to_string()) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for De<Uri> { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where D: Deserializer<'de>, | ||
{ | ||
struct UriVisitor; | ||
|
||
impl<'de> Visitor<'de> for UriVisitor { | ||
type Value = De<Uri>; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
write!(formatter, "an HTTP Uri value") | ||
} | ||
|
||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> | ||
where E: de::Error, | ||
{ | ||
Uri::from_str(v) | ||
.map(De::new) | ||
.map_err(|e| E::custom(format!("{:?}", e))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That shouldn't use |
||
} | ||
} | ||
|
||
deserializer.deserialize_string(UriVisitor) | ||
} | ||
} | ||
|
||
impl<'a> Serialize for Ser<'a, Uri> { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where S: Serializer, | ||
{ | ||
serializer.serialize_str(&self.v.to_string()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allocates for nothing. |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
raw_status
needed?