1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-05-20 01:08:10 +00:00
actix-web/actix-web/src/http/header/accept_charset.rs

63 lines
2.1 KiB
Rust
Raw Normal View History

2022-01-03 13:17:57 +00:00
use super::{common_header, Charset, QualityItem, ACCEPT_CHARSET};
2019-02-07 21:24:24 +00:00
2022-01-03 13:17:57 +00:00
common_header! {
/// `Accept-Charset` header, defined in [RFC 7231 §5.3.3].
2019-02-07 21:24:24 +00:00
///
/// The `Accept-Charset` header field can be sent by a user agent to
/// indicate what charsets are acceptable in textual response content.
/// This field allows user agents capable of understanding more
/// comprehensive or special-purpose charsets to signal that capability
/// to an origin server that is capable of representing information in
/// those charsets.
///
/// # ABNF
2021-12-02 15:25:39 +00:00
/// ```plain
2019-02-07 21:24:24 +00:00
/// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
/// ```
///
/// # Example Values
2019-02-07 21:24:24 +00:00
/// * `iso-8859-5, unicode-1-1;q=0.8`
///
/// # Examples
2021-01-15 02:11:10 +00:00
/// ```
/// use actix_web::HttpResponse;
/// use actix_web::http::header::{AcceptCharset, Charset, QualityItem};
2019-02-07 21:24:24 +00:00
///
/// let mut builder = HttpResponse::Ok();
2021-01-15 02:11:10 +00:00
/// builder.insert_header(
/// AcceptCharset(vec![QualityItem::max(Charset::Us_Ascii)])
2019-02-07 21:24:24 +00:00
/// );
/// ```
2021-01-15 02:11:10 +00:00
///
/// ```
/// use actix_web::HttpResponse;
/// use actix_web::http::header::{AcceptCharset, Charset, q, QualityItem};
2019-02-07 21:24:24 +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
/// AcceptCharset(vec![
/// QualityItem::new(Charset::Us_Ascii, q(0.9)),
/// QualityItem::new(Charset::Iso_8859_10, q(0.2)),
2019-02-07 21:24:24 +00:00
/// ])
/// );
/// ```
2021-01-15 02:11:10 +00:00
///
/// ```
/// use actix_web::HttpResponse;
/// use actix_web::http::header::{AcceptCharset, Charset, QualityItem};
2019-02-07 21:24:24 +00:00
///
/// let mut builder = HttpResponse::Ok();
2021-01-15 02:11:10 +00:00
/// builder.insert_header(
/// AcceptCharset(vec![QualityItem::max(Charset::Ext("utf-8".to_owned()))])
2019-02-07 21:24:24 +00:00
/// );
/// ```
2022-01-03 13:17:57 +00:00
///
/// [RFC 7231 §5.3.3]: https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.3
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)*
2019-02-07 21:24:24 +00:00
test_parse_and_format {
2020-02-24 22:46:03 +00:00
// Test case from RFC
2022-01-03 13:17:57 +00:00
common_header_test!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
2019-02-07 21:24:24 +00:00
}
}