Compare commits

...

17 Commits

Author SHA1 Message Date
Keith Cirkel 21dea2809f
Merge 98e0cc4049 into b6ad483699 2025-07-13 23:42:09 -07:00
dependabot[bot] b6ad483699
build(deps): bump tokio from 1.45.1 to 1.46.1 (#3689)
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.45.1 to 1.46.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.45.1...tokio-1.46.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-version: 1.46.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 01:52:41 +00:00
dependabot[bot] c002fd783c
build(deps): bump taiki-e/install-action from 2.54.3 to 2.56.13 (#3693)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.54.3 to 2.56.13.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/install-action/compare/v2.54.3...v2.56.13)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.56.13
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 01:16:19 +00:00
Thomas de Zeeuw 95ad1caa23
Update socket2 to v0.6 (#3688) 2025-07-14 01:13:01 +00:00
dependabot[bot] eb906d077a
build(deps): bump trybuild from 1.0.105 to 1.0.106 (#3692)
Bumps [trybuild](https://github.com/dtolnay/trybuild) from 1.0.105 to 1.0.106.
- [Release notes](https://github.com/dtolnay/trybuild/releases)
- [Commits](https://github.com/dtolnay/trybuild/compare/1.0.105...1.0.106)

---
updated-dependencies:
- dependency-name: trybuild
  dependency-version: 1.0.106
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 01:01:17 +00:00
dependabot[bot] f08fa6b684
build(deps): bump h2 from 0.3.26 to 0.3.27 (#3691)
Bumps [h2](https://github.com/hyperium/h2) from 0.3.26 to 0.3.27.
- [Release notes](https://github.com/hyperium/h2/releases)
- [Changelog](https://github.com/hyperium/h2/blob/v0.3.27/CHANGELOG.md)
- [Commits](https://github.com/hyperium/h2/compare/v0.3.26...v0.3.27)

---
updated-dependencies:
- dependency-name: h2
  dependency-version: 0.3.27
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 00:50:00 +00:00
Rob Ede 98e0cc4049
Merge branch 'master' into add-uri-typed-headers 2025-05-10 21:17:56 +01:00
Rob Ede cfaa5b24c7
Merge branch 'master' into add-uri-typed-headers 2024-10-01 05:19:11 +01:00
Keith Cirkel 66873d16b5
Merge branch 'master' into add-uri-typed-headers 2024-09-17 09:55:44 +01:00
Keith Cirkel 4f8819d277
use parens to appease linter 2024-08-21 00:18:09 +01:00
Keith Cirkel f96a21f1fa
make Uri in http::header private 2024-08-19 14:13:00 +01:00
Keith Cirkel b66866d2d1
update references and text to RFC 9110 2024-08-19 14:13:00 +01:00
Keith Cirkel bbb7258e7b
add changelog entry for TryIntoHeaderValue Uri 2024-08-19 14:12:58 +01:00
Keith Cirkel 3ff861eb29
add referer typed header 2024-08-19 14:12:39 +01:00
Keith Cirkel f5d340878c
add location typed header 2024-08-19 14:12:39 +01:00
Keith Cirkel 342242a0e7
add content-location typed header 2024-08-19 14:12:38 +01:00
Keith Cirkel 9b6a93d72c
TryIntoHeaderValue for Uri 2024-08-19 14:12:09 +01:00
13 changed files with 197 additions and 50 deletions

View File

@ -49,7 +49,7 @@ jobs:
toolchain: ${{ matrix.version.version }} toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean - name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.3 uses: taiki-e/install-action@v2.56.13
with: with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -83,7 +83,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0 uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
- name: Install just, cargo-hack - name: Install just, cargo-hack
uses: taiki-e/install-action@v2.54.3 uses: taiki-e/install-action@v2.56.13
with: with:
tool: just,cargo-hack tool: just,cargo-hack

View File

@ -64,7 +64,7 @@ jobs:
toolchain: ${{ matrix.version.version }} toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean - name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.3 uses: taiki-e/install-action@v2.56.13
with: with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -113,7 +113,7 @@ jobs:
toolchain: nightly toolchain: nightly
- name: Install just - name: Install just
uses: taiki-e/install-action@v2.54.3 uses: taiki-e/install-action@v2.56.13
with: with:
tool: just tool: just

View File

@ -24,7 +24,7 @@ jobs:
components: llvm-tools components: llvm-tools
- name: Install just, cargo-llvm-cov, cargo-nextest - name: Install just, cargo-llvm-cov, cargo-nextest
uses: taiki-e/install-action@v2.54.3 uses: taiki-e/install-action@v2.56.13
with: with:
tool: just,cargo-llvm-cov,cargo-nextest tool: just,cargo-llvm-cov,cargo-nextest

View File

@ -77,7 +77,7 @@ jobs:
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }} toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
- name: Install just - name: Install just
uses: taiki-e/install-action@v2.54.3 uses: taiki-e/install-action@v2.56.13
with: with:
tool: just tool: just

100
Cargo.lock generated
View File

@ -147,7 +147,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"slab", "slab",
"socket2 0.5.10", "socket2 0.6.0",
"tokio", "tokio",
] ]
@ -393,7 +393,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"smallvec", "smallvec",
"socket2 0.5.10", "socket2 0.6.0",
"static_assertions", "static_assertions",
"time", "time",
"tokio", "tokio",
@ -1509,9 +1509,9 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.26" version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -1785,6 +1785,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "io-uring"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [
"bitflags 2.9.1",
"cfg-if",
"libc",
]
[[package]] [[package]]
name = "ipconfig" name = "ipconfig"
version = "0.3.2" version = "0.3.2"
@ -2794,9 +2805,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_spanned" name = "serde_spanned"
version = "0.6.8" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@ -2882,6 +2893,16 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "socket2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807"
dependencies = [
"libc",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.5.2" version = "0.5.2"
@ -3066,17 +3087,19 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.45.1" version = "1.46.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
"io-uring 0.7.8",
"libc", "libc",
"mio", "mio",
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
"slab",
"socket2 0.5.10", "socket2 0.5.10",
"tokio-macros", "tokio-macros",
"windows-sys 0.52.0", "windows-sys 0.52.0",
@ -3165,7 +3188,7 @@ checksum = "748482e3e13584a34664a710168ad5068e8cb1d968aa4ffa887e83ca6dd27967"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-util", "futures-util",
"io-uring", "io-uring 0.6.4",
"libc", "libc",
"slab", "slab",
"socket2 0.4.10", "socket2 0.4.10",
@ -3187,44 +3210,42 @@ dependencies = [
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.22" version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" checksum = "ed0aee96c12fa71097902e0bb061a5e1ebd766a6636bb605ba401c45c1650eac"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"toml_write", "toml_parser",
"toml_writer",
"winnow", "winnow",
] ]
[[package]] [[package]]
name = "toml_write" name = "toml_datetime"
version = "0.1.1" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3"
dependencies = [
"serde",
]
[[package]]
name = "toml_parser"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97200572db069e74c512a14117b296ba0a80a30123fbbb5aa1f4a348f639ca30"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64"
[[package]] [[package]]
name = "tracing" name = "tracing"
@ -3306,9 +3327,9 @@ dependencies = [
[[package]] [[package]]
name = "trybuild" name = "trybuild"
version = "1.0.105" version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c9bf9513a2f4aeef5fdac8677d7d349c79fdbcc03b9c86da6e9d254f1e43be2" checksum = "65af40ad689f2527aebbd37a0a816aea88ff5f774ceabe99de5be02f2f91dae2"
dependencies = [ dependencies = [
"glob", "glob",
"serde", "serde",
@ -3759,9 +3780,6 @@ name = "winnow"
version = "0.7.10" version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "winreg" name = "winreg"

View File

@ -53,7 +53,7 @@ serde = "1"
serde_json = "1" serde_json = "1"
serde_urlencoded = "0.7" serde_urlencoded = "0.7"
slab = "0.4" slab = "0.4"
socket2 = "0.5" socket2 = "0.6"
tls-openssl = { version = "0.10.55", package = "openssl", optional = true } tls-openssl = { version = "0.10.55", package = "openssl", optional = true }
tokio = { version = "1.38.2", features = ["sync"] } tokio = { version = "1.38.2", features = ["sync"] }

View File

@ -1,7 +1,7 @@
//! [`TryIntoHeaderValue`] trait and implementations. //! [`TryIntoHeaderValue`] trait and implementations.
use bytes::Bytes; use bytes::Bytes;
use http::{header::InvalidHeaderValue, Error as HttpError, HeaderValue}; use http::{header::InvalidHeaderValue, Error as HttpError, HeaderValue, Uri};
use mime::Mime; use mime::Mime;
/// An interface for types that can be converted into a [`HeaderValue`]. /// An interface for types that can be converted into a [`HeaderValue`].
@ -129,3 +129,12 @@ impl TryIntoHeaderValue for Mime {
HeaderValue::from_str(self.as_ref()) HeaderValue::from_str(self.as_ref())
} }
} }
impl TryIntoHeaderValue for Uri {
type Error = InvalidHeaderValue;
#[inline]
fn try_into_value(self) -> Result<HeaderValue, Self::Error> {
HeaderValue::from_str(&self.to_string())
}
}

View File

@ -32,6 +32,10 @@
- On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use. - On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use.
- Update `brotli` dependency to `7`. - Update `brotli` dependency to `7`.
- Minimum supported Rust version (MSRV) is now 1.75. - Minimum supported Rust version (MSRV) is now 1.75.
- Add `TryIntoHeaderValue` for `Uri` type.
- Add `http::header::ContentLocation` typed header.
- Add `http::header::Location` typed header.
- Add `http::header::Referer` typed header.
## 4.9.0 ## 4.9.0

View File

@ -158,7 +158,7 @@ serde = "1.0"
serde_json = "1.0" serde_json = "1.0"
serde_urlencoded = "0.7" serde_urlencoded = "0.7"
smallvec = "1.6.1" smallvec = "1.6.1"
socket2 = "0.5" socket2 = "0.6"
time = { version = "0.3", default-features = false, features = ["formatting"] } time = { version = "0.3", default-features = false, features = ["formatting"] }
tracing = "0.1.30" tracing = "0.1.30"
url = "2.5.4" url = "2.5.4"

View File

@ -0,0 +1,36 @@
use super::{Uri, CONTENT_LOCATION};
crate::http::header::common_header! {
/// `Content-Location` header, defined
/// in [RFC 9110 §8.7](https://datatracker.ietf.org/doc/html/rfc9110#section-8.7)
///
/// 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 content.
///
/// # 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::<Uri>().unwrap())
/// );
/// ```
(ContentLocation, CONTENT_LOCATION) => [Uri]
test_parse_and_format {
crate::http::header::common_header_test!(test1, [b"http://www.example.org/hypertext/Overview.html"]);
}
}

View File

@ -0,0 +1,37 @@
use super::{Uri, LOCATION};
crate::http::header::common_header! {
/// `Location` header, defined
/// in [RFC 9110 §10.2.2](https://datatracker.ietf.org/doc/html/rfc9110#section-10.2.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::<Uri>().unwrap())
/// );
/// ```
(Location, LOCATION) => [Uri]
test_parse_and_format {
crate::http::header::common_header_test!(test1, [b"http://www.example.org/hypertext/Overview.html"]);
}
}

View File

@ -14,6 +14,7 @@ use std::fmt;
// - the few typed headers from actix-http // - the few typed headers from actix-http
// - header parsing utils // - header parsing utils
pub use actix_http::header::*; pub use actix_http::header::*;
use actix_http::Uri;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
mod accept; mod accept;
@ -25,6 +26,7 @@ mod cache_control;
mod content_disposition; mod content_disposition;
mod content_language; mod content_language;
mod content_length; mod content_length;
mod content_location;
mod content_range; mod content_range;
mod content_type; mod content_type;
mod date; mod date;
@ -38,9 +40,11 @@ mod if_none_match;
mod if_range; mod if_range;
mod if_unmodified_since; mod if_unmodified_since;
mod last_modified; mod last_modified;
mod location;
mod macros; mod macros;
mod preference; mod preference;
mod range; mod range;
mod referer;
#[cfg(test)] #[cfg(test)]
pub(crate) use self::macros::common_header_test; pub(crate) use self::macros::common_header_test;
@ -55,6 +59,7 @@ pub use self::{
content_disposition::{ContentDisposition, DispositionParam, DispositionType}, content_disposition::{ContentDisposition, DispositionParam, DispositionType},
content_language::ContentLanguage, content_language::ContentLanguage,
content_length::ContentLength, content_length::ContentLength,
content_location::ContentLocation,
content_range::{ContentRange, ContentRangeSpec}, content_range::{ContentRange, ContentRangeSpec},
content_type::ContentType, content_type::ContentType,
date::Date, date::Date,
@ -68,8 +73,10 @@ pub use self::{
if_range::IfRange, if_range::IfRange,
if_unmodified_since::IfUnmodifiedSince, if_unmodified_since::IfUnmodifiedSince,
last_modified::LastModified, last_modified::LastModified,
location::Location,
preference::Preference, preference::Preference,
range::{ByteRangeSpec, Range}, range::{ByteRangeSpec, Range},
referer::Referer,
}; };
/// Format writer ([`fmt::Write`]) for a [`BytesMut`]. /// Format writer ([`fmt::Write`]) for a [`BytesMut`].

View File

@ -0,0 +1,36 @@
use super::{Uri, REFERER};
crate::http::header::common_header! {
/// `Referer` header, defined
/// in [RFC 9110 §10.1.3](https://datatracker.ietf.org/doc/html/rfc9110#section-10.1.3)
///
/// 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"]);
}
}