Skip to content

Commit cfee42f

Browse files
committed
add location typed header
1 parent 9192e0b commit cfee42f

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

actix-web/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Add `http::header::ContentLocation` typed header.
6+
- Add `http::header::Location` typed header.
67

78
## 4.9.0
89

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use super::{Uri, LOCATION};
2+
3+
crate::http::header::common_header! {
4+
/// `Location` header, defined
5+
/// in [RFC 7231 §7.1.2](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2)
6+
///
7+
/// The "Location" header field is used in some responses to refer to a
8+
/// specific resource in relation to the response. The type of
9+
/// relationship is defined by the combination of request method and
10+
/// status code semantics.
11+
///
12+
/// # ABNF
13+
/// ```plain
14+
/// Location = URI-reference
15+
/// ```
16+
///
17+
/// # Example Values
18+
/// * `http://www.example.org/hypertext/Overview.html`
19+
///
20+
/// # Examples
21+
///
22+
/// ```
23+
/// use actix_web::HttpResponse;
24+
/// use actix_http::Uri;
25+
/// use actix_web::http::header::Location;
26+
///
27+
/// let mut builder = HttpResponse::Ok();
28+
/// builder.insert_header(
29+
/// Location("http://www.example.org".parse::<Uri>().unwrap())
30+
/// );
31+
/// ```
32+
(Location, LOCATION) => [Uri]
33+
34+
test_parse_and_format {
35+
crate::http::header::common_header_test!(test1, [b"http://www.example.org/hypertext/Overview.html"]);
36+
}
37+
}

actix-web/src/http/header/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod if_none_match;
4040
mod if_range;
4141
mod if_unmodified_since;
4242
mod last_modified;
43+
mod location;
4344
mod macros;
4445
mod preference;
4546
mod range;
@@ -71,6 +72,7 @@ pub use self::{
7172
if_range::IfRange,
7273
if_unmodified_since::IfUnmodifiedSince,
7374
last_modified::LastModified,
75+
location::Location,
7476
preference::Preference,
7577
range::{ByteRangeSpec, Range},
7678
};

0 commit comments

Comments
 (0)