From f5d340878c5007e6cb341533bc3db6e69e7b33ad Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Sat, 17 Aug 2024 23:12:05 +0100 Subject: [PATCH] add location typed header --- actix-web/CHANGES.md | 1 + actix-web/src/http/header/location.rs | 37 +++++++++++++++++++++++++++ actix-web/src/http/header/mod.rs | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 actix-web/src/http/header/location.rs diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 1bed4297..a79f6a9c 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -4,6 +4,7 @@ - Minimum supported Rust version (MSRV) is now 1.75. - Add `http::header::ContentLocation` typed header. +- Add `http::header::Location` typed header. ## 4.9.0 diff --git a/actix-web/src/http/header/location.rs b/actix-web/src/http/header/location.rs new file mode 100644 index 00000000..97c7ea78 --- /dev/null +++ b/actix-web/src/http/header/location.rs @@ -0,0 +1,37 @@ +use super::{Uri, LOCATION}; + +crate::http::header::common_header! { + /// `Location` header, defined + /// in [RFC 7231 ยง7.1.2](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2) + /// + /// The "Location" header field is used in some responses to refer to a + /// specific resource in relation to the response. The type of + /// relationship is defined by the combination of request method and + /// status code semantics. + /// + /// # ABNF + /// ```plain + /// Location = URI-reference + /// ``` + /// + /// # Example Values + /// * `http://www.example.org/hypertext/Overview.html` + /// + /// # Examples + /// + /// ``` + /// use actix_web::HttpResponse; + /// use actix_http::Uri; + /// use actix_web::http::header::Location; + /// + /// let mut builder = HttpResponse::Ok(); + /// builder.insert_header( + /// Location("http://www.example.org".parse::().unwrap()) + /// ); + /// ``` + (Location, 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 756880ac..44e47e82 100644 --- a/actix-web/src/http/header/mod.rs +++ b/actix-web/src/http/header/mod.rs @@ -40,6 +40,7 @@ mod if_none_match; mod if_range; mod if_unmodified_since; mod last_modified; +mod location; mod macros; mod preference; mod range; @@ -71,6 +72,7 @@ pub use self::{ if_range::IfRange, if_unmodified_since::IfUnmodifiedSince, last_modified::LastModified, + location::Location, preference::Preference, range::{ByteRangeSpec, Range}, };