From a9e44bcf070b9f51b34f29696b5afd0ed351e7bf Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 12 Sep 2022 10:42:22 +0100 Subject: [PATCH 1/3] fix -http version to 3.2.2 (#2871) fixes #2869 --- actix-web/CHANGES.md | 4 ++++ actix-web/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 03ea1eba8..ad865fb2e 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,6 +1,10 @@ # Changelog ## Unreleased - 2022-xx-xx +### Fixed +- Bump minimum version of `actix-http` dependency to fix compatibility issue. [#2871] + +[#2871]: https://github.com/actix/actix-web/pull/2871 ## 4.2.0 - 2022-09-11 diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 27a77bfc0..a06b06331 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -71,7 +71,7 @@ actix-service = "2" actix-utils = "3" actix-tls = { version = "3", default-features = false, optional = true } -actix-http = { version = "3", features = ["http2", "ws"] } +actix-http = { version = "3.2.2", features = ["http2", "ws"] } actix-router = "0.5" actix-web-codegen = { version = "4.1", optional = true } From 40f7ab38d29c313d1532c4588012662ed724110c Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 12 Sep 2022 10:43:03 +0100 Subject: [PATCH 2/3] prepare actix-web release 4.2.1 --- actix-web/CHANGES.md | 3 +++ actix-web/Cargo.toml | 2 +- actix-web/README.md | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index ad865fb2e..d11108c2a 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,6 +1,9 @@ # Changelog ## Unreleased - 2022-xx-xx + + +## 4.2.1 - 2022-09-12 ### Fixed - Bump minimum version of `actix-http` dependency to fix compatibility issue. [#2871] diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index a06b06331..d57e52f36 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "4.2.0" +version = "4.2.1" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-web/README.md b/actix-web/README.md index 17bd5a7ce..65076e0b8 100644 --- a/actix-web/README.md +++ b/actix-web/README.md @@ -6,10 +6,10 @@

[![crates.io](https://img.shields.io/crates/v/actix-web?label=latest)](https://crates.io/crates/actix-web) -[![Documentation](https://docs.rs/actix-web/badge.svg?version=4.2.0)](https://docs.rs/actix-web/4.2.0) +[![Documentation](https://docs.rs/actix-web/badge.svg?version=4.2.1)](https://docs.rs/actix-web/4.2.1) ![MSRV](https://img.shields.io/badge/rustc-1.59+-ab6000.svg) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-web.svg) -[![Dependency Status](https://deps.rs/crate/actix-web/4.2.0/status.svg)](https://deps.rs/crate/actix-web/4.2.0) +[![Dependency Status](https://deps.rs/crate/actix-web/4.2.1/status.svg)](https://deps.rs/crate/actix-web/4.2.1)
[![CI](https://github.com/actix/actix-web/actions/workflows/ci.yml/badge.svg)](https://github.com/actix/actix-web/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/actix/actix-web/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-web) From 909461087c608855aa252bf2b3343aac53210c75 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 13 Sep 2022 01:19:25 +0100 Subject: [PATCH 3/3] add `ContentDisposition::attachment` constructor (#2867) --- actix-web/CHANGES.md | 4 ++++ .../src/http/header/content_disposition.rs | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index d11108c2a..9ded67e35 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,6 +1,10 @@ # Changelog ## Unreleased - 2022-xx-xx +### Added +- Add `ContentDisposition::attachment` constructor. [#2867] + +[#2867]: https://github.com/actix/actix-web/pull/2867 ## 4.2.1 - 2022-09-12 diff --git a/actix-web/src/http/header/content_disposition.rs b/actix-web/src/http/header/content_disposition.rs index 0bb459193..f743302a2 100644 --- a/actix-web/src/http/header/content_disposition.rs +++ b/actix-web/src/http/header/content_disposition.rs @@ -79,7 +79,7 @@ impl<'a> From<&'a str> for DispositionType { /// assert!(param.is_filename()); /// assert_eq!(param.as_filename().unwrap(), "sample.txt"); /// ``` -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[allow(clippy::large_enum_variant)] pub enum DispositionParam { /// For [`DispositionType::FormData`] (i.e. *multipart/form-data*), the name of an field from @@ -302,7 +302,7 @@ impl DispositionParam { /// change to match local file system conventions if applicable, and do not use directory path /// information that may be present. /// See [RFC 2183 ยง2.3](https://datatracker.ietf.org/doc/html/rfc2183#section-2.3). -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ContentDisposition { /// The disposition type pub disposition: DispositionType, @@ -312,16 +312,36 @@ pub struct ContentDisposition { } impl ContentDisposition { + /// Constructs a Content-Disposition header suitable for downloads. + /// + /// # Examples + /// ``` + /// use actix_web::http::header::{ContentDisposition, TryIntoHeaderValue as _}; + /// + /// let cd = ContentDisposition::attachment("files.zip"); + /// + /// let cd_val = cd.try_into_value().unwrap(); + /// assert_eq!(cd_val, "attachment; filename=\"files.zip\""); + /// ``` + pub fn attachment(filename: impl Into) -> Self { + Self { + disposition: DispositionType::Attachment, + parameters: vec![DispositionParam::Filename(filename.into())], + } + } + /// Parse a raw Content-Disposition header value. pub fn from_raw(hv: &header::HeaderValue) -> Result { // `header::from_one_raw_str` invokes `hv.to_str` which assumes `hv` contains only visible // ASCII characters. So `hv.as_bytes` is necessary here. let hv = String::from_utf8(hv.as_bytes().to_vec()) .map_err(|_| crate::error::ParseError::Header)?; + let (disp_type, mut left) = split_once_and_trim(hv.as_str().trim(), ';'); if disp_type.is_empty() { return Err(crate::error::ParseError::Header); } + let mut cd = ContentDisposition { disposition: disp_type.into(), parameters: Vec::new(),