2019-02-07 21:24:24 +00:00
|
|
|
use language_tags::LanguageTag;
|
|
|
|
|
2021-12-02 15:25:39 +00:00
|
|
|
use super::{common_header, QualityItem, CONTENT_LANGUAGE};
|
|
|
|
|
|
|
|
common_header! {
|
2021-12-01 19:42:02 +00:00
|
|
|
/// `Content-Language` header, defined
|
|
|
|
/// in [RFC 7231 §3.1.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.3.2)
|
2019-02-07 21:24:24 +00:00
|
|
|
///
|
|
|
|
/// The `Content-Language` header field describes the natural language(s)
|
|
|
|
/// of the intended audience for the representation. Note that this
|
|
|
|
/// might not be equivalent to all the languages used within the
|
|
|
|
/// representation.
|
|
|
|
///
|
|
|
|
/// # ABNF
|
2021-12-02 15:25:39 +00:00
|
|
|
/// ```plain
|
2019-02-07 21:24:24 +00:00
|
|
|
/// Content-Language = 1#language-tag
|
|
|
|
/// ```
|
|
|
|
///
|
2021-12-01 19:42:02 +00:00
|
|
|
/// # Example Values
|
2019-02-07 21:24:24 +00:00
|
|
|
/// * `da`
|
|
|
|
/// * `mi, en`
|
|
|
|
///
|
|
|
|
/// # Examples
|
2021-01-15 02:11:10 +00:00
|
|
|
/// ```
|
2021-04-01 15:42:18 +00:00
|
|
|
/// use actix_web::HttpResponse;
|
2021-12-05 03:38:08 +00:00
|
|
|
/// use actix_web::http::header::{ContentLanguage, LanguageTag, QualityItem};
|
2021-01-15 02:11:10 +00:00
|
|
|
///
|
2021-04-01 15:42:18 +00:00
|
|
|
/// let mut builder = HttpResponse::Ok();
|
2021-01-15 02:11:10 +00:00
|
|
|
/// builder.insert_header(
|
2019-02-07 21:24:24 +00:00
|
|
|
/// ContentLanguage(vec![
|
2021-12-05 03:38:08 +00:00
|
|
|
/// QualityItem::max(LanguageTag::parse("en").unwrap()),
|
2019-02-07 21:24:24 +00:00
|
|
|
/// ])
|
|
|
|
/// );
|
|
|
|
/// ```
|
|
|
|
///
|
2021-01-15 02:11:10 +00:00
|
|
|
/// ```
|
2021-04-01 15:42:18 +00:00
|
|
|
/// use actix_web::HttpResponse;
|
2021-12-05 03:38:08 +00:00
|
|
|
/// use actix_web::http::header::{ContentLanguage, LanguageTag, QualityItem};
|
2019-02-07 21:24:24 +00:00
|
|
|
///
|
2021-04-01 15:42:18 +00:00
|
|
|
/// let mut builder = HttpResponse::Ok();
|
2021-01-15 02:11:10 +00:00
|
|
|
/// builder.insert_header(
|
2019-02-07 21:24:24 +00:00
|
|
|
/// ContentLanguage(vec![
|
2021-12-05 03:38:08 +00:00
|
|
|
/// QualityItem::max(LanguageTag::parse("da").unwrap()),
|
|
|
|
/// QualityItem::max(LanguageTag::parse("en-GB").unwrap()),
|
2019-02-07 21:24:24 +00:00
|
|
|
/// ])
|
|
|
|
/// );
|
|
|
|
/// ```
|
|
|
|
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
|
|
|
|
2021-12-01 19:42:02 +00:00
|
|
|
test_parse_and_format {
|
2021-06-25 11:25:50 +00:00
|
|
|
crate::http::header::common_header_test!(test1, vec![b"da"]);
|
|
|
|
crate::http::header::common_header_test!(test2, vec![b"mi, en"]);
|
2019-02-07 21:24:24 +00:00
|
|
|
}
|
|
|
|
}
|