mirror of https://github.com/fafhrd91/actix-web
Compare commits
8 Commits
782f8cb5ff
...
236c30dba3
Author | SHA1 | Date |
---|---|---|
|
236c30dba3 | |
|
90c19a835d | |
|
adf57d2b24 | |
|
fcd10fbb5e | |
|
95b6a81f43 | |
|
ab18efe0ac | |
|
116f7d13b0 | |
|
feee43094e |
|
@ -0,0 +1,3 @@
|
||||||
|
version: "0.2"
|
||||||
|
words:
|
||||||
|
- actix
|
|
@ -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.49.17
|
uses: taiki-e/install-action@v2.49.33
|
||||||
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.11.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||||
|
|
||||||
- name: Install just, cargo-hack
|
- name: Install just, cargo-hack
|
||||||
uses: taiki-e/install-action@v2.49.17
|
uses: taiki-e/install-action@v2.49.33
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack
|
tool: just,cargo-hack
|
||||||
|
|
||||||
|
|
|
@ -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.49.17
|
uses: taiki-e/install-action@v2.49.33
|
||||||
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.49.17
|
uses: taiki-e/install-action@v2.49.33
|
||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
|
|
|
@ -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.49.17
|
uses: taiki-e/install-action@v2.49.33
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-llvm-cov,cargo-nextest
|
tool: just,cargo-llvm-cov,cargo-nextest
|
||||||
|
|
||||||
|
|
|
@ -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.49.17
|
uses: taiki-e/install-action@v2.49.33
|
||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
Cargo.lock
|
|
||||||
target/
|
target/
|
||||||
guide/build/
|
guide/build/
|
||||||
/gh-pages
|
/gh-pages
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,8 +18,8 @@ all-features = true
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bytesize = "2"
|
||||||
darling = "0.20"
|
darling = "0.20"
|
||||||
parse-size = "1"
|
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "1"
|
||||||
quote = "1"
|
quote = "1"
|
||||||
syn = "2"
|
syn = "2"
|
||||||
|
@ -27,7 +27,7 @@ syn = "2"
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-multipart = "0.7"
|
actix-multipart = "0.7"
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
rustversion = "1"
|
rustversion-msrv = "0.100"
|
||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use bytesize::ByteSize;
|
||||||
use darling::{FromDeriveInput, FromField, FromMeta};
|
use darling::{FromDeriveInput, FromField, FromMeta};
|
||||||
use parse_size::parse_size;
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::Ident;
|
use proc_macro2::Ident;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
@ -103,7 +103,7 @@ struct ParsedField<'t> {
|
||||||
/// # Field Limits
|
/// # Field Limits
|
||||||
///
|
///
|
||||||
/// You can use the `#[multipart(limit = "<size>")]` attribute to set field level limits. The limit
|
/// You can use the `#[multipart(limit = "<size>")]` attribute to set field level limits. The limit
|
||||||
/// string is parsed using [parse_size].
|
/// string is parsed using [`bytesize`].
|
||||||
///
|
///
|
||||||
/// Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
|
/// Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
|
||||||
///
|
///
|
||||||
|
@ -150,7 +150,7 @@ struct ParsedField<'t> {
|
||||||
/// struct Form { }
|
/// struct Form { }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [parse_size]: https://docs.rs/parse-size/1/parse_size
|
/// [`bytesize`]: https://docs.rs/bytesize/2
|
||||||
#[proc_macro_derive(MultipartForm, attributes(multipart))]
|
#[proc_macro_derive(MultipartForm, attributes(multipart))]
|
||||||
pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
let input: syn::DeriveInput = parse_macro_input!(input);
|
let input: syn::DeriveInput = parse_macro_input!(input);
|
||||||
|
@ -191,8 +191,8 @@ pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenS
|
||||||
let attrs = FieldAttrs::from_field(field).map_err(|err| err.write_errors())?;
|
let attrs = FieldAttrs::from_field(field).map_err(|err| err.write_errors())?;
|
||||||
let serialization_name = attrs.rename.unwrap_or_else(|| rust_name.to_string());
|
let serialization_name = attrs.rename.unwrap_or_else(|| rust_name.to_string());
|
||||||
|
|
||||||
let limit = match attrs.limit.map(|limit| match parse_size(&limit) {
|
let limit = match attrs.limit.map(|limit| match limit.parse::<ByteSize>() {
|
||||||
Ok(size) => Ok(usize::try_from(size).unwrap()),
|
Ok(ByteSize(size)) => Ok(usize::try_from(size).unwrap()),
|
||||||
Err(err) => Err(syn::Error::new(
|
Err(err) => Err(syn::Error::new(
|
||||||
field.ident.as_ref().unwrap().span(),
|
field.ident.as_ref().unwrap().span(),
|
||||||
format!("Could not parse size limit `{}`: {}", limit, err),
|
format!("Could not parse size limit `{}`: {}", limit, err),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[rustversion::stable(1.72)] // MSRV
|
#[rustversion_msrv::msrv]
|
||||||
#[test]
|
#[test]
|
||||||
fn compile_macros() {
|
fn compile_macros() {
|
||||||
let t = trybuild::TestCases::new();
|
let t = trybuild::TestCases::new();
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
error: Could not parse size limit `2 bytes`: invalid digit found in string
|
error: Could not parse size limit `2 bytes`: couldn't parse "bytes" into a known SI unit, couldn't parse unit of "bytes"
|
||||||
--> tests/trybuild/size-limit-parse-fail.rs:6:5
|
--> tests/trybuild/size-limit-parse-fail.rs:6:5
|
||||||
|
|
|
|
||||||
6 | description: Text<String>,
|
6 | description: Text<String>,
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error: Could not parse size limit `2 megabytes`: invalid digit found in string
|
error: Could not parse size limit `2 megabytes`: couldn't parse "megabytes" into a known SI unit, couldn't parse unit of "megabytes"
|
||||||
--> tests/trybuild/size-limit-parse-fail.rs:12:5
|
--> tests/trybuild/size-limit-parse-fail.rs:12:5
|
||||||
|
|
|
|
||||||
12 | description: Text<String>,
|
12 | description: Text<String>,
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error: Could not parse size limit `four meters`: invalid digit found in string
|
error: Could not parse size limit `four meters`: couldn't parse "four meters" into a ByteSize, cannot parse float from empty string
|
||||||
--> tests/trybuild/size-limit-parse-fail.rs:18:5
|
--> tests/trybuild/size-limit-parse-fail.rs:18:5
|
||||||
|
|
|
|
||||||
18 | description: Text<String>,
|
18 | description: Text<String>,
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
## 0.5.3
|
## 0.5.3
|
||||||
|
|
||||||
- Add `unicode` crate feature (on-by-default) to switch between `regex` and `regex-lite` as a trade-off between full unicode support and binary size.
|
- Add `unicode` crate feature (on-by-default) to switch between `regex` and `regex-lite` as a trade-off between full unicode support and binary size.
|
||||||
|
- Add support for extracting multi-component path params into a sequence (Vec, tuple, ...)
|
||||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
- Minimum supported Rust version (MSRV) is now 1.72.
|
||||||
|
|
||||||
## 0.5.2
|
## 0.5.2
|
||||||
|
|
|
@ -396,11 +396,25 @@ impl<'de> Deserializer<'de> for Value<'de> {
|
||||||
visitor.visit_newtype_struct(self)
|
visitor.visit_newtype_struct(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_tuple<V>(self, _: usize, _: V) -> Result<V::Value, Self::Error>
|
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
Err(de::value::Error::custom("unsupported type: tuple"))
|
let value_seq = ValueSeq::new(self.value);
|
||||||
|
if len == value_seq.len() {
|
||||||
|
visitor.visit_seq(value_seq)
|
||||||
|
} else {
|
||||||
|
Err(de::value::Error::custom(
|
||||||
|
"path and tuple lengths don't match",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
visitor.visit_seq(ValueSeq::new(self.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_struct<V>(
|
fn deserialize_struct<V>(
|
||||||
|
@ -428,7 +442,6 @@ impl<'de> Deserializer<'de> for Value<'de> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsupported_type!(deserialize_any, "any");
|
unsupported_type!(deserialize_any, "any");
|
||||||
unsupported_type!(deserialize_seq, "seq");
|
|
||||||
unsupported_type!(deserialize_map, "map");
|
unsupported_type!(deserialize_map, "map");
|
||||||
unsupported_type!(deserialize_identifier, "identifier");
|
unsupported_type!(deserialize_identifier, "identifier");
|
||||||
}
|
}
|
||||||
|
@ -498,6 +511,45 @@ impl<'de> de::VariantAccess<'de> for UnitVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ValueSeq<'de> {
|
||||||
|
value: &'de str,
|
||||||
|
elems: std::str::Split<'de, char>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> ValueSeq<'de> {
|
||||||
|
fn new(value: &'de str) -> Self {
|
||||||
|
Self {
|
||||||
|
value,
|
||||||
|
elems: value.split('/'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
self.value.split('/').filter(|s| !s.is_empty()).count()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> de::SeqAccess<'de> for ValueSeq<'de> {
|
||||||
|
type Error = de::value::Error;
|
||||||
|
|
||||||
|
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
||||||
|
where
|
||||||
|
T: de::DeserializeSeed<'de>,
|
||||||
|
{
|
||||||
|
for elem in &mut self.elems {
|
||||||
|
if !elem.is_empty() {
|
||||||
|
return seed.deserialize(Value { value: elem }).map(Some);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> Option<usize> {
|
||||||
|
Some(self.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -532,6 +584,16 @@ mod tests {
|
||||||
val: TestEnum,
|
val: TestEnum,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct TestSeq1 {
|
||||||
|
tail: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct TestSeq2 {
|
||||||
|
tail: (String, String, String),
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_request_extract() {
|
fn test_request_extract() {
|
||||||
let mut router = Router::<()>::build();
|
let mut router = Router::<()>::build();
|
||||||
|
@ -627,6 +689,39 @@ mod tests {
|
||||||
assert!(format!("{:?}", i).contains("unknown variant"));
|
assert!(format!("{:?}", i).contains("unknown variant"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_extract_seq() {
|
||||||
|
let mut router = Router::<()>::build();
|
||||||
|
router.path("/path/to/{tail}*", ());
|
||||||
|
let router = router.finish();
|
||||||
|
|
||||||
|
let mut path = Path::new("/path/to/tail/with/slash%2fes");
|
||||||
|
assert!(router.recognize(&mut path).is_some());
|
||||||
|
|
||||||
|
let i: (String,) = de::Deserialize::deserialize(PathDeserializer::new(&path)).unwrap();
|
||||||
|
assert_eq!(i.0, String::from("tail/with/slash/es"));
|
||||||
|
|
||||||
|
let i: TestSeq1 = de::Deserialize::deserialize(PathDeserializer::new(&path)).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
i.tail,
|
||||||
|
vec![
|
||||||
|
String::from("tail"),
|
||||||
|
String::from("with"),
|
||||||
|
String::from("slash/es")
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
let i: TestSeq2 = de::Deserialize::deserialize(PathDeserializer::new(&path)).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
i.tail,
|
||||||
|
(
|
||||||
|
String::from("tail"),
|
||||||
|
String::from("with"),
|
||||||
|
String::from("slash/es")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_extract_errors() {
|
fn test_extract_errors() {
|
||||||
let mut router = Router::<()>::build();
|
let mut router = Router::<()>::build();
|
||||||
|
|
|
@ -34,7 +34,7 @@ actix-web = "4"
|
||||||
|
|
||||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
rustversion = "1"
|
rustversion-msrv = "0.100"
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[rustversion::stable(1.72)] // MSRV
|
#[rustversion_msrv::msrv]
|
||||||
#[test]
|
#[test]
|
||||||
fn compile_macros() {
|
fn compile_macros() {
|
||||||
let t = trybuild::TestCases::new();
|
let t = trybuild::TestCases::new();
|
||||||
|
|
|
@ -53,6 +53,26 @@ use crate::{
|
||||||
/// format!("Welcome {}!", info.name)
|
/// format!("Welcome {}!", info.name)
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// Segments matching multiple path components can be deserialized
|
||||||
|
/// into a Vec<_> to percent-decode the components individually. Empty
|
||||||
|
/// path components are ignored.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use actix_web::{get, web};
|
||||||
|
/// use serde::Deserialize;
|
||||||
|
///
|
||||||
|
/// #[derive(Deserialize)]
|
||||||
|
/// struct Tail {
|
||||||
|
/// tail: Vec<String>,
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// // extract `Tail` from a path using serde
|
||||||
|
/// #[get("/path/to/{tail}*")]
|
||||||
|
/// async fn index(info: web::Path<Tail>) -> String {
|
||||||
|
/// format!("Navigating to {}!", info.tail.join(" :: "))
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From)]
|
||||||
pub struct Path<T>(T);
|
pub struct Path<T>(T);
|
||||||
|
|
||||||
|
|
12
justfile
12
justfile
|
@ -7,14 +7,14 @@ fmt:
|
||||||
cargo +nightly fmt
|
cargo +nightly fmt
|
||||||
fd --hidden --type=file --extension=md --extension=yml --exec-batch npx -y prettier --write
|
fd --hidden --type=file --extension=md --extension=yml --exec-batch npx -y prettier --write
|
||||||
|
|
||||||
# Downgrade dev-dependencies necessary to run MSRV checks/tests.
|
# Downgrade dependencies necessary to run MSRV checks/tests.
|
||||||
[private]
|
[private]
|
||||||
downgrade-for-msrv:
|
downgrade-for-msrv:
|
||||||
cargo update -p=parse-size --precise=1.0.0
|
cargo update -p=clap --precise=4.4.18 # next ver: 1.74.0
|
||||||
cargo update -p=clap --precise=4.4.18
|
cargo update -p=divan --precise=0.1.15 # next ver: 1.80.0
|
||||||
cargo update -p=divan --precise=0.1.15
|
cargo update -p=litemap --precise=0.7.4 # next ver: 1.81.0
|
||||||
cargo update -p=litemap --precise=0.7.4
|
cargo update -p=zerofrom --precise=0.1.5 # next ver: 1.81.0
|
||||||
cargo update -p=zerofrom --precise=0.1.5
|
cargo update -p=half --precise=2.4.1 # next ver: 1.81.0
|
||||||
|
|
||||||
msrv := ```
|
msrv := ```
|
||||||
cargo metadata --format-version=1 \
|
cargo metadata --format-version=1 \
|
||||||
|
|
Loading…
Reference in New Issue