diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 36e8b62dd..1bed42976 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - Minimum supported Rust version (MSRV) is now 1.75. +- Add `http::header::ContentLocation` typed header. ## 4.9.0 diff --git a/actix-web/src/http/header/content_location.rs b/actix-web/src/http/header/content_location.rs new file mode 100644 index 000000000..e36ce3b71 --- /dev/null +++ b/actix-web/src/http/header/content_location.rs @@ -0,0 +1,36 @@ +use super::{Uri, CONTENT_LOCATION}; + +crate::http::header::common_header! { + /// `Content-Location` header, defined + /// in [RFC 7231 ยง3.1.4.2](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.4.2) + /// + /// The "Content-Location" header field references a URI that can be used + /// as an identifier for a specific resource corresponding to the + /// representation in this message's payload. + /// + /// # ABNF + /// ```plain + /// Content-Location = absolute-URI / partial-URI + /// ``` + /// + /// # Example Values + /// * `http://www.example.org/hypertext/Overview.html` + /// + /// # Examples + /// + /// ``` + /// use actix_web::HttpResponse; + /// use actix_http::Uri; + /// use actix_web::http::header::ContentLocation; + /// + /// let mut builder = HttpResponse::Created(); + /// builder.insert_header( + /// ContentLocation("http://www.example.org".parse::().unwrap()) + /// ); + /// ``` + (ContentLocation, CONTENT_LOCATION) => [Uri] + + test_parse_and_format { + crate::http::header::common_header_test!(test1, [b"http://www.example.org/hypertext/Overview.html"]); + } +} diff --git a/actix-web/src/http/header/mod.rs b/actix-web/src/http/header/mod.rs index 51ac4fcfd..756880acc 100644 --- a/actix-web/src/http/header/mod.rs +++ b/actix-web/src/http/header/mod.rs @@ -14,6 +14,7 @@ use std::fmt; // - the few typed headers from actix-http // - header parsing utils pub use actix_http::header::*; +pub use actix_http::Uri; use bytes::{Bytes, BytesMut}; mod accept; @@ -25,6 +26,7 @@ mod cache_control; mod content_disposition; mod content_language; mod content_length; +mod content_location; mod content_range; mod content_type; mod date; @@ -55,6 +57,7 @@ pub use self::{ content_disposition::{ContentDisposition, DispositionParam, DispositionType}, content_language::ContentLanguage, content_length::ContentLength, + content_location::ContentLocation, content_range::{ContentRange, ContentRangeSpec}, content_type::ContentType, date::Date,