mirror of https://github.com/fafhrd91/actix-web
Compare commits
13 Commits
c9404acbb3
...
9b253a7cfe
Author | SHA1 | Date |
---|---|---|
|
9b253a7cfe | |
|
95b6a81f43 | |
|
ab18efe0ac | |
|
cfaa5b24c7 | |
|
66873d16b5 | |
|
4f8819d277 | |
|
f96a21f1fa | |
|
b66866d2d1 | |
|
bbb7258e7b | |
|
3ff861eb29 | |
|
f5d340878c | |
|
342242a0e7 | |
|
9b6a93d72c |
|
@ -0,0 +1,3 @@
|
|||
version: "0.2"
|
||||
words:
|
||||
- actix
|
|
@ -1,4 +1,3 @@
|
|||
Cargo.lock
|
||||
target/
|
||||
guide/build/
|
||||
/gh-pages
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
//! [`TryIntoHeaderValue`] trait and implementations.
|
||||
|
||||
use bytes::Bytes;
|
||||
use http::{header::InvalidHeaderValue, Error as HttpError, HeaderValue};
|
||||
use http::{header::InvalidHeaderValue, Error as HttpError, HeaderValue, Uri};
|
||||
use mime::Mime;
|
||||
|
||||
/// 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())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryIntoHeaderValue for Uri {
|
||||
type Error = InvalidHeaderValue;
|
||||
|
||||
#[inline]
|
||||
fn try_into_value(self) -> Result<HeaderValue, Self::Error> {
|
||||
HeaderValue::from_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ all-features = true
|
|||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
bytesize = "2"
|
||||
darling = "0.20"
|
||||
parse-size = "1"
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = "2"
|
||||
|
@ -27,7 +27,7 @@ syn = "2"
|
|||
[dev-dependencies]
|
||||
actix-multipart = "0.7"
|
||||
actix-web = "4"
|
||||
rustversion = "1"
|
||||
rustversion-msrv = "0.100"
|
||||
trybuild = "1"
|
||||
|
||||
[lints]
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use bytesize::ByteSize;
|
||||
use darling::{FromDeriveInput, FromField, FromMeta};
|
||||
use parse_size::parse_size;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Ident;
|
||||
use quote::quote;
|
||||
|
@ -103,7 +103,7 @@ struct ParsedField<'t> {
|
|||
/// # Field Limits
|
||||
///
|
||||
/// 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`.
|
||||
///
|
||||
|
@ -150,7 +150,7 @@ struct ParsedField<'t> {
|
|||
/// struct Form { }
|
||||
/// ```
|
||||
///
|
||||
/// [parse_size]: https://docs.rs/parse-size/1/parse_size
|
||||
/// [`bytesize`]: https://docs.rs/bytesize/2
|
||||
#[proc_macro_derive(MultipartForm, attributes(multipart))]
|
||||
pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
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 serialization_name = attrs.rename.unwrap_or_else(|| rust_name.to_string());
|
||||
|
||||
let limit = match attrs.limit.map(|limit| match parse_size(&limit) {
|
||||
Ok(size) => Ok(usize::try_from(size).unwrap()),
|
||||
let limit = match attrs.limit.map(|limit| match limit.parse::<ByteSize>() {
|
||||
Ok(ByteSize(size)) => Ok(usize::try_from(size).unwrap()),
|
||||
Err(err) => Err(syn::Error::new(
|
||||
field.ident.as_ref().unwrap().span(),
|
||||
format!("Could not parse size limit `{}`: {}", limit, err),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#[rustversion::stable(1.72)] // MSRV
|
||||
#[rustversion_msrv::msrv]
|
||||
#[test]
|
||||
fn compile_macros() {
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
18 | description: Text<String>,
|
||||
|
|
|
@ -34,7 +34,7 @@ actix-web = "4"
|
|||
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
trybuild = "1"
|
||||
rustversion = "1"
|
||||
rustversion-msrv = "0.100"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#[rustversion::stable(1.72)] // MSRV
|
||||
#[rustversion_msrv::msrv]
|
||||
#[test]
|
||||
fn compile_macros() {
|
||||
let t = trybuild::TestCases::new();
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
- 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`.
|
||||
- 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
|
||||
|
||||
|
|
|
@ -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"]);
|
||||
}
|
||||
}
|
|
@ -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"]);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ use std::fmt;
|
|||
// - the few typed headers from actix-http
|
||||
// - header parsing utils
|
||||
pub use actix_http::header::*;
|
||||
use actix_http::Uri;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
|
||||
mod accept;
|
||||
|
@ -25,6 +26,7 @@ mod cache_control;
|
|||
mod content_disposition;
|
||||
mod content_language;
|
||||
mod content_length;
|
||||
mod content_location;
|
||||
mod content_range;
|
||||
mod content_type;
|
||||
mod date;
|
||||
|
@ -38,9 +40,11 @@ mod if_none_match;
|
|||
mod if_range;
|
||||
mod if_unmodified_since;
|
||||
mod last_modified;
|
||||
mod location;
|
||||
mod macros;
|
||||
mod preference;
|
||||
mod range;
|
||||
mod referer;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use self::macros::common_header_test;
|
||||
|
@ -55,6 +59,7 @@ pub use self::{
|
|||
content_disposition::{ContentDisposition, DispositionParam, DispositionType},
|
||||
content_language::ContentLanguage,
|
||||
content_length::ContentLength,
|
||||
content_location::ContentLocation,
|
||||
content_range::{ContentRange, ContentRangeSpec},
|
||||
content_type::ContentType,
|
||||
date::Date,
|
||||
|
@ -68,8 +73,10 @@ pub use self::{
|
|||
if_range::IfRange,
|
||||
if_unmodified_since::IfUnmodifiedSince,
|
||||
last_modified::LastModified,
|
||||
location::Location,
|
||||
preference::Preference,
|
||||
range::{ByteRangeSpec, Range},
|
||||
referer::Referer,
|
||||
};
|
||||
|
||||
/// Format writer ([`fmt::Write`]) for a [`BytesMut`].
|
||||
|
|
|
@ -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"]);
|
||||
}
|
||||
}
|
12
justfile
12
justfile
|
@ -7,14 +7,14 @@ fmt:
|
|||
cargo +nightly fmt
|
||||
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]
|
||||
downgrade-for-msrv:
|
||||
cargo update -p=parse-size --precise=1.0.0
|
||||
cargo update -p=clap --precise=4.4.18
|
||||
cargo update -p=divan --precise=0.1.15
|
||||
cargo update -p=litemap --precise=0.7.4
|
||||
cargo update -p=zerofrom --precise=0.1.5
|
||||
cargo update -p=clap --precise=4.4.18 # next ver: 1.74.0
|
||||
cargo update -p=divan --precise=0.1.15 # next ver: 1.80.0
|
||||
cargo update -p=litemap --precise=0.7.4 # next ver: 1.81.0
|
||||
cargo update -p=zerofrom --precise=0.1.5 # next ver: 1.81.0
|
||||
cargo update -p=half --precise=2.4.1 # next ver: 1.81.0
|
||||
|
||||
msrv := ```
|
||||
cargo metadata --format-version=1 \
|
||||
|
|
Loading…
Reference in New Issue