Skip to content

Commit c75c46d

Browse files
committed
add referer typed header
1 parent cfee42f commit c75c46d

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

actix-web/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Add `http::header::ContentLocation` typed header.
66
- Add `http::header::Location` typed header.
7+
- Add `http::header::Referer` typed header.
78

89
## 4.9.0
910

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

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod location;
4444
mod macros;
4545
mod preference;
4646
mod range;
47+
mod referer;
4748

4849
#[cfg(test)]
4950
pub(crate) use self::macros::common_header_test;
@@ -75,6 +76,7 @@ pub use self::{
7576
location::Location,
7677
preference::Preference,
7778
range::{ByteRangeSpec, Range},
79+
referer::Referer,
7880
};
7981

8082
/// Format writer ([`fmt::Write`]) for a [`BytesMut`].

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

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use super::{Uri, REFERER};
2+
3+
crate::http::header::common_header! {
4+
/// `Referer` header, defined
5+
/// in [RFC 7231 §5.5.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.5.2)
6+
///
7+
/// The "Referer" [sic] header field allows the user agent to specify a
8+
/// URI reference for the resource from which the target URI was obtained
9+
/// (i.e., the "referrer", though the field name is misspelled).
10+
///
11+
/// # ABNF
12+
/// ```plain
13+
/// Referer = absolute-URI / partial-URI
14+
/// ```
15+
///
16+
/// # Example Values
17+
/// * `http://www.example.org/hypertext/Overview.html`
18+
///
19+
/// # Examples
20+
///
21+
/// ```
22+
/// use actix_web::HttpResponse;
23+
/// use actix_http::Uri;
24+
/// use actix_web::http::header::Referer;
25+
///
26+
/// let mut builder = HttpResponse::Ok();
27+
/// builder.insert_header(
28+
/// Referer("http://www.example.org".parse::<Uri>().unwrap())
29+
/// );
30+
/// ```
31+
(Referer, REFERER) => [Uri]
32+
33+
test_parse_and_format {
34+
crate::http::header::common_header_test!(test1, [b"http://www.example.org/hypertext/Overview.html"]);
35+
}
36+
}

0 commit comments

Comments
 (0)