|
1 | 1 | //! Client header advertising available compression algorithms.
|
2 | 2 |
|
3 |
| -use crate::content::MediaTypeProposal; |
| 3 | +use crate::content::{ContentType, MediaTypeProposal}; |
4 | 4 | use crate::headers::{HeaderName, HeaderValue, Headers, ToHeaderValues, ACCEPT};
|
5 | 5 | use crate::utils::sort_by_weight;
|
6 | 6 | use crate::{Error, Mime, StatusCode};
|
@@ -29,10 +29,10 @@ use std::slice;
|
29 | 29 | /// accept.push(MediaTypeProposal::new(mime::PLAIN, None)?);
|
30 | 30 | ///
|
31 | 31 | /// let mut res = Response::new(200);
|
32 |
| -/// let media_type = accept.negotiate(&[mime::XML])?; |
33 |
| -/// media_type.apply(&mut res); |
| 32 | +/// let content_type = accept.negotiate(&[mime::XML])?; |
| 33 | +/// content_type.apply(&mut res); |
34 | 34 | ///
|
35 |
| -/// assert_eq!(res["Content-Encoding"], "text/html"); |
| 35 | +/// assert_eq!(res["Content-Type"], "application/xml;charset=utf-8"); |
36 | 36 | /// #
|
37 | 37 | /// # Ok(()) }
|
38 | 38 | /// ```
|
@@ -111,14 +111,14 @@ impl Accept {
|
111 | 111 | /// # Errors
|
112 | 112 | ///
|
113 | 113 | /// If no suitable encoding is found, an error with the status of `406` will be returned.
|
114 |
| - pub fn negotiate(&mut self, available: &[Mime]) -> crate::Result<Mime> { |
| 114 | + pub fn negotiate(&mut self, available: &[Mime]) -> crate::Result<ContentType> { |
115 | 115 | // Start by ordering the encodings.
|
116 | 116 | self.sort();
|
117 | 117 |
|
118 | 118 | // Try and find the first encoding that matches.
|
119 | 119 | for accept in &self.entries {
|
120 | 120 | if available.contains(&accept) {
|
121 |
| - return Ok(accept.clone().into()); |
| 121 | + return Ok(accept.media_type.clone().into()); |
122 | 122 | }
|
123 | 123 | }
|
124 | 124 |
|
|
0 commit comments