Skip to content

Commit

Permalink
add referer typed header
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Aug 17, 2024
1 parent cfee42f commit c75c46d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add `http::header::ContentLocation` typed header.
- Add `http::header::Location` typed header.
- Add `http::header::Referer` typed header.

## 4.9.0

Expand Down
2 changes: 2 additions & 0 deletions actix-web/src/http/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod location;
mod macros;
mod preference;
mod range;
mod referer;

#[cfg(test)]
pub(crate) use self::macros::common_header_test;
Expand Down Expand Up @@ -75,6 +76,7 @@ pub use self::{
location::Location,
preference::Preference,
range::{ByteRangeSpec, Range},
referer::Referer,
};

/// Format writer ([`fmt::Write`]) for a [`BytesMut`].
Expand Down
36 changes: 36 additions & 0 deletions actix-web/src/http/header/referer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::{Uri, REFERER};

crate::http::header::common_header! {
/// `Referer` header, defined

Check failure on line 4 in actix-web/src/http/header/referer.rs

View workflow job for this annotation

GitHub Actions / lint-docs

unresolved link to `sic`

Check failure on line 4 in actix-web/src/http/header/referer.rs

View workflow job for this annotation

GitHub Actions / doc tests

unresolved link to `sic`
/// in [RFC 7231 §5.5.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.5.2)
///
/// The "Referer" [sic] header field allows the user agent to specify a
/// URI reference for the resource from which the target URI was obtained
/// (i.e., the "referrer", though the field name is misspelled).
///
/// # ABNF
/// ```plain
/// Referer = 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::Referer;
///
/// let mut builder = HttpResponse::Ok();
/// builder.insert_header(
/// Referer("http://www.example.org".parse::<Uri>().unwrap())
/// );
/// ```
(Referer, REFERER) => [Uri]

test_parse_and_format {
crate::http::header::common_header_test!(test1, [b"http://www.example.org/hypertext/Overview.html"]);
}
}

0 comments on commit c75c46d

Please sign in to comment.