fix(http): avoid infinite recursion when Body::from is called with Cow::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.
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							9c80fdbb9e
						
					
				
				
					commit
					e8d6173734
				
			| @@ -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) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user