Skip to content

Commit aeb1fb4

Browse files
authored
Merge pull request #141 from http-rs/fix-header-append
Fix header append
2 parents 5467861 + 7bd8922 commit aeb1fb4

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

src/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Body {
219219
/// assert_eq!(&body.into_string().await.unwrap(), "Hello Nori");
220220
/// # Ok(()) }) }
221221
/// ```
222-
pub async fn into_string(mut self) -> io::Result<String> {
222+
pub async fn into_string(mut self) -> crate::Result<String> {
223223
let mut result = String::with_capacity(self.len().unwrap_or(0));
224224
self.read_to_string(&mut result).await?;
225225
Ok(result)

src/headers/headers.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,17 @@ impl Headers {
5858
///
5959
/// Unlike `insert` this function will not override the contents of a header, but insert a
6060
/// header if there aren't any. Or else append to the existing list of headers.
61-
pub fn append(
62-
&mut self,
63-
name: impl Into<HeaderName>,
64-
values: impl ToHeaderValues,
65-
) -> crate::Result<()> {
61+
pub fn append(&mut self, name: impl Into<HeaderName>, values: impl ToHeaderValues) {
6662
let name = name.into();
6763
match self.get_mut(name.clone()) {
6864
Some(headers) => {
69-
let mut values: HeaderValues = values.to_header_values()?.collect();
65+
let mut values: HeaderValues = values.to_header_values().unwrap().collect();
7066
headers.append(&mut values);
7167
}
7268
None => {
7369
self.insert(name, values);
7470
}
7571
}
76-
Ok(())
7772
}
7873

7974
/// Get a reference to a header.
@@ -194,9 +189,9 @@ mod tests {
194189
let non_static_header = HeaderName::from_str("hello")?;
195190

196191
let mut headers = Headers::new();
197-
headers.append(STATIC_HEADER, "foo0")?;
198-
headers.append(static_header.clone(), "foo1")?;
199-
headers.append(non_static_header.clone(), "foo2")?;
192+
headers.append(STATIC_HEADER, "foo0");
193+
headers.append(static_header.clone(), "foo1");
194+
headers.append(non_static_header.clone(), "foo2");
200195

201196
assert_eq!(headers[STATIC_HEADER], ["foo0", "foo1", "foo2",][..]);
202197
assert_eq!(headers[static_header], ["foo0", "foo1", "foo2",][..]);

src/request.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl Request {
304304
/// assert_eq!(&req.body_string().await.unwrap(), "Hello Nori");
305305
/// # Ok(()) }) }
306306
/// ```
307-
pub async fn body_string(self) -> io::Result<String> {
307+
pub async fn body_string(self) -> crate::Result<String> {
308308
self.body.into_string().await
309309
}
310310

@@ -441,15 +441,11 @@ impl Request {
441441
/// use http_types::{Url, Method, Request};
442442
///
443443
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
444-
/// req.append_header("Content-Type", "text/plain")?;
444+
/// req.append_header("Content-Type", "text/plain");
445445
/// #
446446
/// # Ok(()) }
447447
/// ```
448-
pub fn append_header(
449-
&mut self,
450-
name: impl Into<HeaderName>,
451-
values: impl ToHeaderValues,
452-
) -> crate::Result<()> {
448+
pub fn append_header(&mut self, name: impl Into<HeaderName>, values: impl ToHeaderValues) {
453449
self.headers.append(name, values)
454450
}
455451

src/response.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,11 @@ impl Response {
126126
/// use http_types::{Response, StatusCode};
127127
///
128128
/// let mut res = Response::new(StatusCode::Ok);
129-
/// res.append_header("Content-Type", "text/plain")?;
129+
/// res.append_header("Content-Type", "text/plain");
130130
/// #
131131
/// # Ok(()) }
132132
/// ```
133-
pub fn append_header(
134-
&mut self,
135-
name: impl Into<HeaderName>,
136-
values: impl ToHeaderValues,
137-
) -> crate::Result<()> {
133+
pub fn append_header(&mut self, name: impl Into<HeaderName>, values: impl ToHeaderValues) {
138134
self.headers.append(name, values)
139135
}
140136

@@ -265,7 +261,7 @@ impl Response {
265261
/// assert_eq!(&res.body_string().await.unwrap(), "Hello Nori");
266262
/// # Ok(()) }) }
267263
/// ```
268-
pub async fn body_string(self) -> io::Result<String> {
264+
pub async fn body_string(self) -> crate::Result<String> {
269265
self.body.into_string().await
270266
}
271267

src/security/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,5 @@ pub fn referrer_policy(mut headers: impl AsMut<Headers>, referrer: Option<Referr
220220

221221
// We MUST allow for multiple Referrer-Policy headers to be set.
222222
// See: https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values example #13
223-
headers.as_mut().append("Referrer-Policy", policy).unwrap();
223+
headers.as_mut().append("Referrer-Policy", policy);
224224
}

src/trailers.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,11 @@ impl Trailers {
108108
/// use http_types::Trailers;
109109
///
110110
/// let mut trailers = Trailers::new();
111-
/// trailers.append("Content-Type", "text/plain")?;
111+
/// trailers.append("Content-Type", "text/plain");
112112
/// #
113113
/// # Ok(()) }
114114
/// ```
115-
pub fn append(
116-
&mut self,
117-
name: impl Into<HeaderName>,
118-
values: impl ToHeaderValues,
119-
) -> crate::Result<()> {
115+
pub fn append(&mut self, name: impl Into<HeaderName>, values: impl ToHeaderValues) {
120116
self.headers.append(name, values)
121117
}
122118

0 commit comments

Comments
 (0)