mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 03:21:08 +00:00
update all IETF RFC links to new URL format
This commit is contained in:
parent
697238fadc
commit
0df275c478
27 changed files with 163 additions and 184 deletions
|
@ -1,9 +1,8 @@
|
|||
use std::fmt::{self, Display};
|
||||
use std::str::FromStr;
|
||||
use std::{fmt, str};
|
||||
|
||||
use self::Charset::*;
|
||||
|
||||
/// A Mime charset.
|
||||
/// A MIME character set.
|
||||
///
|
||||
/// 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 {
|
||||
f.write_str(self.label())
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Charset {
|
||||
impl str::FromStr for Charset {
|
||||
type Err = crate::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Charset, crate::Error> {
|
||||
|
|
|
@ -24,8 +24,8 @@ pub struct ExtendedValue {
|
|||
pub value: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Parses extended header parameter values (`ext-value`), as defined in
|
||||
/// [RFC 5987](https://tools.ietf.org/html/rfc5987#section-3.2).
|
||||
/// Parses extended header parameter values (`ext-value`), as defined
|
||||
/// 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 `*`.
|
||||
///
|
||||
|
@ -34,7 +34,7 @@ pub struct ExtendedValue {
|
|||
/// ```text
|
||||
/// ext-value = charset "'" [ language ] "'" value-chars
|
||||
/// ; like RFC 2231's <extended-initial-value>
|
||||
/// ; (see [RFC2231], Section 7)
|
||||
/// ; (see [RFC 2231 §7])
|
||||
///
|
||||
/// 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
|
||||
/// ; 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 )
|
||||
///
|
||||
/// pct-encoded = "%" HEXDIG HEXDIG
|
||||
/// ; see [RFC3986], Section 2.1
|
||||
/// ; see [RFC 3986 §2.1]
|
||||
///
|
||||
/// attr-char = ALPHA / DIGIT
|
||||
/// / "!" / "#" / "$" / "&" / "+" / "-" / "."
|
||||
/// / "^" / "_" / "`" / "|" / "~"
|
||||
/// ; 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(
|
||||
val: &str,
|
||||
) -> Result<ExtendedValue, crate::error::ParseError> {
|
||||
|
|
|
@ -224,7 +224,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromStr for Encoding {
|
||||
impl str::FromStr for Encoding {
|
||||
type Err = crate::error::ParseError;
|
||||
fn from_str(s: &str) -> Result<Encoding, crate::error::ParseError> {
|
||||
use Encoding::*;
|
||||
|
|
|
@ -13,8 +13,10 @@ where
|
|||
T: FromStr,
|
||||
{
|
||||
let mut result = Vec::new();
|
||||
|
||||
for h in all {
|
||||
let s = h.to_str().map_err(|_| ParseError::Header)?;
|
||||
|
||||
result.extend(
|
||||
s.split(',')
|
||||
.filter_map(|x| match x.trim() {
|
||||
|
|
|
@ -3,7 +3,9 @@ use std::{
|
|||
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)]
|
||||
pub enum OpCode {
|
||||
/// Indicates a continuation frame of a fragmented message.
|
||||
|
@ -105,7 +107,7 @@ pub enum CloseCode {
|
|||
Abnormal,
|
||||
|
||||
/// 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).
|
||||
Invalid,
|
||||
|
||||
|
|
|
@ -312,9 +312,8 @@ impl WebsocketsRequest {
|
|||
);
|
||||
}
|
||||
|
||||
// Generate a random key for the `Sec-WebSocket-Key` header.
|
||||
// a base64-encoded (see Section 4 of [RFC4648]) value that,
|
||||
// when decoded, is 16 bytes in length (RFC 6455)
|
||||
// Generate a random key for the `Sec-WebSocket-Key` header which is a base64-encoded
|
||||
// (see RFC 4648 §4) value that, when decoded, is 16 bytes in length (RFC 6455 §1.3).
|
||||
let sec_key: [u8; 16] = rand::random();
|
||||
let key = base64::encode(&sec_key);
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ use super::{qitem, QualityItem};
|
|||
use crate::http::header;
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `Accept` header, defined in [RFC7231](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
|
||||
/// response media types that are acceptable. Accept header fields can
|
||||
|
@ -15,7 +16,6 @@ crate::http::header::common_header! {
|
|||
/// in-line image
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Accept = #( media-range [ accept-params ] )
|
||||
///
|
||||
|
@ -27,7 +27,7 @@ crate::http::header::common_header! {
|
|||
/// accept-ext = OWS ";" OWS token [ "=" ( token / quoted-string ) ]
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
/// * `audio/*; q=0.2, audio/basic`
|
||||
/// * `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>)+
|
||||
|
||||
test_accept {
|
||||
test_parse_and_format {
|
||||
// Tests from the RFC
|
||||
crate::http::header::common_header_test!(
|
||||
test1,
|
||||
|
|
|
@ -2,7 +2,7 @@ use super::{Charset, QualityItem, ACCEPT_CHARSET};
|
|||
|
||||
crate::http::header::common_header! {
|
||||
/// `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
|
||||
/// indicate what charsets are acceptable in textual response content.
|
||||
|
@ -12,12 +12,11 @@ crate::http::header::common_header! {
|
|||
/// those charsets.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Accept-Charset = 1#( ( charset / "*" ) [ weight ] )
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
/// * `iso-8859-5, unicode-1-1;q=0.8`
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -55,7 +54,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
||||
|
||||
test_accept_charset {
|
||||
test_parse_and_format {
|
||||
// Test case from RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use header::{Encoding, QualityItem};
|
||||
|
||||
header! {
|
||||
/// `Accept-Encoding` header, defined in
|
||||
/// [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.4)
|
||||
/// `Accept-Encoding` header, defined
|
||||
/// 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
|
||||
/// indicate what response content-codings are
|
||||
|
@ -11,13 +11,12 @@ header! {
|
|||
/// preferred.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Accept-Encoding = #( codings [ weight ] )
|
||||
/// codings = content-coding / "identity" / "*"
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
/// * `compress, gzip`
|
||||
/// * ``
|
||||
/// * `*`
|
||||
|
@ -62,7 +61,7 @@ header! {
|
|||
/// ```
|
||||
(AcceptEncoding, "Accept-Encoding") => (QualityItem<Encoding>)*
|
||||
|
||||
test_accept_encoding {
|
||||
test_parse_and_format {
|
||||
// From the RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"compress, gzip"]);
|
||||
crate::http::header::common_header_test!(test2, vec![b""], Some(AcceptEncoding(vec![])));
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
use crate::http::header;
|
||||
use actix_http::http::Method;
|
||||
|
||||
use crate::http::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
|
||||
/// 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
|
||||
/// with the resource.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Allow = #method
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
/// * `GET, HEAD, PUT`
|
||||
/// * `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr`
|
||||
/// * ``
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::{header::Allow, Method};
|
||||
|
@ -47,7 +47,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(Allow, header::ALLOW) => (Method)*
|
||||
|
||||
test_allow {
|
||||
test_parse_and_format {
|
||||
// From the RFC
|
||||
crate::http::header::common_header_test!(
|
||||
test1,
|
||||
|
|
|
@ -5,7 +5,8 @@ use super::{fmt_comma_delimited, from_comma_delimited, Header, IntoHeaderValue,
|
|||
|
||||
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
|
||||
/// 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.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Cache-Control = 1#cache-directive
|
||||
/// cache-directive = token [ "=" ( token / quoted-string ) ]
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
///
|
||||
/// * `no-cache`
|
||||
/// * `private, community="UCI"`
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
//! # References
|
||||
//! The `Content-Disposition` header and associated types.
|
||||
//!
|
||||
//! "The Content-Disposition Header Field" <https://www.ietf.org/rfc/rfc2183.txt>
|
||||
//! "The Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)" <https://www.ietf.org/rfc/rfc6266.txt>
|
||||
//! "Returning Values from Forms: multipart/form-data" <https://www.ietf.org/rfc/rfc7578.txt>
|
||||
//! Browser conformance tests at: <http://greenbytes.de/tech/tc2231/>
|
||||
//! IANA assignment: <http://www.iana.org/assignments/cont-disp/cont-disp.xhtml>
|
||||
//! # References
|
||||
//! - "The Content-Disposition Header Field":
|
||||
//! <https://datatracker.ietf.org/doc/html/rfc2183>
|
||||
//! - "The Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)":
|
||||
//! <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 regex::Regex;
|
||||
|
@ -41,8 +45,9 @@ pub enum DispositionType {
|
|||
/// rather than process it normally (as per its media type).
|
||||
Attachment,
|
||||
|
||||
/// Used in *multipart/form-data* as defined in [RFC7578](https://tools.ietf.org/html/rfc7578)
|
||||
/// to carry the field name and optional filename.
|
||||
/// Used in *multipart/form-data* as defined in
|
||||
/// [RFC 7578](https://datatracker.ietf.org/doc/html/rfc7578) to carry the field name and
|
||||
/// optional filename.
|
||||
FormData,
|
||||
|
||||
/// Extension type. Should be handled by recipients the same way as Attachment.
|
||||
|
@ -82,26 +87,29 @@ pub enum DispositionParam {
|
|||
|
||||
/// A plain file name.
|
||||
///
|
||||
/// It is [not supposed](https://tools.ietf.org/html/rfc6266#appendix-D) to contain any
|
||||
/// non-ASCII characters when used in a *Content-Disposition* HTTP response header, where
|
||||
/// It 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
|
||||
/// [`FilenameExt`](DispositionParam::FilenameExt) with charset UTF-8 may be used instead
|
||||
/// in case there are Unicode characters in file names.
|
||||
Filename(String),
|
||||
|
||||
/// 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),
|
||||
|
||||
/// An unrecognized regular parameter as defined in
|
||||
/// [RFC5987](https://tools.ietf.org/html/rfc5987) as *reg-parameter*, in
|
||||
/// [RFC6266](https://tools.ietf.org/html/rfc6266) as *token "=" value*. Recipients should
|
||||
/// ignore unrecognizable parameters.
|
||||
/// [RFC 5987 §3.2.1](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1) as
|
||||
/// `reg-parameter`, in
|
||||
/// [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),
|
||||
|
||||
/// An unrecognized extended parameter as defined in
|
||||
/// [RFC5987](https://tools.ietf.org/html/rfc5987) as *ext-parameter*, in
|
||||
/// [RFC6266](https://tools.ietf.org/html/rfc6266) as *ext-token "=" ext-value*. The single
|
||||
/// trailing asterisk is not included. Recipients should ignore unrecognizable parameters.
|
||||
/// [RFC 5987 §3.2.1](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1) as
|
||||
/// `ext-parameter`, in
|
||||
/// [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),
|
||||
}
|
||||
|
||||
|
@ -195,10 +203,10 @@ impl DispositionParam {
|
|||
}
|
||||
|
||||
/// 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)
|
||||
/// as (re)defined in [RFC6266](https://tools.ietf.org/html/rfc6266), or as
|
||||
/// [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 [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)
|
||||
/// 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
|
||||
/// 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
|
||||
/// *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
|
||||
/// 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
|
||||
/// *filename* [must not](https://datatracker.ietf.org/doc/html/rfc7578#section-4.2) be used within
|
||||
/// *multipart/form-data*.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use actix_web::http::header::{
|
||||
/// Charset, ContentDisposition, DispositionParam, DispositionType,
|
||||
|
@ -291,10 +297,9 @@ impl DispositionParam {
|
|||
/// ```
|
||||
///
|
||||
/// # Security Note
|
||||
///
|
||||
/// 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
|
||||
/// 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
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ContentDisposition {
|
||||
|
@ -342,7 +347,7 @@ impl ContentDisposition {
|
|||
} else {
|
||||
// regular parameters
|
||||
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 quoted_string = vec![];
|
||||
let mut end = None;
|
||||
|
@ -393,22 +398,22 @@ impl ContentDisposition {
|
|||
Ok(cd)
|
||||
}
|
||||
|
||||
/// Returns `true` if it is [`Inline`](DispositionType::Inline).
|
||||
/// Returns `true` if type is [`Inline`](DispositionType::Inline).
|
||||
pub fn is_inline(&self) -> bool {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
matches!(
|
||||
self.disposition,
|
||||
|
@ -487,7 +492,9 @@ impl fmt::Display for DispositionParam {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// All ASCII control characters (0-30, 127) including horizontal tab, double quote, and
|
||||
// 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
|
||||
// value = token | quoted-string
|
||||
// quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
|
||||
|
@ -501,7 +508,7 @@ impl fmt::Display for DispositionParam {
|
|||
// CTL = <any US-ASCII control character
|
||||
// (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
|
||||
// attribute := token
|
||||
// ; Matching of attributes
|
||||
|
@ -746,7 +753,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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
|
||||
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.
|
||||
|
@ -819,9 +826,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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.
|
||||
// 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.
|
||||
// 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
|
||||
|
|
|
@ -2,8 +2,8 @@ use super::{QualityItem, CONTENT_LANGUAGE};
|
|||
use language_tags::LanguageTag;
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `Content-Language` header, defined in
|
||||
/// [RFC7231](https://tools.ietf.org/html/rfc7231#section-3.1.3.2)
|
||||
/// `Content-Language` header, defined
|
||||
/// 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)
|
||||
/// of the intended audience for the representation. Note that this
|
||||
|
@ -11,18 +11,15 @@ crate::http::header::common_header! {
|
|||
/// representation.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Content-Language = 1#language-tag
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `da`
|
||||
/// * `mi, en`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::header::{ContentLanguage, LanguageTag, qitem};
|
||||
|
@ -49,7 +46,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(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!(test2, vec![b"mi, en"]);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
use std::fmt::{self, Display, Write};
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
fmt::{self, Display, Write},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer, CONTENT_RANGE};
|
||||
use crate::error::ParseError;
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `Content-Range` header, defined in
|
||||
/// [RFC7233](http://tools.ietf.org/html/rfc7233#section-4.2)
|
||||
/// `Content-Range` header, defined
|
||||
/// in [RFC 7233 §4.2](https://datatracker.ietf.org/doc/html/rfc7233#section-4.2)
|
||||
(ContentRange, CONTENT_RANGE) => [ContentRangeSpec]
|
||||
|
||||
test_content_range {
|
||||
test_parse_and_format {
|
||||
crate::http::header::common_header_test!(test_bytes,
|
||||
vec![b"bytes 0-499/500"],
|
||||
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
|
||||
///
|
||||
/// ```text
|
||||
/// Content-Range = byte-content-range
|
||||
/// / other-content-range
|
||||
|
|
|
@ -2,8 +2,8 @@ use super::CONTENT_TYPE;
|
|||
use mime::Mime;
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `Content-Type` header, defined in
|
||||
/// [RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.1.5)
|
||||
/// `Content-Type` header, defined
|
||||
/// 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
|
||||
/// 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.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Content-Type = media-type
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `text/html; charset=utf-8`
|
||||
/// * `application/json`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::header::ContentType;
|
||||
|
@ -51,7 +48,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(ContentType, CONTENT_TYPE) => [Mime]
|
||||
|
||||
test_content_type {
|
||||
test_parse_and_format {
|
||||
crate::http::header::common_header_test!(
|
||||
test1,
|
||||
vec![b"text/html"],
|
||||
|
|
|
@ -2,19 +2,18 @@ use super::{HttpDate, DATE};
|
|||
use std::time::SystemTime;
|
||||
|
||||
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
|
||||
/// message was originated.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Date = HTTP-date
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `Tue, 15 Nov 1994 08:12:31 GMT`
|
||||
///
|
||||
/// # Example
|
||||
|
@ -31,7 +30,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(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"]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::fmt::{self, Display, Write};
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
fmt::{self, Display, Write},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer};
|
||||
|
||||
|
@ -15,7 +17,8 @@ fn check_slice_validity(slice: &str) -> bool {
|
|||
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.
|
||||
/// Preceding the first double quote is an optional weakness indicator,
|
||||
|
@ -23,7 +26,6 @@ fn check_slice_validity(slice: &str) -> bool {
|
|||
/// `W/"xyzzy"`.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// entity-tag = [ weak ] opaque-tag
|
||||
/// weak = %x57.2F ; "W/", case-sensitive
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use super::{EntityTag, ETAG};
|
||||
|
||||
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
|
||||
/// for the selected representation, as determined at the conclusion of
|
||||
|
@ -14,19 +15,16 @@ crate::http::header::common_header! {
|
|||
/// prefixed by a weakness indicator.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// ETag = entity-tag
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `"xyzzy"`
|
||||
/// * `W/"xyzzy"`
|
||||
/// * `""`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::header::{ETag, EntityTag};
|
||||
|
@ -48,7 +46,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(ETag, ETAG) => [EntityTag]
|
||||
|
||||
test_etag {
|
||||
test_parse_and_format {
|
||||
// From the RFC
|
||||
crate::http::header::common_header_test!(test1,
|
||||
vec![b"\"xyzzy\""],
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use super::{HttpDate, EXPIRES};
|
||||
|
||||
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
|
||||
/// response is considered stale.
|
||||
|
@ -11,12 +12,11 @@ crate::http::header::common_header! {
|
|||
/// time.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Expires = HTTP-date
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
/// * `Thu, 01 Dec 1994 16:00:00 GMT`
|
||||
///
|
||||
/// # Example
|
||||
|
@ -34,7 +34,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(Expires, EXPIRES) => [HttpDate]
|
||||
|
||||
test_expires {
|
||||
test_parse_and_format {
|
||||
// Test case from RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"Thu, 01 Dec 1994 16:00:00 GMT"]);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{EntityTag, IF_MATCH};
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `If-Match` header, defined in
|
||||
/// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.1)
|
||||
/// `If-Match` header, defined
|
||||
/// 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 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.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// If-Match = "*" / 1#entity-tag
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `"xyzzy"`
|
||||
/// * "xyzzy", "r2d2xxxx", "c3piozzzz"
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::header::IfMatch;
|
||||
|
@ -52,7 +49,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(IfMatch, IF_MATCH) => {Any / (EntityTag)+}
|
||||
|
||||
test_if_match {
|
||||
test_parse_and_format {
|
||||
crate::http::header::common_header_test!(
|
||||
test1,
|
||||
vec![b"\"xyzzy\""],
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{HttpDate, IF_MODIFIED_SINCE};
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `If-Modified-Since` header, defined in
|
||||
/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-3.3)
|
||||
/// `If-Modified-Since` header, defined
|
||||
/// 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
|
||||
/// method conditional on the selected representation's modification date
|
||||
|
@ -11,12 +11,11 @@ crate::http::header::common_header! {
|
|||
/// data has not changed.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// If-Unmodified-Since = HTTP-date
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
/// * `Sat, 29 Oct 1994 19:43:31 GMT`
|
||||
///
|
||||
/// # Example
|
||||
|
@ -34,7 +33,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate]
|
||||
|
||||
test_if_modified_since {
|
||||
test_parse_and_format {
|
||||
// Test case from RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{EntityTag, IF_NONE_MATCH};
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `If-None-Match` header, defined in
|
||||
/// [RFC7232](https://tools.ietf.org/html/rfc7232#section-3.2)
|
||||
/// `If-None-Match` header, defined
|
||||
/// 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
|
||||
/// on a recipient cache or origin server either not having any current
|
||||
|
@ -16,13 +16,11 @@ crate::http::header::common_header! {
|
|||
/// the representation data.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// If-None-Match = "*" / 1#entity-tag
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `"xyzzy"`
|
||||
/// * `W/"xyzzy"`
|
||||
/// * `"xyzzy", "r2d2xxxx", "c3piozzzz"`
|
||||
|
@ -30,7 +28,6 @@ crate::http::header::common_header! {
|
|||
/// * `*`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::header::IfNoneMatch;
|
||||
|
@ -54,7 +51,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(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!(test2, vec![b"W/\"xyzzy\""]);
|
||||
crate::http::header::common_header_test!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);
|
||||
|
|
|
@ -8,7 +8,8 @@ use crate::error::ParseError;
|
|||
use crate::http::header;
|
||||
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
|
||||
/// 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.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// If-Range = entity-tag / HTTP-date
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
/// # Example Values
|
||||
///
|
||||
/// * `Sat, 29 Oct 1994 19:43:31 GMT`
|
||||
/// * `\"xyzzy\"`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::HttpResponse;
|
||||
/// use actix_web::http::header::{EntityTag, IfRange};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{HttpDate, IF_UNMODIFIED_SINCE};
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `If-Unmodified-Since` header, defined in
|
||||
/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-3.4)
|
||||
/// `If-Unmodified-Since` header, defined
|
||||
/// 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
|
||||
/// 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.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// If-Unmodified-Since = HTTP-date
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `Sat, 29 Oct 1994 19:43:31 GMT`
|
||||
///
|
||||
/// # Example
|
||||
|
@ -35,7 +33,7 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(IfUnmodifiedSince, IF_UNMODIFIED_SINCE) => [HttpDate]
|
||||
|
||||
test_if_unmodified_since {
|
||||
test_parse_and_format {
|
||||
// Test case from RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{HttpDate, LAST_MODIFIED};
|
||||
|
||||
crate::http::header::common_header! {
|
||||
/// `Last-Modified` header, defined in
|
||||
/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.2)
|
||||
/// `Last-Modified` header, defined
|
||||
/// 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
|
||||
/// 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.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Expires = HTTP-date
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `Sat, 29 Oct 1994 19:43:31 GMT`
|
||||
///
|
||||
/// # Example
|
||||
|
@ -34,8 +32,8 @@ crate::http::header::common_header! {
|
|||
/// ```
|
||||
(LastModified, LAST_MODIFIED) => [HttpDate]
|
||||
|
||||
test_last_modified {
|
||||
// Test case from RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
|
||||
}
|
||||
test_parse_and_format {
|
||||
// Test case from RFC
|
||||
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,14 @@ use std::str::FromStr;
|
|||
use super::parsing::from_one_raw_str;
|
||||
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
|
||||
/// semantics to request transfer of only one or more sub-ranges of the
|
||||
/// selected representation data, rather than the entire selected
|
||||
/// The "Range" header field on a GET request modifies the method semantics to request transfer of
|
||||
/// only one or more sub-ranges of the selected representation data, rather than the entire selected
|
||||
/// representation data.
|
||||
///
|
||||
/// # ABNF
|
||||
///
|
||||
/// ```text
|
||||
/// Range = byte-ranges-specifier / other-ranges-specifier
|
||||
/// other-ranges-specifier = other-range-unit "=" other-range-set
|
||||
|
@ -27,8 +26,7 @@ use super::{Header, Raw};
|
|||
/// last-byte-pos = 1*DIGIT
|
||||
/// ```
|
||||
///
|
||||
/// # Example values
|
||||
///
|
||||
/// # Example Values
|
||||
/// * `bytes=1000-`
|
||||
/// * `bytes=-2000`
|
||||
/// * `bytes=0-1,30-40`
|
||||
|
@ -37,7 +35,6 @@ use super::{Header, Raw};
|
|||
/// * `custom_unit=xxx-yyy`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hyper::header::{Headers, Range, ByteRangeSpec};
|
||||
///
|
||||
|
@ -63,6 +60,7 @@ use super::{Header, Raw};
|
|||
pub enum Range {
|
||||
/// Byte range
|
||||
Bytes(Vec<ByteRangeSpec>),
|
||||
|
||||
/// Custom range, with unit not registered at IANA
|
||||
/// (`other-range-unit`: String , `other-range-set`: String)
|
||||
Unregistered(String, String),
|
||||
|
@ -74,8 +72,10 @@ pub enum Range {
|
|||
pub enum ByteRangeSpec {
|
||||
/// Get all bytes between x and y ("x-y")
|
||||
FromTo(u64, u64),
|
||||
|
||||
/// Get all bytes starting from x ("x-")
|
||||
AllFrom(u64),
|
||||
|
||||
/// Get last x bytes ("-x")
|
||||
Last(u64),
|
||||
}
|
||||
|
@ -238,9 +238,7 @@ impl FromStr for ByteRangeSpec {
|
|||
.or(Err(::Error::Header))
|
||||
.map(ByteRangeSpec::AllFrom),
|
||||
(Some(start), Some(end)) => match (start.parse(), end.parse()) {
|
||||
(Ok(start), Ok(end)) if start <= end => {
|
||||
Ok(ByteRangeSpec::FromTo(start, end))
|
||||
}
|
||||
(Ok(start), Ok(end)) if start <= end => Ok(ByteRangeSpec::FromTo(start, end)),
|
||||
_ => 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 {
|
||||
fn header_name() -> &'static str {
|
||||
static NAME: &'static str = "Range";
|
||||
|
@ -286,8 +274,7 @@ mod tests {
|
|||
assert_eq!(r2, r3);
|
||||
|
||||
let r: Range = Header::parse_header(&"bytes=1-100,200-".into()).unwrap();
|
||||
let r2: Range =
|
||||
Header::parse_header(&"bytes= 1-100 , 101-xxx, 200- ".into()).unwrap();
|
||||
let r2: Range = Header::parse_header(&"bytes= 1-100 , 101-xxx, 200- ".into()).unwrap();
|
||||
let r3 = Range::Bytes(vec![
|
||||
ByteRangeSpec::FromTo(1, 100),
|
||||
ByteRangeSpec::AllFrom(200),
|
||||
|
|
|
@ -561,7 +561,6 @@ where
|
|||
/// The max number of services can be grouped together is 12.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::{services, web, App};
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue