1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-19 14:14:41 +01:00

Merge branch 'master' into fix-accept-lang

This commit is contained in:
Rob Ede 2021-12-01 19:45:18 +00:00 committed by GitHub
commit 2f9c97461a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 162 additions and 183 deletions

View File

@ -1,9 +1,8 @@
use std::fmt::{self, Display}; use std::{fmt, str};
use std::str::FromStr;
use self::Charset::*; use self::Charset::*;
/// A Mime charset. /// A MIME character set.
/// ///
/// The string representation is normalized to upper case. /// The string representation is normalized to upper case.
/// ///
@ -95,13 +94,13 @@ impl Charset {
} }
} }
impl Display for Charset { impl fmt::Display for Charset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label()) f.write_str(self.label())
} }
} }
impl FromStr for Charset { impl str::FromStr for Charset {
type Err = crate::Error; type Err = crate::Error;
fn from_str(s: &str) -> Result<Charset, crate::Error> { fn from_str(s: &str) -> Result<Charset, crate::Error> {

View File

@ -24,8 +24,8 @@ pub struct ExtendedValue {
pub value: Vec<u8>, pub value: Vec<u8>,
} }
/// Parses extended header parameter values (`ext-value`), as defined in /// Parses extended header parameter values (`ext-value`), as defined
/// [RFC 5987](https://tools.ietf.org/html/rfc5987#section-3.2). /// in [RFC 5987 §3.2](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2).
/// ///
/// Extended values are denoted by parameter names that end with `*`. /// Extended values are denoted by parameter names that end with `*`.
/// ///
@ -34,7 +34,7 @@ pub struct ExtendedValue {
/// ```text /// ```text
/// ext-value = charset "'" [ language ] "'" value-chars /// ext-value = charset "'" [ language ] "'" value-chars
/// ; like RFC 2231's <extended-initial-value> /// ; like RFC 2231's <extended-initial-value>
/// ; (see [RFC2231], Section 7) /// ; (see [RFC 2231 §7])
/// ///
/// charset = "UTF-8" / "ISO-8859-1" / mime-charset /// charset = "UTF-8" / "ISO-8859-1" / mime-charset
/// ///
@ -43,22 +43,26 @@ pub struct ExtendedValue {
/// / "!" / "#" / "$" / "%" / "&" /// / "!" / "#" / "$" / "%" / "&"
/// / "+" / "-" / "^" / "_" / "`" /// / "+" / "-" / "^" / "_" / "`"
/// / "{" / "}" / "~" /// / "{" / "}" / "~"
/// ; as <mime-charset> in Section 2.3 of [RFC2978] /// ; as <mime-charset> in [RFC 2978 §2.3]
/// ; except that the single quote is not included /// ; except that the single quote is not included
/// ; SHOULD be registered in the IANA charset registry /// ; SHOULD be registered in the IANA charset registry
/// ///
/// language = <Language-Tag, defined in [RFC5646], Section 2.1> /// language = <Language-Tag, defined in [RFC 5646 §2.1]>
/// ///
/// value-chars = *( pct-encoded / attr-char ) /// value-chars = *( pct-encoded / attr-char )
/// ///
/// pct-encoded = "%" HEXDIG HEXDIG /// pct-encoded = "%" HEXDIG HEXDIG
/// ; see [RFC3986], Section 2.1 /// ; see [RFC 3986 §2.1]
/// ///
/// attr-char = ALPHA / DIGIT /// attr-char = ALPHA / DIGIT
/// / "!" / "#" / "$" / "&" / "+" / "-" / "." /// / "!" / "#" / "$" / "&" / "+" / "-" / "."
/// / "^" / "_" / "`" / "|" / "~" /// / "^" / "_" / "`" / "|" / "~"
/// ; token except ( "*" / "'" / "%" ) /// ; token except ( "*" / "'" / "%" )
/// ``` /// ```
///
/// [RFC 2231 §7]: https://datatracker.ietf.org/doc/html/rfc2231#section-7
/// [RFC 2978 §2.3]: https://datatracker.ietf.org/doc/html/rfc2978#section-2.3
/// [RFC 3986 §2.1]: https://datatracker.ietf.org/doc/html/rfc5646#section-2.1
pub fn parse_extended_value( pub fn parse_extended_value(
val: &str, val: &str,
) -> Result<ExtendedValue, crate::error::ParseError> { ) -> Result<ExtendedValue, crate::error::ParseError> {

View File

@ -13,8 +13,10 @@ where
T: FromStr, T: FromStr,
{ {
let mut result = Vec::new(); let mut result = Vec::new();
for h in all { for h in all {
let s = h.to_str().map_err(|_| ParseError::Header)?; let s = h.to_str().map_err(|_| ParseError::Header)?;
result.extend( result.extend(
s.split(',') s.split(',')
.filter_map(|x| match x.trim() { .filter_map(|x| match x.trim() {

View File

@ -3,7 +3,9 @@ use std::{
fmt, fmt,
}; };
/// Operation codes as part of RFC6455. /// Operation codes defined in [RFC 6455 §11.8].
///
/// [RFC 6455]: https://datatracker.ietf.org/doc/html/rfc6455#section-11.8
#[derive(Debug, Eq, PartialEq, Clone, Copy)] #[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum OpCode { pub enum OpCode {
/// Indicates a continuation frame of a fragmented message. /// Indicates a continuation frame of a fragmented message.
@ -105,7 +107,7 @@ pub enum CloseCode {
Abnormal, Abnormal,
/// Indicates that an endpoint is terminating the connection because it has received data within /// Indicates that an endpoint is terminating the connection because it has received data within
/// a message that was not consistent with the type of the message (e.g., non-UTF-8 \[RFC3629\] /// a message that was not consistent with the type of the message (e.g., non-UTF-8 \[RFC 3629\]
/// data within a text message). /// data within a text message).
Invalid, Invalid,

View File

@ -312,9 +312,8 @@ impl WebsocketsRequest {
); );
} }
// Generate a random key for the `Sec-WebSocket-Key` header. // Generate a random key for the `Sec-WebSocket-Key` header which is a base64-encoded
// a base64-encoded (see Section 4 of [RFC4648]) value that, // (see RFC 4648 §4) value that, when decoded, is 16 bytes in length (RFC 6455 §1.3).
// when decoded, is 16 bytes in length (RFC 6455)
let sec_key: [u8; 16] = rand::random(); let sec_key: [u8; 16] = rand::random();
let key = base64::encode(&sec_key); let key = base64::encode(&sec_key);

View File

@ -6,7 +6,8 @@ use super::{qitem, QualityItem};
use crate::http::header; use crate::http::header;
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Accept` header, defined in [RFC 7231](http://tools.ietf.org/html/rfc7231#section-5.3.2) /// `Accept` header, defined
/// in [RFC 7231 §5.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2)
/// ///
/// The `Accept` header field can be used by user agents to specify /// The `Accept` header field can be used by user agents to specify
/// response media types that are acceptable. Accept header fields can /// response media types that are acceptable. Accept header fields can
@ -15,7 +16,6 @@ crate::http::header::common_header! {
/// in-line image /// in-line image
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Accept = #( media-range [ accept-params ] ) /// Accept = #( media-range [ accept-params ] )
/// ///
@ -27,7 +27,7 @@ crate::http::header::common_header! {
/// accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ] /// accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ]
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// * `audio/*; q=0.2, audio/basic` /// * `audio/*; q=0.2, audio/basic`
/// * `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c` /// * `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c`
/// ///
@ -79,7 +79,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(Accept, header::ACCEPT) => (QualityItem<Mime>)+ (Accept, header::ACCEPT) => (QualityItem<Mime>)+
common_tests { test_parse_and_format {
// Tests from the RFC // Tests from the RFC
crate::http::header::common_header_test!( crate::http::header::common_header_test!(
test1, test1,

View File

@ -2,7 +2,7 @@ use super::{Charset, QualityItem, ACCEPT_CHARSET};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Accept-Charset` header, defined in /// `Accept-Charset` header, defined in
/// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.3) /// [RFC 7231 §5.3.3](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.3)
/// ///
/// The `Accept-Charset` header field can be sent by a user agent to /// The `Accept-Charset` header field can be sent by a user agent to
/// indicate what charsets are acceptable in textual response content. /// indicate what charsets are acceptable in textual response content.
@ -12,12 +12,11 @@ crate::http::header::common_header! {
/// those charsets. /// those charsets.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Accept-Charset = 1#( ( charset / "*" ) [ weight ] ) /// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// * `iso-8859-5, unicode-1-1;q=0.8` /// * `iso-8859-5, unicode-1-1;q=0.8`
/// ///
/// # Examples /// # Examples
@ -55,7 +54,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+ (AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
test_accept_charset { test_parse_and_format {
// Test case from RFC // Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]); crate::http::header::common_header_test!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
} }

View File

@ -1,8 +1,8 @@
use header::{Encoding, QualityItem}; use header::{Encoding, QualityItem};
header! { header! {
/// `Accept-Encoding` header, defined in /// `Accept-Encoding` header, defined
/// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.4) /// in [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4)
/// ///
/// The `Accept-Encoding` header field can be used by user agents to /// The `Accept-Encoding` header field can be used by user agents to
/// indicate what response content-codings are /// indicate what response content-codings are
@ -11,13 +11,12 @@ header! {
/// preferred. /// preferred.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Accept-Encoding = #( codings [ weight ] ) /// Accept-Encoding = #( codings [ weight ] )
/// codings = content-coding / "identity" / "*" /// codings = content-coding / "identity" / "*"
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// * `compress, gzip` /// * `compress, gzip`
/// * `` /// * ``
/// * `*` /// * `*`
@ -62,7 +61,7 @@ header! {
/// ``` /// ```
(AcceptEncoding, "Accept-Encoding") => (QualityItem<Encoding>)* (AcceptEncoding, "Accept-Encoding") => (QualityItem<Encoding>)*
test_accept_encoding { test_parse_and_format {
// From the RFC // From the RFC
crate::http::header::common_header_test!(test1, vec![b"compress, gzip"]); crate::http::header::common_header_test!(test1, vec![b"compress, gzip"]);
crate::http::header::common_header_test!(test2, vec![b""], Some(AcceptEncoding(vec![]))); crate::http::header::common_header_test!(test2, vec![b""], Some(AcceptEncoding(vec![])));

View File

@ -1,27 +1,27 @@
use crate::http::header;
use actix_http::http::Method; use actix_http::http::Method;
use crate::http::header;
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1) /// `Allow` header, defined
/// in [RFC 7231 §7.4.1](https://datatracker.ietf.org/doc/html/rfc7231#section-7.4.1)
/// ///
/// The `Allow` header field lists the set of methods advertised as /// The `Allow` header field lists the set of methods advertised as
/// supported by the target resource. The purpose of this field is /// supported by the target resource. The purpose of this field is
/// strictly to inform the recipient of valid request methods associated /// strictly to inform the recipient of valid request methods associated
/// with the resource. /// with the resource.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Allow = #method /// Allow = #method
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// * `GET, HEAD, PUT` /// * `GET, HEAD, PUT`
/// * `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr` /// * `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr`
/// * `` /// * ``
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::HttpResponse; /// use actix_web::HttpResponse;
/// use actix_web::http::{header::Allow, Method}; /// use actix_web::http::{header::Allow, Method};
@ -47,7 +47,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(Allow, header::ALLOW) => (Method)* (Allow, header::ALLOW) => (Method)*
test_allow { test_parse_and_format {
// From the RFC // From the RFC
crate::http::header::common_header_test!( crate::http::header::common_header_test!(
test1, test1,

View File

@ -5,7 +5,8 @@ use super::{fmt_comma_delimited, from_comma_delimited, Header, IntoHeaderValue,
use crate::http::header; use crate::http::header;
/// `Cache-Control` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.2) /// `Cache-Control` header, defined
/// in [RFC 7234 §5.2](https://datatracker.ietf.org/doc/html/rfc7234#section-5.2).
/// ///
/// The `Cache-Control` header field is used to specify directives for /// The `Cache-Control` header field is used to specify directives for
/// caches along the request/response chain. Such cache directives are /// caches along the request/response chain. Such cache directives are
@ -13,13 +14,12 @@ use crate::http::header;
/// not imply that the same directive is to be given in the response. /// not imply that the same directive is to be given in the response.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Cache-Control = 1#cache-directive /// Cache-Control = 1#cache-directive
/// cache-directive = token [ "=" ( token / quoted-string ) ] /// cache-directive = token [ "=" ( token / quoted-string ) ]
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// ///
/// * `no-cache` /// * `no-cache`
/// * `private, community="UCI"` /// * `private, community="UCI"`

View File

@ -1,10 +1,14 @@
//! # References //! The `Content-Disposition` header and associated types.
//! //!
//! "The Content-Disposition Header Field" <https://www.ietf.org/rfc/rfc2183.txt> //! # References
//! "The Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)" <https://www.ietf.org/rfc/rfc6266.txt> //! - "The Content-Disposition Header Field":
//! "Returning Values from Forms: multipart/form-data" <https://www.ietf.org/rfc/rfc7578.txt> //! <https://datatracker.ietf.org/doc/html/rfc2183>
//! Browser conformance tests at: <http://greenbytes.de/tech/tc2231/> //! - "The Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)":
//! IANA assignment: <http://www.iana.org/assignments/cont-disp/cont-disp.xhtml> //! <https://datatracker.ietf.org/doc/html/rfc6266>
//! - "Returning Values from Forms: multipart/form-data":
//! <https://datatracker.ietf.org/doc/html/rfc7578>
//! - Browser conformance tests at: <http://greenbytes.de/tech/tc2231/>
//! - IANA assignment: <http://www.iana.org/assignments/cont-disp/cont-disp.xhtml>
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
@ -41,8 +45,9 @@ pub enum DispositionType {
/// rather than process it normally (as per its media type). /// rather than process it normally (as per its media type).
Attachment, Attachment,
/// Used in *multipart/form-data* as defined in [RFC7578](https://tools.ietf.org/html/rfc7578) /// Used in *multipart/form-data* as defined in
/// to carry the field name and optional filename. /// [RFC 7578](https://datatracker.ietf.org/doc/html/rfc7578) to carry the field name and
/// optional filename.
FormData, FormData,
/// Extension type. Should be handled by recipients the same way as Attachment. /// Extension type. Should be handled by recipients the same way as Attachment.
@ -82,26 +87,29 @@ pub enum DispositionParam {
/// A plain file name. /// A plain file name.
/// ///
/// It is [not supposed](https://tools.ietf.org/html/rfc6266#appendix-D) to contain any /// It is [not supposed](https://datatracker.ietf.org/doc/html/rfc6266#appendix-D) to contain
/// non-ASCII characters when used in a *Content-Disposition* HTTP response header, where /// any non-ASCII characters when used in a *Content-Disposition* HTTP response header, where
/// [`FilenameExt`](DispositionParam::FilenameExt) with charset UTF-8 may be used instead /// [`FilenameExt`](DispositionParam::FilenameExt) with charset UTF-8 may be used instead
/// in case there are Unicode characters in file names. /// in case there are Unicode characters in file names.
Filename(String), Filename(String),
/// An extended file name. It must not exist for `ContentType::Formdata` according to /// An extended file name. It must not exist for `ContentType::Formdata` according to
/// [RFC7578 Section 4.2](https://tools.ietf.org/html/rfc7578#section-4.2). /// [RFC 7578 §4.2](https://datatracker.ietf.org/doc/html/rfc7578#section-4.2).
FilenameExt(ExtendedValue), FilenameExt(ExtendedValue),
/// An unrecognized regular parameter as defined in /// An unrecognized regular parameter as defined in
/// [RFC5987](https://tools.ietf.org/html/rfc5987) as *reg-parameter*, in /// [RFC 5987 §3.2.1](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1) as
/// [RFC6266](https://tools.ietf.org/html/rfc6266) as *token "=" value*. Recipients should /// `reg-parameter`, in
/// ignore unrecognizable parameters. /// [RFC 6266 §4.1](https://datatracker.ietf.org/doc/html/rfc6266#section-4.1) as
/// `token "=" value`. Recipients should ignore unrecognizable parameters.
Unknown(String, String), Unknown(String, String),
/// An unrecognized extended parameter as defined in /// An unrecognized extended parameter as defined in
/// [RFC5987](https://tools.ietf.org/html/rfc5987) as *ext-parameter*, in /// [RFC 5987 §3.2.1](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1) as
/// [RFC6266](https://tools.ietf.org/html/rfc6266) as *ext-token "=" ext-value*. The single /// `ext-parameter`, in
/// trailing asterisk is not included. Recipients should ignore unrecognizable parameters. /// [RFC 6266 §4.1](https://datatracker.ietf.org/doc/html/rfc6266#section-4.1) as
/// `ext-token "=" ext-value`. The single trailing asterisk is not included. Recipients should
/// ignore unrecognizable parameters.
UnknownExt(String, ExtendedValue), UnknownExt(String, ExtendedValue),
} }
@ -195,10 +203,10 @@ impl DispositionParam {
} }
/// A *Content-Disposition* header. It is compatible to be used either as /// A *Content-Disposition* header. It is compatible to be used either as
/// [a response header for the main body](https://mdn.io/Content-Disposition#As_a_response_header_for_the_main_body) /// [a response header for the main body](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#as_a_response_header_for_the_main_body)
/// as (re)defined in [RFC6266](https://tools.ietf.org/html/rfc6266), or as /// as (re)defined in [RFC 6266](https://tools.ietf.org/html/rfc6266), or as
/// [a header for a multipart body](https://mdn.io/Content-Disposition#As_a_header_for_a_multipart_body) /// [a header for a multipart body](https://mdn.io/Content-Disposition#As_a_header_for_a_multipart_body)
/// as (re)defined in [RFC7587](https://tools.ietf.org/html/rfc7578). /// as (re)defined in [RFC 7587](https://tools.ietf.org/html/rfc7578).
/// ///
/// In a regular HTTP response, the *Content-Disposition* response header is a header indicating if /// In a regular HTTP response, the *Content-Disposition* response header is a header indicating if
/// the content is expected to be displayed *inline* in the browser, that is, as a Web page or as /// the content is expected to be displayed *inline* in the browser, that is, as a Web page or as
@ -233,19 +241,17 @@ impl DispositionParam {
/// ``` /// ```
/// ///
/// # Note /// # Note
/// *filename* is [not supposed](https://datatracker.ietf.org/doc/html/rfc6266#appendix-D) to
/// contain any non-ASCII characters when used in a *Content-Disposition* HTTP response header,
/// where filename* with charset UTF-8 may be used instead in case there are Unicode characters in
/// file names. Filename is [acceptable](https://datatracker.ietf.org/doc/html/rfc7578#section-4.2)
/// to be UTF-8 encoded directly in a *Content-Disposition* header for
/// *multipart/form-data*, though.
/// ///
/// filename is [not supposed](https://tools.ietf.org/html/rfc6266#appendix-D) to contain any /// *filename* [must not](https://datatracker.ietf.org/doc/html/rfc7578#section-4.2) be used within
/// non-ASCII characters when used in a *Content-Disposition* HTTP response header, where
/// filename* with charset UTF-8 may be used instead in case there are Unicode characters in file
/// names.
/// filename is [acceptable](https://tools.ietf.org/html/rfc7578#section-4.2) to be UTF-8 encoded
/// directly in a *Content-Disposition* header for *multipart/form-data*, though.
///
/// filename* [must not](https://tools.ietf.org/html/rfc7578#section-4.2) be used within
/// *multipart/form-data*. /// *multipart/form-data*.
/// ///
/// # Example /// # Examples
///
/// ``` /// ```
/// use actix_web::http::header::{ /// use actix_web::http::header::{
/// Charset, ContentDisposition, DispositionParam, DispositionType, /// Charset, ContentDisposition, DispositionParam, DispositionType,
@ -291,10 +297,9 @@ impl DispositionParam {
/// ``` /// ```
/// ///
/// # Security Note /// # Security Note
///
/// If "filename" parameter is supplied, do not use the file name blindly, check and possibly /// If "filename" parameter is supplied, do not use the file name blindly, check and possibly
/// change to match local file system conventions if applicable, and do not use directory path /// change to match local file system conventions if applicable, and do not use directory path
/// information that may be present. See [RFC2183](https://tools.ietf.org/html/rfc2183#section-2.3). /// information that may be present. See [RFC 2183](https://tools.ietf.org/html/rfc2183#section-2.3).
// TODO: private fields and use smallvec // TODO: private fields and use smallvec
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct ContentDisposition { pub struct ContentDisposition {
@ -342,7 +347,7 @@ impl ContentDisposition {
} else { } else {
// regular parameters // regular parameters
let value = if left.starts_with('\"') { let value = if left.starts_with('\"') {
// quoted-string: defined in RFC6266 -> RFC2616 Section 3.6 // quoted-string: defined in RFC 6266 -> RFC 2616 Section 3.6
let mut escaping = false; let mut escaping = false;
let mut quoted_string = vec![]; let mut quoted_string = vec![];
let mut end = None; let mut end = None;
@ -393,22 +398,22 @@ impl ContentDisposition {
Ok(cd) Ok(cd)
} }
/// Returns `true` if it is [`Inline`](DispositionType::Inline). /// Returns `true` if type is [`Inline`](DispositionType::Inline).
pub fn is_inline(&self) -> bool { pub fn is_inline(&self) -> bool {
matches!(self.disposition, DispositionType::Inline) matches!(self.disposition, DispositionType::Inline)
} }
/// Returns `true` if it is [`Attachment`](DispositionType::Attachment). /// Returns `true` if type is [`Attachment`](DispositionType::Attachment).
pub fn is_attachment(&self) -> bool { pub fn is_attachment(&self) -> bool {
matches!(self.disposition, DispositionType::Attachment) matches!(self.disposition, DispositionType::Attachment)
} }
/// Returns `true` if it is [`FormData`](DispositionType::FormData). /// Returns `true` if type is [`FormData`](DispositionType::FormData).
pub fn is_form_data(&self) -> bool { pub fn is_form_data(&self) -> bool {
matches!(self.disposition, DispositionType::FormData) matches!(self.disposition, DispositionType::FormData)
} }
/// Returns `true` if it is [`Ext`](DispositionType::Ext) and the `disp_type` matches. /// Returns `true` if type is [`Ext`](DispositionType::Ext) and the `disp_type` matches.
pub fn is_ext(&self, disp_type: impl AsRef<str>) -> bool { pub fn is_ext(&self, disp_type: impl AsRef<str>) -> bool {
matches!( matches!(
self.disposition, self.disposition,
@ -487,7 +492,9 @@ impl fmt::Display for DispositionParam {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// All ASCII control characters (0-30, 127) including horizontal tab, double quote, and // All ASCII control characters (0-30, 127) including horizontal tab, double quote, and
// backslash should be escaped in quoted-string (i.e. "foobar"). // backslash should be escaped in quoted-string (i.e. "foobar").
// Ref: RFC6266 S4.1 -> RFC2616 S3.6 //
// Ref: RFC 6266 §4.1 -> RFC 2616 §3.6
//
// filename-parm = "filename" "=" value // filename-parm = "filename" "=" value
// value = token | quoted-string // value = token | quoted-string
// quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) // quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
@ -501,7 +508,7 @@ impl fmt::Display for DispositionParam {
// CTL = <any US-ASCII control character // CTL = <any US-ASCII control character
// (octets 0 - 31) and DEL (127)> // (octets 0 - 31) and DEL (127)>
// //
// Ref: RFC7578 S4.2 -> RFC2183 S2 -> RFC2045 S5.1 // Ref: RFC 7578 S4.2 -> RFC 2183 S2 -> RFC 2045 S5.1
// parameter := attribute "=" value // parameter := attribute "=" value
// attribute := token // attribute := token
// ; Matching of attributes // ; Matching of attributes
@ -746,7 +753,7 @@ mod tests {
#[test] #[test]
fn from_raw_with_unicode() { fn from_raw_with_unicode() {
/* RFC7578 Section 4.2: /* RFC 7578 Section 4.2:
Some commonly deployed systems use multipart/form-data with file names directly encoded Some commonly deployed systems use multipart/form-data with file names directly encoded
including octets outside the US-ASCII range. The encoding used for the file names is including octets outside the US-ASCII range. The encoding used for the file names is
typically UTF-8, although HTML forms will use the charset associated with the form. typically UTF-8, although HTML forms will use the charset associated with the form.
@ -819,9 +826,9 @@ mod tests {
#[test] #[test]
fn test_from_raw_unnecessary_percent_decode() { fn test_from_raw_unnecessary_percent_decode() {
// In fact, RFC7578 (multipart/form-data) Section 2 and 4.2 suggests that filename with // In fact, RFC 7578 (multipart/form-data) Section 2 and 4.2 suggests that filename with
// non-ASCII characters MAY be percent-encoded. // non-ASCII characters MAY be percent-encoded.
// On the contrary, RFC6266 or other RFCs related to Content-Disposition response header // On the contrary, RFC 6266 or other RFCs related to Content-Disposition response header
// do not mention such percent-encoding. // do not mention such percent-encoding.
// So, it appears to be undecidable whether to percent-decode or not without // So, it appears to be undecidable whether to percent-decode or not without
// knowing the usage scenario (multipart/form-data v.s. HTTP response header) and // knowing the usage scenario (multipart/form-data v.s. HTTP response header) and

View File

@ -2,8 +2,8 @@ use super::{QualityItem, CONTENT_LANGUAGE};
use language_tags::LanguageTag; use language_tags::LanguageTag;
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Content-Language` header, defined in /// `Content-Language` header, defined
/// [RFC7231](https://tools.ietf.org/html/rfc7231#section-3.1.3.2) /// in [RFC 7231 §3.1.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.3.2)
/// ///
/// The `Content-Language` header field describes the natural language(s) /// The `Content-Language` header field describes the natural language(s)
/// of the intended audience for the representation. Note that this /// of the intended audience for the representation. Note that this
@ -11,18 +11,15 @@ crate::http::header::common_header! {
/// representation. /// representation.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Content-Language = 1#language-tag /// Content-Language = 1#language-tag
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `da` /// * `da`
/// * `mi, en` /// * `mi, en`
/// ///
/// # 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, qitem};
@ -49,7 +46,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+ (ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
test_content_language { test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"da"]); crate::http::header::common_header_test!(test1, vec![b"da"]);
crate::http::header::common_header_test!(test2, vec![b"mi, en"]); crate::http::header::common_header_test!(test2, vec![b"mi, en"]);
} }

View File

@ -1,15 +1,17 @@
use std::fmt::{self, Display, Write}; use std::{
use std::str::FromStr; fmt::{self, Display, Write},
str::FromStr,
};
use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer, CONTENT_RANGE}; use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer, CONTENT_RANGE};
use crate::error::ParseError; use crate::error::ParseError;
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Content-Range` header, defined in /// `Content-Range` header, defined
/// [RFC7233](http://tools.ietf.org/html/rfc7233#section-4.2) /// in [RFC 7233 §4.2](https://datatracker.ietf.org/doc/html/rfc7233#section-4.2)
(ContentRange, CONTENT_RANGE) => [ContentRangeSpec] (ContentRange, CONTENT_RANGE) => [ContentRangeSpec]
test_content_range { test_parse_and_format {
crate::http::header::common_header_test!(test_bytes, crate::http::header::common_header_test!(test_bytes,
vec![b"bytes 0-499/500"], vec![b"bytes 0-499/500"],
Some(ContentRange(ContentRangeSpec::Bytes { Some(ContentRange(ContentRangeSpec::Bytes {
@ -69,10 +71,9 @@ crate::http::header::common_header! {
} }
} }
/// Content-Range, described in [RFC7233](https://tools.ietf.org/html/rfc7233#section-4.2) /// Content-Range, described in [RFC 7233](https://tools.ietf.org/html/rfc7233#section-4.2)
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Content-Range = byte-content-range /// Content-Range = byte-content-range
/// / other-content-range /// / other-content-range

View File

@ -2,8 +2,8 @@ use super::CONTENT_TYPE;
use mime::Mime; use mime::Mime;
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Content-Type` header, defined in /// `Content-Type` header, defined
/// [RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.1.5) /// in [RFC 7231 §3.1.1.5](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.5)
/// ///
/// The `Content-Type` header field indicates the media type of the /// The `Content-Type` header field indicates the media type of the
/// associated representation: either the representation enclosed in the /// associated representation: either the representation enclosed in the
@ -18,18 +18,15 @@ crate::http::header::common_header! {
/// this is an issue, it's possible to implement `Header` on a custom struct. /// this is an issue, it's possible to implement `Header` on a custom struct.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Content-Type = media-type /// Content-Type = media-type
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `text/html; charset=utf-8` /// * `text/html; charset=utf-8`
/// * `application/json` /// * `application/json`
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::HttpResponse; /// use actix_web::HttpResponse;
/// use actix_web::http::header::ContentType; /// use actix_web::http::header::ContentType;
@ -51,7 +48,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(ContentType, CONTENT_TYPE) => [Mime] (ContentType, CONTENT_TYPE) => [Mime]
test_content_type { test_parse_and_format {
crate::http::header::common_header_test!( crate::http::header::common_header_test!(
test1, test1,
vec![b"text/html"], vec![b"text/html"],

View File

@ -2,19 +2,18 @@ use super::{HttpDate, DATE};
use std::time::SystemTime; use std::time::SystemTime;
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Date` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.1.1.2) /// `Date` header, defined
/// in [RFC 7231 §7.1.1.2](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2)
/// ///
/// The `Date` header field represents the date and time at which the /// The `Date` header field represents the date and time at which the
/// message was originated. /// message was originated.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Date = HTTP-date /// Date = HTTP-date
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `Tue, 15 Nov 1994 08:12:31 GMT` /// * `Tue, 15 Nov 1994 08:12:31 GMT`
/// ///
/// # Example /// # Example
@ -31,7 +30,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(Date, DATE) => [HttpDate] (Date, DATE) => [HttpDate]
test_date { test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"Tue, 15 Nov 1994 08:12:31 GMT"]); crate::http::header::common_header_test!(test1, vec![b"Tue, 15 Nov 1994 08:12:31 GMT"]);
} }
} }

View File

@ -1,5 +1,7 @@
use std::fmt::{self, Display, Write}; use std::{
use std::str::FromStr; fmt::{self, Display, Write},
str::FromStr,
};
use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer}; use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer};
@ -15,7 +17,8 @@ fn check_slice_validity(slice: &str) -> bool {
slice.bytes().all(entity_validate_char) slice.bytes().all(entity_validate_char)
} }
/// An entity tag, defined in [RFC7232](https://tools.ietf.org/html/rfc7232#section-2.3) /// An entity tag, defined
/// in [RFC 7232 §2.3](https://datatracker.ietf.org/doc/html/rfc7232#section-2.3)
/// ///
/// An entity tag consists of a string enclosed by two literal double quotes. /// An entity tag consists of a string enclosed by two literal double quotes.
/// Preceding the first double quote is an optional weakness indicator, /// Preceding the first double quote is an optional weakness indicator,
@ -23,7 +26,6 @@ fn check_slice_validity(slice: &str) -> bool {
/// `W/"xyzzy"`. /// `W/"xyzzy"`.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// entity-tag = [ weak ] opaque-tag /// entity-tag = [ weak ] opaque-tag
/// weak = %x57.2F ; "W/", case-sensitive /// weak = %x57.2F ; "W/", case-sensitive

View File

@ -1,7 +1,8 @@
use super::{EntityTag, ETAG}; use super::{EntityTag, ETAG};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `ETag` header, defined in [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.3) /// `ETag` header, defined in
/// [RFC 7232 §2.3](https://datatracker.ietf.org/doc/html/rfc7232#section-2.3)
/// ///
/// The `ETag` header field in a response provides the current entity-tag /// The `ETag` header field in a response provides the current entity-tag
/// for the selected representation, as determined at the conclusion of /// for the selected representation, as determined at the conclusion of
@ -14,19 +15,16 @@ crate::http::header::common_header! {
/// prefixed by a weakness indicator. /// prefixed by a weakness indicator.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// ETag = entity-tag /// ETag = entity-tag
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `"xyzzy"` /// * `"xyzzy"`
/// * `W/"xyzzy"` /// * `W/"xyzzy"`
/// * `""` /// * `""`
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::HttpResponse; /// use actix_web::HttpResponse;
/// use actix_web::http::header::{ETag, EntityTag}; /// use actix_web::http::header::{ETag, EntityTag};
@ -48,7 +46,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(ETag, ETAG) => [EntityTag] (ETag, ETAG) => [EntityTag]
test_etag { test_parse_and_format {
// From the RFC // From the RFC
crate::http::header::common_header_test!(test1, crate::http::header::common_header_test!(test1,
vec![b"\"xyzzy\""], vec![b"\"xyzzy\""],

View File

@ -1,7 +1,8 @@
use super::{HttpDate, EXPIRES}; use super::{HttpDate, EXPIRES};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Expires` header, defined in [RFC7234](http://tools.ietf.org/html/rfc7234#section-5.3) /// `Expires` header, defined
/// in [RFC 7234 §5.3](https://datatracker.ietf.org/doc/html/rfc7234#section-5.3)
/// ///
/// The `Expires` header field gives the date/time after which the /// The `Expires` header field gives the date/time after which the
/// response is considered stale. /// response is considered stale.
@ -11,12 +12,11 @@ crate::http::header::common_header! {
/// time. /// time.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Expires = HTTP-date /// Expires = HTTP-date
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// * `Thu, 01 Dec 1994 16:00:00 GMT` /// * `Thu, 01 Dec 1994 16:00:00 GMT`
/// ///
/// # Example /// # Example
@ -34,7 +34,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(Expires, EXPIRES) => [HttpDate] (Expires, EXPIRES) => [HttpDate]
test_expires { test_parse_and_format {
// Test case from RFC // Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Thu, 01 Dec 1994 16:00:00 GMT"]); crate::http::header::common_header_test!(test1, vec![b"Thu, 01 Dec 1994 16:00:00 GMT"]);
} }

View File

@ -1,8 +1,8 @@
use super::{EntityTag, IF_MATCH}; use super::{EntityTag, IF_MATCH};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `If-Match` header, defined in /// `If-Match` header, defined
/// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.1) /// in [RFC 7232 §3.1](https://datatracker.ietf.org/doc/html/rfc7232#section-3.1)
/// ///
/// The `If-Match` header field makes the request method conditional on /// The `If-Match` header field makes the request method conditional on
/// the recipient origin server either having at least one current /// the recipient origin server either having at least one current
@ -17,18 +17,15 @@ crate::http::header::common_header! {
/// there have been any changes to the representation data. /// there have been any changes to the representation data.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// If-Match = "*" / 1#entity-tag /// If-Match = "*" / 1#entity-tag
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `"xyzzy"` /// * `"xyzzy"`
/// * "xyzzy", "r2d2xxxx", "c3piozzzz" /// * "xyzzy", "r2d2xxxx", "c3piozzzz"
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::HttpResponse; /// use actix_web::HttpResponse;
/// use actix_web::http::header::IfMatch; /// use actix_web::http::header::IfMatch;
@ -52,7 +49,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(IfMatch, IF_MATCH) => {Any / (EntityTag)+} (IfMatch, IF_MATCH) => {Any / (EntityTag)+}
test_if_match { test_parse_and_format {
crate::http::header::common_header_test!( crate::http::header::common_header_test!(
test1, test1,
vec![b"\"xyzzy\""], vec![b"\"xyzzy\""],

View File

@ -1,8 +1,8 @@
use super::{HttpDate, IF_MODIFIED_SINCE}; use super::{HttpDate, IF_MODIFIED_SINCE};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `If-Modified-Since` header, defined in /// `If-Modified-Since` header, defined
/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-3.3) /// in [RFC 7232 §3.3](https://datatracker.ietf.org/doc/html/rfc7232#section-3.3)
/// ///
/// The `If-Modified-Since` header field makes a GET or HEAD request /// The `If-Modified-Since` header field makes a GET or HEAD request
/// method conditional on the selected representation's modification date /// method conditional on the selected representation's modification date
@ -11,12 +11,11 @@ crate::http::header::common_header! {
/// data has not changed. /// data has not changed.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// If-Unmodified-Since = HTTP-date /// If-Unmodified-Since = HTTP-date
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// * `Sat, 29 Oct 1994 19:43:31 GMT` /// * `Sat, 29 Oct 1994 19:43:31 GMT`
/// ///
/// # Example /// # Example
@ -34,7 +33,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate] (IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate]
test_if_modified_since { test_parse_and_format {
// Test case from RFC // Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]); crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
} }

View File

@ -1,8 +1,8 @@
use super::{EntityTag, IF_NONE_MATCH}; use super::{EntityTag, IF_NONE_MATCH};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `If-None-Match` header, defined in /// `If-None-Match` header, defined
/// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.2) /// in [RFC 7232 §3.2](https://datatracker.ietf.org/doc/html/rfc7232#section-3.2)
/// ///
/// The `If-None-Match` header field makes the request method conditional /// The `If-None-Match` header field makes the request method conditional
/// on a recipient cache or origin server either not having any current /// on a recipient cache or origin server either not having any current
@ -16,13 +16,11 @@ crate::http::header::common_header! {
/// the representation data. /// the representation data.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// If-None-Match = "*" / 1#entity-tag /// If-None-Match = "*" / 1#entity-tag
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `"xyzzy"` /// * `"xyzzy"`
/// * `W/"xyzzy"` /// * `W/"xyzzy"`
/// * `"xyzzy", "r2d2xxxx", "c3piozzzz"` /// * `"xyzzy", "r2d2xxxx", "c3piozzzz"`
@ -30,7 +28,6 @@ crate::http::header::common_header! {
/// * `*` /// * `*`
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::HttpResponse; /// use actix_web::HttpResponse;
/// use actix_web::http::header::IfNoneMatch; /// use actix_web::http::header::IfNoneMatch;
@ -54,7 +51,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(IfNoneMatch, IF_NONE_MATCH) => {Any / (EntityTag)+} (IfNoneMatch, IF_NONE_MATCH) => {Any / (EntityTag)+}
test_if_none_match { test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"\"xyzzy\""]); crate::http::header::common_header_test!(test1, vec![b"\"xyzzy\""]);
crate::http::header::common_header_test!(test2, vec![b"W/\"xyzzy\""]); crate::http::header::common_header_test!(test2, vec![b"W/\"xyzzy\""]);
crate::http::header::common_header_test!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]); crate::http::header::common_header_test!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);

View File

@ -8,7 +8,8 @@ use crate::error::ParseError;
use crate::http::header; use crate::http::header;
use crate::HttpMessage; use crate::HttpMessage;
/// `If-Range` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-3.2) /// `If-Range` header, defined
/// in [RFC 7233 §3.2](https://datatracker.ietf.org/doc/html/rfc7233#section-3.2)
/// ///
/// If a client has a partial copy of a representation and wishes to have /// If a client has a partial copy of a representation and wishes to have
/// an up-to-date copy of the entire representation, it could use the /// an up-to-date copy of the entire representation, it could use the
@ -24,18 +25,16 @@ use crate::HttpMessage;
/// in Range; otherwise, send me the entire representation. /// in Range; otherwise, send me the entire representation.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// If-Range = entity-tag / HTTP-date /// If-Range = entity-tag / HTTP-date
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
/// ///
/// * `Sat, 29 Oct 1994 19:43:31 GMT` /// * `Sat, 29 Oct 1994 19:43:31 GMT`
/// * `\"xyzzy\"` /// * `\"xyzzy\"`
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::HttpResponse; /// use actix_web::HttpResponse;
/// use actix_web::http::header::{EntityTag, IfRange}; /// use actix_web::http::header::{EntityTag, IfRange};

View File

@ -1,8 +1,8 @@
use super::{HttpDate, IF_UNMODIFIED_SINCE}; use super::{HttpDate, IF_UNMODIFIED_SINCE};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `If-Unmodified-Since` header, defined in /// `If-Unmodified-Since` header, defined
/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-3.4) /// in [RFC 7232 §3.4](https://datatracker.ietf.org/doc/html/rfc7232#section-3.4)
/// ///
/// The `If-Unmodified-Since` header field makes the request method /// The `If-Unmodified-Since` header field makes the request method
/// conditional on the selected representation's last modification date /// conditional on the selected representation's last modification date
@ -11,13 +11,11 @@ crate::http::header::common_header! {
/// the user agent does not have an entity-tag for the representation. /// the user agent does not have an entity-tag for the representation.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// If-Unmodified-Since = HTTP-date /// If-Unmodified-Since = HTTP-date
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `Sat, 29 Oct 1994 19:43:31 GMT` /// * `Sat, 29 Oct 1994 19:43:31 GMT`
/// ///
/// # Example /// # Example
@ -35,7 +33,7 @@ crate::http::header::common_header! {
/// ``` /// ```
(IfUnmodifiedSince, IF_UNMODIFIED_SINCE) => [HttpDate] (IfUnmodifiedSince, IF_UNMODIFIED_SINCE) => [HttpDate]
test_if_unmodified_since { test_parse_and_format {
// Test case from RFC // Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]); crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
} }

View File

@ -1,8 +1,8 @@
use super::{HttpDate, LAST_MODIFIED}; use super::{HttpDate, LAST_MODIFIED};
crate::http::header::common_header! { crate::http::header::common_header! {
/// `Last-Modified` header, defined in /// `Last-Modified` header, defined
/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.2) /// in [RFC 7232 §2.2](https://datatracker.ietf.org/doc/html/rfc7232#section-2.2)
/// ///
/// The `Last-Modified` header field in a response provides a timestamp /// The `Last-Modified` header field in a response provides a timestamp
/// indicating the date and time at which the origin server believes the /// indicating the date and time at which the origin server believes the
@ -10,13 +10,11 @@ crate::http::header::common_header! {
/// conclusion of handling the request. /// conclusion of handling the request.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Expires = HTTP-date /// Expires = HTTP-date
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `Sat, 29 Oct 1994 19:43:31 GMT` /// * `Sat, 29 Oct 1994 19:43:31 GMT`
/// ///
/// # Example /// # Example
@ -34,8 +32,8 @@ crate::http::header::common_header! {
/// ``` /// ```
(LastModified, LAST_MODIFIED) => [HttpDate] (LastModified, LAST_MODIFIED) => [HttpDate]
test_last_modified { test_parse_and_format {
// Test case from RFC // Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]); crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
} }
} }

View File

@ -4,15 +4,14 @@ use std::str::FromStr;
use super::parsing::from_one_raw_str; use super::parsing::from_one_raw_str;
use super::{Header, Raw}; use super::{Header, Raw};
/// `Range` header, defined in [RFC7233](https://tools.ietf.org/html/rfc7233#section-3.1) /// `Range` header, defined
/// in [RFC 7233 §3.1](https://datatracker.ietf.org/doc/html/rfc7233#section-3.1)
/// ///
/// The "Range" header field on a GET request modifies the method /// The "Range" header field on a GET request modifies the method semantics to request transfer of
/// semantics to request transfer of only one or more sub-ranges of the /// only one or more sub-ranges of the selected representation data, rather than the entire selected
/// selected representation data, rather than the entire selected
/// representation data. /// representation data.
/// ///
/// # ABNF /// # ABNF
///
/// ```text /// ```text
/// Range = byte-ranges-specifier / other-ranges-specifier /// Range = byte-ranges-specifier / other-ranges-specifier
/// other-ranges-specifier = other-range-unit "=" other-range-set /// other-ranges-specifier = other-range-unit "=" other-range-set
@ -27,8 +26,7 @@ use super::{Header, Raw};
/// last-byte-pos = 1*DIGIT /// last-byte-pos = 1*DIGIT
/// ``` /// ```
/// ///
/// # Example values /// # Example Values
///
/// * `bytes=1000-` /// * `bytes=1000-`
/// * `bytes=-2000` /// * `bytes=-2000`
/// * `bytes=0-1,30-40` /// * `bytes=0-1,30-40`
@ -37,7 +35,6 @@ use super::{Header, Raw};
/// * `custom_unit=xxx-yyy` /// * `custom_unit=xxx-yyy`
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use hyper::header::{Headers, Range, ByteRangeSpec}; /// use hyper::header::{Headers, Range, ByteRangeSpec};
/// ///
@ -63,6 +60,7 @@ use super::{Header, Raw};
pub enum Range { pub enum Range {
/// Byte range /// Byte range
Bytes(Vec<ByteRangeSpec>), Bytes(Vec<ByteRangeSpec>),
/// Custom range, with unit not registered at IANA /// Custom range, with unit not registered at IANA
/// (`other-range-unit`: String , `other-range-set`: String) /// (`other-range-unit`: String , `other-range-set`: String)
Unregistered(String, String), Unregistered(String, String),
@ -74,8 +72,10 @@ pub enum Range {
pub enum ByteRangeSpec { pub enum ByteRangeSpec {
/// Get all bytes between x and y ("x-y") /// Get all bytes between x and y ("x-y")
FromTo(u64, u64), FromTo(u64, u64),
/// Get all bytes starting from x ("x-") /// Get all bytes starting from x ("x-")
AllFrom(u64), AllFrom(u64),
/// Get last x bytes ("-x") /// Get last x bytes ("-x")
Last(u64), Last(u64),
} }
@ -238,9 +238,7 @@ impl FromStr for ByteRangeSpec {
.or(Err(::Error::Header)) .or(Err(::Error::Header))
.map(ByteRangeSpec::AllFrom), .map(ByteRangeSpec::AllFrom),
(Some(start), Some(end)) => match (start.parse(), end.parse()) { (Some(start), Some(end)) => match (start.parse(), end.parse()) {
(Ok(start), Ok(end)) if start <= end => { (Ok(start), Ok(end)) if start <= end => Ok(ByteRangeSpec::FromTo(start, end)),
Ok(ByteRangeSpec::FromTo(start, end))
}
_ => Err(::Error::Header), _ => Err(::Error::Header),
}, },
_ => Err(::Error::Header), _ => Err(::Error::Header),
@ -248,16 +246,6 @@ impl FromStr for ByteRangeSpec {
} }
} }
fn from_comma_delimited<T: FromStr>(s: &str) -> Vec<T> {
s.split(',')
.filter_map(|x| match x.trim() {
"" => None,
y => Some(y),
})
.filter_map(|x| x.parse().ok())
.collect()
}
impl Header for Range { impl Header for Range {
fn header_name() -> &'static str { fn header_name() -> &'static str {
static NAME: &'static str = "Range"; static NAME: &'static str = "Range";
@ -286,8 +274,7 @@ mod tests {
assert_eq!(r2, r3); assert_eq!(r2, r3);
let r: Range = Header::parse_header(&"bytes=1-100,200-".into()).unwrap(); let r: Range = Header::parse_header(&"bytes=1-100,200-".into()).unwrap();
let r2: Range = let r2: Range = Header::parse_header(&"bytes= 1-100 , 101-xxx, 200- ".into()).unwrap();
Header::parse_header(&"bytes= 1-100 , 101-xxx, 200- ".into()).unwrap();
let r3 = Range::Bytes(vec![ let r3 = Range::Bytes(vec![
ByteRangeSpec::FromTo(1, 100), ByteRangeSpec::FromTo(1, 100),
ByteRangeSpec::AllFrom(200), ByteRangeSpec::AllFrom(200),

View File

@ -561,7 +561,6 @@ where
/// The max number of services can be grouped together is 12. /// The max number of services can be grouped together is 12.
/// ///
/// # Examples /// # Examples
///
/// ``` /// ```
/// use actix_web::{services, web, App}; /// use actix_web::{services, web, App};
/// ///