diff --git a/src/body.rs b/src/body.rs index e9be0b65..b2e5b5c2 100644 --- a/src/body.rs +++ b/src/body.rs @@ -219,7 +219,7 @@ impl Body { /// assert_eq!(&body.into_string().await.unwrap(), "Hello Nori"); /// # Ok(()) }) } /// ``` - pub async fn into_string(mut self) -> io::Result { + pub async fn into_string(mut self) -> crate::Result { let mut result = String::with_capacity(self.len().unwrap_or(0)); self.read_to_string(&mut result).await?; Ok(result) diff --git a/src/headers/headers.rs b/src/headers/headers.rs index e7efba26..c4245e7d 100644 --- a/src/headers/headers.rs +++ b/src/headers/headers.rs @@ -58,22 +58,17 @@ impl Headers { /// /// Unlike `insert` this function will not override the contents of a header, but insert a /// header if there aren't any. Or else append to the existing list of headers. - pub fn append( - &mut self, - name: impl Into, - values: impl ToHeaderValues, - ) -> crate::Result<()> { + pub fn append(&mut self, name: impl Into, values: impl ToHeaderValues) { let name = name.into(); match self.get_mut(name.clone()) { Some(headers) => { - let mut values: HeaderValues = values.to_header_values()?.collect(); + let mut values: HeaderValues = values.to_header_values().unwrap().collect(); headers.append(&mut values); } None => { self.insert(name, values); } } - Ok(()) } /// Get a reference to a header. @@ -194,9 +189,9 @@ mod tests { let non_static_header = HeaderName::from_str("hello")?; let mut headers = Headers::new(); - headers.append(STATIC_HEADER, "foo0")?; - headers.append(static_header.clone(), "foo1")?; - headers.append(non_static_header.clone(), "foo2")?; + headers.append(STATIC_HEADER, "foo0"); + headers.append(static_header.clone(), "foo1"); + headers.append(non_static_header.clone(), "foo2"); assert_eq!(headers[STATIC_HEADER], ["foo0", "foo1", "foo2",][..]); assert_eq!(headers[static_header], ["foo0", "foo1", "foo2",][..]); diff --git a/src/request.rs b/src/request.rs index 27aa73f9..89354738 100644 --- a/src/request.rs +++ b/src/request.rs @@ -304,7 +304,7 @@ impl Request { /// assert_eq!(&req.body_string().await.unwrap(), "Hello Nori"); /// # Ok(()) }) } /// ``` - pub async fn body_string(self) -> io::Result { + pub async fn body_string(self) -> crate::Result { self.body.into_string().await } @@ -441,15 +441,11 @@ impl Request { /// use http_types::{Url, Method, Request}; /// /// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?); - /// req.append_header("Content-Type", "text/plain")?; + /// req.append_header("Content-Type", "text/plain"); /// # /// # Ok(()) } /// ``` - pub fn append_header( - &mut self, - name: impl Into, - values: impl ToHeaderValues, - ) -> crate::Result<()> { + pub fn append_header(&mut self, name: impl Into, values: impl ToHeaderValues) { self.headers.append(name, values) } diff --git a/src/response.rs b/src/response.rs index 79066a7f..a37b8f99 100644 --- a/src/response.rs +++ b/src/response.rs @@ -126,15 +126,11 @@ impl Response { /// use http_types::{Response, StatusCode}; /// /// let mut res = Response::new(StatusCode::Ok); - /// res.append_header("Content-Type", "text/plain")?; + /// res.append_header("Content-Type", "text/plain"); /// # /// # Ok(()) } /// ``` - pub fn append_header( - &mut self, - name: impl Into, - values: impl ToHeaderValues, - ) -> crate::Result<()> { + pub fn append_header(&mut self, name: impl Into, values: impl ToHeaderValues) { self.headers.append(name, values) } @@ -265,7 +261,7 @@ impl Response { /// assert_eq!(&res.body_string().await.unwrap(), "Hello Nori"); /// # Ok(()) }) } /// ``` - pub async fn body_string(self) -> io::Result { + pub async fn body_string(self) -> crate::Result { self.body.into_string().await } diff --git a/src/security/mod.rs b/src/security/mod.rs index a502f694..b19b3ab4 100644 --- a/src/security/mod.rs +++ b/src/security/mod.rs @@ -220,5 +220,5 @@ pub fn referrer_policy(mut headers: impl AsMut, referrer: Option, - values: impl ToHeaderValues, - ) -> crate::Result<()> { + pub fn append(&mut self, name: impl Into, values: impl ToHeaderValues) { self.headers.append(name, values) }