mirror of https://github.com/fafhrd91/actix-web
remove qitem helper
This commit is contained in:
parent
d29195babd
commit
c61d945d58
|
@ -11,6 +11,8 @@
|
||||||
* `impl Clone for ws::HandshakeError`. [#2468]
|
* `impl Clone for ws::HandshakeError`. [#2468]
|
||||||
* `#[must_use]` for `ws::Codec` to prevent subtle bugs. [#1920]
|
* `#[must_use]` for `ws::Codec` to prevent subtle bugs. [#1920]
|
||||||
* `impl Default ` for `ws::Codec`. [#1920]
|
* `impl Default ` for `ws::Codec`. [#1920]
|
||||||
|
* `header::QualityItem::{max, min}`. [#????]
|
||||||
|
* `header::Quality::{MAX, MIN}`. [#????]
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* Rename `body::BoxBody::{from_body => new}`. [#2468]
|
* Rename `body::BoxBody::{from_body => new}`. [#2468]
|
||||||
|
@ -27,10 +29,12 @@
|
||||||
* Remove unnecessary `MessageBody` bound on types passed to `body::AnyBody::new`. [#2468]
|
* Remove unnecessary `MessageBody` bound on types passed to `body::AnyBody::new`. [#2468]
|
||||||
* Move `body::AnyBody` to `awc`. Replaced with `EitherBody` and `BoxBody`. [#2468]
|
* Move `body::AnyBody` to `awc`. Replaced with `EitherBody` and `BoxBody`. [#2468]
|
||||||
* `impl Copy` for `ws::Codec`. [#1920]
|
* `impl Copy` for `ws::Codec`. [#1920]
|
||||||
|
* `header::qitem` helper. Replaced with `header::QualityItem::max` [#????]
|
||||||
|
|
||||||
[#2483]: https://github.com/actix/actix-web/pull/2483
|
[#2483]: https://github.com/actix/actix-web/pull/2483
|
||||||
[#2468]: https://github.com/actix/actix-web/pull/2468
|
[#2468]: https://github.com/actix/actix-web/pull/2468
|
||||||
[#1920]: https://github.com/actix/actix-web/pull/1920
|
[#1920]: https://github.com/actix/actix-web/pull/1920
|
||||||
|
[#????]: https://github.com/actix/actix-web/pull/????
|
||||||
|
|
||||||
|
|
||||||
## 3.0.0-beta.14 - 2021-11-30
|
## 3.0.0-beta.14 - 2021-11-30
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::cmp::Ordering;
|
||||||
|
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
|
|
||||||
use super::{qitem, QualityItem};
|
use super::QualityItem;
|
||||||
use crate::http::header;
|
use crate::http::header;
|
||||||
|
|
||||||
crate::http::header::common_header! {
|
crate::http::header::common_header! {
|
||||||
|
@ -34,42 +34,42 @@ crate::http::header::common_header! {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{Accept, qitem};
|
/// use actix_web::http::header::{Accept, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// Accept(vec![
|
/// Accept(vec![
|
||||||
/// qitem(mime::TEXT_HTML),
|
/// QualityItem::max(mime::TEXT_HTML),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{Accept, qitem};
|
/// use actix_web::http::header::{Accept, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// Accept(vec![
|
/// Accept(vec![
|
||||||
/// qitem(mime::APPLICATION_JSON),
|
/// QualityItem::max(mime::APPLICATION_JSON),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{Accept, QualityItem, q, qitem};
|
/// use actix_web::http::header::{Accept, QualityItem, q};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// Accept(vec![
|
/// Accept(vec![
|
||||||
/// qitem(mime::TEXT_HTML),
|
/// QualityItem::max(mime::TEXT_HTML),
|
||||||
/// qitem("application/xhtml+xml".parse().unwrap()),
|
/// QualityItem::max("application/xhtml+xml".parse().unwrap()),
|
||||||
/// QualityItem::new(
|
/// QualityItem::new(
|
||||||
/// mime::TEXT_XML,
|
/// mime::TEXT_XML,
|
||||||
/// q(900)
|
/// q(900)
|
||||||
/// ),
|
/// ),
|
||||||
/// qitem("image/webp".parse().unwrap()),
|
/// QualityItem::max("image/webp".parse().unwrap()),
|
||||||
/// QualityItem::new(
|
/// QualityItem::new(
|
||||||
/// mime::STAR_STAR,
|
/// mime::STAR_STAR,
|
||||||
/// q(800)
|
/// q(800)
|
||||||
|
@ -86,7 +86,7 @@ crate::http::header::common_header! {
|
||||||
vec![b"audio/*; q=0.2, audio/basic"],
|
vec![b"audio/*; q=0.2, audio/basic"],
|
||||||
Some(Accept(vec![
|
Some(Accept(vec![
|
||||||
QualityItem::new("audio/*".parse().unwrap(), q(200)),
|
QualityItem::new("audio/*".parse().unwrap(), q(200)),
|
||||||
qitem("audio/basic".parse().unwrap()),
|
QualityItem::max("audio/basic".parse().unwrap()),
|
||||||
])));
|
])));
|
||||||
|
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
|
@ -94,11 +94,11 @@ crate::http::header::common_header! {
|
||||||
vec![b"text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
|
vec![b"text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
|
||||||
Some(Accept(vec![
|
Some(Accept(vec![
|
||||||
QualityItem::new(mime::TEXT_PLAIN, q(500)),
|
QualityItem::new(mime::TEXT_PLAIN, q(500)),
|
||||||
qitem(mime::TEXT_HTML),
|
QualityItem::max(mime::TEXT_HTML),
|
||||||
QualityItem::new(
|
QualityItem::new(
|
||||||
"text/x-dvi".parse().unwrap(),
|
"text/x-dvi".parse().unwrap(),
|
||||||
q(800)),
|
q(800)),
|
||||||
qitem("text/x-c".parse().unwrap()),
|
QualityItem::max("text/x-c".parse().unwrap()),
|
||||||
])));
|
])));
|
||||||
|
|
||||||
// Custom tests
|
// Custom tests
|
||||||
|
@ -106,7 +106,7 @@ crate::http::header::common_header! {
|
||||||
test3,
|
test3,
|
||||||
vec![b"text/plain; charset=utf-8"],
|
vec![b"text/plain; charset=utf-8"],
|
||||||
Some(Accept(vec![
|
Some(Accept(vec![
|
||||||
qitem(mime::TEXT_PLAIN_UTF_8),
|
QualityItem::max(mime::TEXT_PLAIN_UTF_8),
|
||||||
])));
|
])));
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test4,
|
test4,
|
||||||
|
@ -130,27 +130,27 @@ crate::http::header::common_header! {
|
||||||
impl Accept {
|
impl Accept {
|
||||||
/// Construct `Accept: */*`.
|
/// Construct `Accept: */*`.
|
||||||
pub fn star() -> Accept {
|
pub fn star() -> Accept {
|
||||||
Accept(vec![qitem(mime::STAR_STAR)])
|
Accept(vec![QualityItem::max(mime::STAR_STAR)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct `Accept: application/json`.
|
/// Construct `Accept: application/json`.
|
||||||
pub fn json() -> Accept {
|
pub fn json() -> Accept {
|
||||||
Accept(vec![qitem(mime::APPLICATION_JSON)])
|
Accept(vec![QualityItem::max(mime::APPLICATION_JSON)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct `Accept: text/*`.
|
/// Construct `Accept: text/*`.
|
||||||
pub fn text() -> Accept {
|
pub fn text() -> Accept {
|
||||||
Accept(vec![qitem(mime::TEXT_STAR)])
|
Accept(vec![QualityItem::max(mime::TEXT_STAR)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct `Accept: image/*`.
|
/// Construct `Accept: image/*`.
|
||||||
pub fn image() -> Accept {
|
pub fn image() -> Accept {
|
||||||
Accept(vec![qitem(mime::IMAGE_STAR)])
|
Accept(vec![QualityItem::max(mime::IMAGE_STAR)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct `Accept: text/html`.
|
/// Construct `Accept: text/html`.
|
||||||
pub fn html() -> Accept {
|
pub fn html() -> Accept {
|
||||||
Accept(vec![qitem(mime::TEXT_HTML)])
|
Accept(vec![QualityItem::max(mime::TEXT_HTML)])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a sorted list of mime types from highest to lowest preference, accounting for
|
/// Returns a sorted list of mime types from highest to lowest preference, accounting for
|
||||||
|
@ -244,11 +244,11 @@ mod tests {
|
||||||
let test = Accept(vec![]);
|
let test = Accept(vec![]);
|
||||||
assert!(test.ranked().is_empty());
|
assert!(test.ranked().is_empty());
|
||||||
|
|
||||||
let test = Accept(vec![qitem(mime::APPLICATION_JSON)]);
|
let test = Accept(vec![QualityItem::max(mime::APPLICATION_JSON)]);
|
||||||
assert_eq!(test.ranked(), vec!(mime::APPLICATION_JSON));
|
assert_eq!(test.ranked(), vec!(mime::APPLICATION_JSON));
|
||||||
|
|
||||||
let test = Accept(vec![
|
let test = Accept(vec![
|
||||||
qitem(mime::TEXT_HTML),
|
QualityItem::max(mime::TEXT_HTML),
|
||||||
"application/xhtml+xml".parse().unwrap(),
|
"application/xhtml+xml".parse().unwrap(),
|
||||||
QualityItem::new("application/xml".parse().unwrap(), q(0.9)),
|
QualityItem::new("application/xml".parse().unwrap(), q(0.9)),
|
||||||
QualityItem::new(mime::STAR_STAR, q(0.8)),
|
QualityItem::new(mime::STAR_STAR, q(0.8)),
|
||||||
|
@ -264,9 +264,9 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let test = Accept(vec![
|
let test = Accept(vec![
|
||||||
qitem(mime::STAR_STAR),
|
QualityItem::max(mime::STAR_STAR),
|
||||||
qitem(mime::IMAGE_STAR),
|
QualityItem::max(mime::IMAGE_STAR),
|
||||||
qitem(mime::IMAGE_PNG),
|
QualityItem::max(mime::IMAGE_PNG),
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test.ranked(),
|
test.ranked(),
|
||||||
|
@ -277,7 +277,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn preference_selection() {
|
fn preference_selection() {
|
||||||
let test = Accept(vec![
|
let test = Accept(vec![
|
||||||
qitem(mime::TEXT_HTML),
|
QualityItem::max(mime::TEXT_HTML),
|
||||||
"application/xhtml+xml".parse().unwrap(),
|
"application/xhtml+xml".parse().unwrap(),
|
||||||
QualityItem::new("application/xml".parse().unwrap(), q(0.9)),
|
QualityItem::new("application/xml".parse().unwrap(), q(0.9)),
|
||||||
QualityItem::new(mime::STAR_STAR, q(0.8)),
|
QualityItem::new(mime::STAR_STAR, q(0.8)),
|
||||||
|
@ -286,9 +286,9 @@ mod tests {
|
||||||
|
|
||||||
let test = Accept(vec![
|
let test = Accept(vec![
|
||||||
QualityItem::new("video/*".parse().unwrap(), q(0.8)),
|
QualityItem::new("video/*".parse().unwrap(), q(0.8)),
|
||||||
qitem(mime::IMAGE_PNG),
|
QualityItem::max(mime::IMAGE_PNG),
|
||||||
QualityItem::new(mime::STAR_STAR, q(0.5)),
|
QualityItem::new(mime::STAR_STAR, q(0.5)),
|
||||||
qitem(mime::IMAGE_SVG),
|
QualityItem::max(mime::IMAGE_SVG),
|
||||||
QualityItem::new(mime::IMAGE_STAR, q(0.8)),
|
QualityItem::new(mime::IMAGE_STAR, q(0.8)),
|
||||||
]);
|
]);
|
||||||
assert_eq!(test.preference(), mime::IMAGE_PNG);
|
assert_eq!(test.preference(), mime::IMAGE_PNG);
|
||||||
|
|
|
@ -22,11 +22,11 @@ crate::http::header::common_header! {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptCharset, Charset, qitem};
|
/// use actix_web::http::header::{AcceptCharset, Charset, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptCharset(vec![qitem(Charset::Us_Ascii)])
|
/// AcceptCharset(vec![QualityItem::max(Charset::Us_Ascii)])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -45,11 +45,11 @@ crate::http::header::common_header! {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptCharset, Charset, qitem};
|
/// use actix_web::http::header::{AcceptCharset, Charset, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))])
|
/// AcceptCharset(vec![QualityItem::max(Charset::Ext("utf-8".to_owned()))])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
||||||
|
|
|
@ -29,36 +29,38 @@ common_header! {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptEncoding, Encoding, qitem};
|
/// use actix_web::http::header::{AcceptEncoding, Encoding, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptEncoding(vec![qitem(Encoding::Chunked)])
|
/// AcceptEncoding(vec![QualityItem::max(Encoding::Chunked)])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptEncoding, Encoding, qitem};
|
/// use actix_web::http::header::{AcceptEncoding, Encoding, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptEncoding(vec![
|
/// AcceptEncoding(vec![
|
||||||
/// qitem(Encoding::Chunked),
|
/// QualityItem::max(Encoding::Chunked),
|
||||||
/// qitem(Encoding::Gzip),
|
/// QualityItem::max(Encoding::Gzip),
|
||||||
/// qitem(Encoding::Deflate),
|
/// QualityItem::max(Encoding::Deflate),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptEncoding, Encoding, QualityItem, q, qitem};
|
/// use actix_web::http::header::{AcceptEncoding, Encoding, QualityItem, q};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptEncoding(vec![
|
/// AcceptEncoding(vec![
|
||||||
/// qitem(Encoding::Chunked),
|
/// QualityItem::max(Encoding::Chunked),
|
||||||
/// QualityItem::new(Encoding::Gzip, q(600)),
|
/// QualityItem::new(Encoding::Gzip, q(600)),
|
||||||
/// QualityItem::new(Encoding::EncodingExt("*".to_owned()), q(0)),
|
/// QualityItem::min(Encoding::EncodingExt("*".to_owned())),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use language_tags::LanguageTag;
|
use language_tags::LanguageTag;
|
||||||
|
|
||||||
use super::{common_header, Preference, QualityItem};
|
use super::{common_header, Preference, Quality, QualityItem};
|
||||||
use crate::http::header;
|
use crate::http::header;
|
||||||
|
|
||||||
common_header! {
|
common_header! {
|
||||||
|
@ -32,24 +32,24 @@ common_header! {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptLanguage, qitem};
|
/// use actix_web::http::header::{AcceptLanguage, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptLanguage(vec![
|
/// AcceptLanguage(vec![
|
||||||
/// qitem("en-US".parse().unwrap())
|
/// QualityItem::max("en-US".parse().unwrap())
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{AcceptLanguage, QualityItem, q, qitem};
|
/// use actix_web::http::header::{AcceptLanguage, QualityItem, q};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// AcceptLanguage(vec![
|
/// AcceptLanguage(vec![
|
||||||
/// qitem("da".parse().unwrap()),
|
/// QualityItem::max("da".parse().unwrap()),
|
||||||
/// QualityItem::new("en-GB".parse().unwrap(), q(800)),
|
/// QualityItem::new("en-GB".parse().unwrap(), q(800)),
|
||||||
/// QualityItem::new("en".parse().unwrap(), q(700)),
|
/// QualityItem::new("en".parse().unwrap(), q(700)),
|
||||||
/// ])
|
/// ])
|
||||||
|
@ -72,9 +72,9 @@ common_header! {
|
||||||
not_ordered_by_weight,
|
not_ordered_by_weight,
|
||||||
vec![b"en-US, en; q=0.5, fr"],
|
vec![b"en-US, en; q=0.5, fr"],
|
||||||
Some(AcceptLanguage(vec![
|
Some(AcceptLanguage(vec![
|
||||||
qitem("en-US".parse().unwrap()),
|
QualityItem::max("en-US".parse().unwrap()),
|
||||||
QualityItem::new("en".parse().unwrap(), q(500)),
|
QualityItem::new("en".parse().unwrap(), q(500)),
|
||||||
qitem("fr".parse().unwrap()),
|
QualityItem::max("fr".parse().unwrap()),
|
||||||
]))
|
]))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ common_header! {
|
||||||
has_wildcard,
|
has_wildcard,
|
||||||
vec![b"fr-CH, fr; q=0.9, en; q=0.8, de; q=0.7, *; q=0.5"],
|
vec![b"fr-CH, fr; q=0.9, en; q=0.8, de; q=0.7, *; q=0.5"],
|
||||||
Some(AcceptLanguage(vec![
|
Some(AcceptLanguage(vec![
|
||||||
qitem("fr-CH".parse().unwrap()),
|
QualityItem::max("fr-CH".parse().unwrap()),
|
||||||
QualityItem::new("fr".parse().unwrap(), q(900)),
|
QualityItem::new("fr".parse().unwrap(), q(900)),
|
||||||
QualityItem::new("en".parse().unwrap(), q(800)),
|
QualityItem::new("en".parse().unwrap(), q(800)),
|
||||||
QualityItem::new("de".parse().unwrap(), q(700)),
|
QualityItem::new("de".parse().unwrap(), q(700)),
|
||||||
|
@ -122,10 +122,8 @@ impl AcceptLanguage {
|
||||||
///
|
///
|
||||||
/// [q-factor weighting]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
/// [q-factor weighting]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
||||||
pub fn preference(&self) -> Preference<LanguageTag> {
|
pub fn preference(&self) -> Preference<LanguageTag> {
|
||||||
use actix_http::header::q;
|
|
||||||
|
|
||||||
let mut max_item = None;
|
let mut max_item = None;
|
||||||
let mut max_pref = q(0);
|
let mut max_pref = Quality::MIN;
|
||||||
|
|
||||||
// uses manual max lookup loop since we want the first occurrence in the case of same
|
// uses manual max lookup loop since we want the first occurrence in the case of same
|
||||||
// preference but `Iterator::max_by_key` would give us the last occurrence
|
// preference but `Iterator::max_by_key` would give us the last occurrence
|
||||||
|
@ -153,7 +151,7 @@ mod tests {
|
||||||
let test = AcceptLanguage(vec![]);
|
let test = AcceptLanguage(vec![]);
|
||||||
assert!(test.ranked().is_empty());
|
assert!(test.ranked().is_empty());
|
||||||
|
|
||||||
let test = AcceptLanguage(vec![qitem("fr-CH".parse().unwrap())]);
|
let test = AcceptLanguage(vec![QualityItem::max("fr-CH".parse().unwrap())]);
|
||||||
assert_eq!(test.ranked(), vec!("fr-CH".parse().unwrap()));
|
assert_eq!(test.ranked(), vec!("fr-CH".parse().unwrap()));
|
||||||
|
|
||||||
let test = AcceptLanguage(vec![
|
let test = AcceptLanguage(vec![
|
||||||
|
@ -175,11 +173,11 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let test = AcceptLanguage(vec![
|
let test = AcceptLanguage(vec![
|
||||||
qitem("fr".parse().unwrap()),
|
QualityItem::max("fr".parse().unwrap()),
|
||||||
qitem("fr-CH".parse().unwrap()),
|
QualityItem::max("fr-CH".parse().unwrap()),
|
||||||
qitem("en".parse().unwrap()),
|
QualityItem::max("en".parse().unwrap()),
|
||||||
qitem("*".parse().unwrap()),
|
QualityItem::max("*".parse().unwrap()),
|
||||||
qitem("de".parse().unwrap()),
|
QualityItem::max("de".parse().unwrap()),
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test.ranked(),
|
test.ranked(),
|
||||||
|
@ -208,11 +206,11 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let test = AcceptLanguage(vec![
|
let test = AcceptLanguage(vec![
|
||||||
qitem("fr".parse().unwrap()),
|
QualityItem::max("fr".parse().unwrap()),
|
||||||
qitem("fr-CH".parse().unwrap()),
|
QualityItem::max("fr-CH".parse().unwrap()),
|
||||||
qitem("en".parse().unwrap()),
|
QualityItem::max("en".parse().unwrap()),
|
||||||
qitem("*".parse().unwrap()),
|
QualityItem::max("*".parse().unwrap()),
|
||||||
qitem("de".parse().unwrap()),
|
QualityItem::max("de".parse().unwrap()),
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test.preference(),
|
test.preference(),
|
||||||
|
|
|
@ -23,25 +23,25 @@ common_header! {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{ContentLanguage, LanguageTag, qitem};
|
/// use actix_web::http::header::{ContentLanguage, LanguageTag, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// ContentLanguage(vec![
|
/// ContentLanguage(vec![
|
||||||
/// qitem(LanguageTag::parse("en").unwrap()),
|
/// QualityItem::max(LanguageTag::parse("en").unwrap()),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::HttpResponse;
|
/// use actix_web::HttpResponse;
|
||||||
/// use actix_web::http::header::{ContentLanguage, LanguageTag, qitem};
|
/// use actix_web::http::header::{ContentLanguage, LanguageTag, QualityItem};
|
||||||
///
|
///
|
||||||
/// let mut builder = HttpResponse::Ok();
|
/// let mut builder = HttpResponse::Ok();
|
||||||
/// builder.insert_header(
|
/// builder.insert_header(
|
||||||
/// ContentLanguage(vec![
|
/// ContentLanguage(vec![
|
||||||
/// qitem(LanguageTag::parse("da").unwrap()),
|
/// QualityItem::max(LanguageTag::parse("da").unwrap()),
|
||||||
/// qitem(LanguageTag::parse("en-GB").unwrap()),
|
/// QualityItem::max(LanguageTag::parse("en-GB").unwrap()),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
|
Loading…
Reference in New Issue