Skip to content

Commit

Permalink
fix(http): avoid infinite recursion when Body::from is called with Co…
Browse files Browse the repository at this point in the history
…w::Owned. (#1343)

When cow is a Cow::Owned, cow.to_owned() returns a Cow::Owned, which leads to infinite recursion.
Extract the owned or borrowed values from the cow to ensure progress is made in either case.
  • Loading branch information
aaronriekenberg authored and seanmonstar committed Oct 1, 2017
1 parent 9c80fdb commit e8d6173
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/proto/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ impl From<&'static [u8]> for Body {
impl From<Cow<'static, [u8]>> for Body {
#[inline]
fn from (cow: Cow<'static, [u8]>) -> Body {
if let Cow::Borrowed(value) = cow {
Body::from(value)
} else {
Body::from(cow.to_owned())
match cow {
Cow::Borrowed(b) => Body::from(b),
Cow::Owned(o) => Body::from(o)
}
}
}
Expand All @@ -123,10 +122,9 @@ impl From<&'static str> for Body {
impl From<Cow<'static, str>> for Body {
#[inline]
fn from(cow: Cow<'static, str>) -> Body {
if let Cow::Borrowed(value) = cow {
Body::from(value)
} else {
Body::from(cow.to_owned())
match cow {
Cow::Borrowed(b) => Body::from(b),
Cow::Owned(o) => Body::from(o)
}
}
}
Expand Down

0 comments on commit e8d6173

Please sign in to comment.