rename trait to TryIntoHeaderValue

This commit is contained in:
Rob Ede 2021-12-13 05:57:04 +00:00
parent afc9aa4c92
commit 44005e216e
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
25 changed files with 83 additions and 74 deletions

View File

@ -2,12 +2,16 @@
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
### Added ### Added
* Method on `Responder` trait (`customize`) for customizing responders and `CustomizeResponder` struct. [#????] * Method on `Responder` trait (`customize`) for customizing responders and `CustomizeResponder` struct. [#2510]
* Implement `Debug` for `DefaultHeaders`. [#2510]
### Changed ### Changed
* Align `DefaultHeader` method terminology, deprecating previous methods. [#????] * Align `DefaultHeader` method terminology, deprecating previous methods. [#2510]
[#????]: https://github.com/actix/actix-web/pull/???? ### Removed
* Top-level `EitherExtractError` export. [#2510]
[#2510]: https://github.com/actix/actix-web/pull/2510
## 4.0.0-beta.14 - 2021-12-11 ## 4.0.0-beta.14 - 2021-12-11

View File

@ -2,9 +2,10 @@
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
### Changed ### Changed
* Rename trait `IntoHeaderPair => TryIntoHeaderPair`. [#????] * Rename trait `IntoHeaderPair => TryIntoHeaderPair`. [#2510]
* Rename trait `IntoHeaderValue => TryIntoHeaderValue`. [#2510]
[#????]: https://github.com/actix/actix-web/pull/???? [#2510]: https://github.com/actix/actix-web/pull/2510
## 3.0.0-beta.15 - 2021-12-11 ## 3.0.0-beta.15 - 2021-12-11
@ -275,9 +276,9 @@
* `trust-dns` optional feature to enable `trust-dns-resolver` as client dns resolver. [#1969] * `trust-dns` optional feature to enable `trust-dns-resolver` as client dns resolver. [#1969]
### Changed ### Changed
* `ResponseBuilder::content_type` now takes an `impl IntoHeaderValue` to support using typed * `ResponseBuilder::content_type` now takes an `impl TryIntoHeaderValue` to support using typed
`mime` types. [#1894] `mime` types. [#1894]
* Renamed `IntoHeaderValue::{try_into => try_into_value}` to avoid ambiguity with std * Renamed `TryIntoHeaderValue::{try_into => try_into_value}` to avoid ambiguity with std
`TryInto` trait. [#1894] `TryInto` trait. [#1894]
* `Extensions::insert` returns Option of replaced item. [#1904] * `Extensions::insert` returns Option of replaced item. [#1904]
* Remove `HttpResponseBuilder::json2()`. [#1903] * Remove `HttpResponseBuilder::json2()`. [#1903]

View File

@ -3,7 +3,7 @@
use std::convert::TryFrom as _; use std::convert::TryFrom as _;
use super::{ use super::{
Header, HeaderName, HeaderValue, IntoHeaderValue, InvalidHeaderName, InvalidHeaderValue, Header, HeaderName, HeaderValue, InvalidHeaderName, InvalidHeaderValue, TryIntoHeaderValue,
}; };
use crate::error::HttpError; use crate::error::HttpError;
@ -34,7 +34,7 @@ impl From<InvalidHeaderPart> for HttpError {
impl<V> TryIntoHeaderPair for (HeaderName, V) impl<V> TryIntoHeaderPair for (HeaderName, V)
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
V::Error: Into<InvalidHeaderValue>, V::Error: Into<InvalidHeaderValue>,
{ {
type Error = InvalidHeaderPart; type Error = InvalidHeaderPart;
@ -50,7 +50,7 @@ where
impl<V> TryIntoHeaderPair for (&HeaderName, V) impl<V> TryIntoHeaderPair for (&HeaderName, V)
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
V::Error: Into<InvalidHeaderValue>, V::Error: Into<InvalidHeaderValue>,
{ {
type Error = InvalidHeaderPart; type Error = InvalidHeaderPart;
@ -66,7 +66,7 @@ where
impl<V> TryIntoHeaderPair for (&[u8], V) impl<V> TryIntoHeaderPair for (&[u8], V)
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
V::Error: Into<InvalidHeaderValue>, V::Error: Into<InvalidHeaderValue>,
{ {
type Error = InvalidHeaderPart; type Error = InvalidHeaderPart;
@ -83,7 +83,7 @@ where
impl<V> TryIntoHeaderPair for (&str, V) impl<V> TryIntoHeaderPair for (&str, V)
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
V::Error: Into<InvalidHeaderValue>, V::Error: Into<InvalidHeaderValue>,
{ {
type Error = InvalidHeaderPart; type Error = InvalidHeaderPart;
@ -100,7 +100,7 @@ where
impl<V> TryIntoHeaderPair for (String, V) impl<V> TryIntoHeaderPair for (String, V)
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
V::Error: Into<InvalidHeaderValue>, V::Error: Into<InvalidHeaderValue>,
{ {
type Error = InvalidHeaderPart; type Error = InvalidHeaderPart;
@ -113,7 +113,7 @@ where
} }
impl<T: Header> TryIntoHeaderPair for T { impl<T: Header> TryIntoHeaderPair for T {
type Error = <T as IntoHeaderValue>::Error; type Error = <T as TryIntoHeaderValue>::Error;
#[inline] #[inline]
fn try_into_header_pair(self) -> Result<(HeaderName, HeaderValue), Self::Error> { fn try_into_header_pair(self) -> Result<(HeaderName, HeaderValue), Self::Error> {

View File

@ -1,4 +1,4 @@
//! [`IntoHeaderValue`] trait and implementations. //! [`TryIntoHeaderValue`] trait and implementations.
use std::convert::TryFrom as _; use std::convert::TryFrom as _;
@ -7,7 +7,7 @@ use http::{header::InvalidHeaderValue, Error as HttpError, HeaderValue};
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`].
pub trait IntoHeaderValue: Sized { pub trait TryIntoHeaderValue: Sized {
/// The type returned in the event of a conversion error. /// The type returned in the event of a conversion error.
type Error: Into<HttpError>; type Error: Into<HttpError>;
@ -15,7 +15,7 @@ pub trait IntoHeaderValue: Sized {
fn try_into_value(self) -> Result<HeaderValue, Self::Error>; fn try_into_value(self) -> Result<HeaderValue, Self::Error>;
} }
impl IntoHeaderValue for HeaderValue { impl TryIntoHeaderValue for HeaderValue {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -24,7 +24,7 @@ impl IntoHeaderValue for HeaderValue {
} }
} }
impl IntoHeaderValue for &HeaderValue { impl TryIntoHeaderValue for &HeaderValue {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -33,7 +33,7 @@ impl IntoHeaderValue for &HeaderValue {
} }
} }
impl IntoHeaderValue for &str { impl TryIntoHeaderValue for &str {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -42,7 +42,7 @@ impl IntoHeaderValue for &str {
} }
} }
impl IntoHeaderValue for &[u8] { impl TryIntoHeaderValue for &[u8] {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -51,7 +51,7 @@ impl IntoHeaderValue for &[u8] {
} }
} }
impl IntoHeaderValue for Bytes { impl TryIntoHeaderValue for Bytes {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -60,7 +60,7 @@ impl IntoHeaderValue for Bytes {
} }
} }
impl IntoHeaderValue for Vec<u8> { impl TryIntoHeaderValue for Vec<u8> {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -69,7 +69,7 @@ impl IntoHeaderValue for Vec<u8> {
} }
} }
impl IntoHeaderValue for String { impl TryIntoHeaderValue for String {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -78,7 +78,7 @@ impl IntoHeaderValue for String {
} }
} }
impl IntoHeaderValue for usize { impl TryIntoHeaderValue for usize {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -87,7 +87,7 @@ impl IntoHeaderValue for usize {
} }
} }
impl IntoHeaderValue for i64 { impl TryIntoHeaderValue for i64 {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -96,7 +96,7 @@ impl IntoHeaderValue for i64 {
} }
} }
impl IntoHeaderValue for u64 { impl TryIntoHeaderValue for u64 {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -105,7 +105,7 @@ impl IntoHeaderValue for u64 {
} }
} }
impl IntoHeaderValue for i32 { impl TryIntoHeaderValue for i32 {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -114,7 +114,7 @@ impl IntoHeaderValue for i32 {
} }
} }
impl IntoHeaderValue for u32 { impl TryIntoHeaderValue for u32 {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]
@ -123,7 +123,7 @@ impl IntoHeaderValue for u32 {
} }
} }
impl IntoHeaderValue for Mime { impl TryIntoHeaderValue for Mime {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
#[inline] #[inline]

View File

@ -38,7 +38,7 @@ mod utils;
pub use self::as_name::AsHeaderName; pub use self::as_name::AsHeaderName;
pub use self::into_pair::TryIntoHeaderPair; pub use self::into_pair::TryIntoHeaderPair;
pub use self::into_value::IntoHeaderValue; pub use self::into_value::TryIntoHeaderValue;
pub use self::map::HeaderMap; pub use self::map::HeaderMap;
pub use self::shared::{ pub use self::shared::{
parse_extended_value, q, Charset, ContentEncoding, ExtendedValue, HttpDate, LanguageTag, parse_extended_value, q, Charset, ContentEncoding, ExtendedValue, HttpDate, LanguageTag,
@ -49,7 +49,7 @@ pub use self::utils::{
}; };
/// An interface for types that already represent a valid header. /// An interface for types that already represent a valid header.
pub trait Header: IntoHeaderValue { pub trait Header: TryIntoHeaderValue {
/// Returns the name of the header field /// Returns the name of the header field
fn name() -> HeaderName; fn name() -> HeaderName;

View File

@ -5,7 +5,7 @@ use http::header::InvalidHeaderValue;
use crate::{ use crate::{
error::ParseError, error::ParseError,
header::{self, from_one_raw_str, Header, HeaderName, HeaderValue, IntoHeaderValue}, header::{self, from_one_raw_str, Header, HeaderName, HeaderValue, TryIntoHeaderValue},
HttpMessage, HttpMessage,
}; };
@ -96,7 +96,7 @@ impl TryFrom<&str> for ContentEncoding {
} }
} }
impl IntoHeaderValue for ContentEncoding { impl TryIntoHeaderValue for ContentEncoding {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
fn try_into_value(self) -> Result<http::HeaderValue, Self::Error> { fn try_into_value(self) -> Result<http::HeaderValue, Self::Error> {

View File

@ -4,7 +4,8 @@ use bytes::BytesMut;
use http::header::{HeaderValue, InvalidHeaderValue}; use http::header::{HeaderValue, InvalidHeaderValue};
use crate::{ use crate::{
config::DATE_VALUE_LENGTH, error::ParseError, header::IntoHeaderValue, helpers::MutWriter, config::DATE_VALUE_LENGTH, error::ParseError, header::TryIntoHeaderValue,
helpers::MutWriter,
}; };
/// A timestamp with HTTP-style formatting and parsing. /// A timestamp with HTTP-style formatting and parsing.
@ -29,7 +30,7 @@ impl fmt::Display for HttpDate {
} }
} }
impl IntoHeaderValue for HttpDate { impl TryIntoHeaderValue for HttpDate {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
fn try_into_value(self) -> Result<HeaderValue, Self::Error> { fn try_into_value(self) -> Result<HeaderValue, Self::Error> {

View File

@ -11,7 +11,7 @@ use bytestring::ByteString;
use crate::{ use crate::{
body::{BoxBody, MessageBody}, body::{BoxBody, MessageBody},
extensions::Extensions, extensions::Extensions,
header::{self, HeaderMap, IntoHeaderValue}, header::{self, HeaderMap, TryIntoHeaderValue},
message::{BoxedResponseHead, ResponseHead}, message::{BoxedResponseHead, ResponseHead},
Error, ResponseBuilder, StatusCode, Error, ResponseBuilder, StatusCode,
}; };

View File

@ -8,7 +8,7 @@ use std::{
use crate::{ use crate::{
body::{EitherBody, MessageBody}, body::{EitherBody, MessageBody},
error::{Error, HttpError}, error::{Error, HttpError},
header::{self, IntoHeaderValue, TryIntoHeaderPair}, header::{self, TryIntoHeaderPair, TryIntoHeaderValue},
message::{BoxedResponseHead, ConnectionType, ResponseHead}, message::{BoxedResponseHead, ConnectionType, ResponseHead},
Extensions, Response, StatusCode, Extensions, Response, StatusCode,
}; };
@ -151,7 +151,7 @@ impl ResponseBuilder {
#[inline] #[inline]
pub fn upgrade<V>(&mut self, value: V) -> &mut Self pub fn upgrade<V>(&mut self, value: V) -> &mut Self
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
if let Some(parts) = self.inner() { if let Some(parts) = self.inner() {
parts.set_connection_type(ConnectionType::Upgrade); parts.set_connection_type(ConnectionType::Upgrade);
@ -189,7 +189,7 @@ impl ResponseBuilder {
#[inline] #[inline]
pub fn content_type<V>(&mut self, value: V) -> &mut Self pub fn content_type<V>(&mut self, value: V) -> &mut Self
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
if let Some(parts) = self.inner() { if let Some(parts) = self.inner() {
match value.try_into_value() { match value.try_into_value() {

View File

@ -166,7 +166,7 @@ where
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: fmt::Debug + Into<HttpError>, <HeaderName as TryFrom<K>>::Error: fmt::Debug + Into<HttpError>,
V: header::IntoHeaderValue, V: header::TryIntoHeaderValue,
V::Error: fmt::Debug, V::Error: fmt::Debug,
{ {
match HeaderName::try_from(key) { match HeaderName::try_from(key) {

View File

@ -9,7 +9,7 @@ use actix_http::{
body::{BodySize, MessageBody}, body::{BodySize, MessageBody},
error::PayloadError, error::PayloadError,
h1, h1,
header::{HeaderMap, IntoHeaderValue, EXPECT, HOST}, header::{HeaderMap, TryIntoHeaderValue, EXPECT, HOST},
Payload, RequestHeadType, ResponseHead, StatusCode, Payload, RequestHeadType, ResponseHead, StatusCode,
}; };
use actix_utils::future::poll_fn; use actix_utils::future::poll_fn;

View File

@ -6,7 +6,7 @@ use serde::Serialize;
use actix_http::{ use actix_http::{
error::HttpError, error::HttpError,
header::{HeaderMap, HeaderName, IntoHeaderValue}, header::{HeaderMap, HeaderName, TryIntoHeaderValue},
Method, RequestHead, Uri, Method, RequestHead, Uri,
}; };
@ -114,7 +114,7 @@ impl FrozenClientRequest {
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>, <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
self.extra_headers(HeaderMap::new()) self.extra_headers(HeaderMap::new())
.extra_header(key, value) .extra_header(key, value)
@ -142,7 +142,7 @@ impl FrozenSendBuilder {
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>, <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
match HeaderName::try_from(key) { match HeaderName::try_from(key) {
Ok(key) => match value.try_into_value() { Ok(key) => match value.try_into_value() {

View File

@ -10,7 +10,7 @@ use std::{
use actix_http::{ use actix_http::{
body::BodyStream, body::BodyStream,
error::HttpError, error::HttpError,
header::{self, HeaderMap, HeaderName, IntoHeaderValue}, header::{self, HeaderMap, HeaderName, TryIntoHeaderValue},
RequestHead, RequestHeadType, RequestHead, RequestHeadType,
}; };
use actix_rt::time::{sleep, Sleep}; use actix_rt::time::{sleep, Sleep};
@ -298,7 +298,7 @@ impl RequestSender {
fn set_header_if_none<V>(&mut self, key: HeaderName, value: V) -> Result<(), HttpError> fn set_header_if_none<V>(&mut self, key: HeaderName, value: V) -> Result<(), HttpError>
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
match self { match self {
RequestSender::Owned(head) => { RequestSender::Owned(head) => {

View File

@ -39,7 +39,7 @@ use crate::{
connect::{BoxedSocket, ConnectRequest}, connect::{BoxedSocket, ConnectRequest},
error::{HttpError, InvalidUrl, SendRequestError, WsClientError}, error::{HttpError, InvalidUrl, SendRequestError, WsClientError},
http::{ http::{
header::{self, HeaderName, HeaderValue, IntoHeaderValue, AUTHORIZATION}, header::{self, HeaderName, HeaderValue, TryIntoHeaderValue, AUTHORIZATION},
ConnectionType, Method, StatusCode, Uri, Version, ConnectionType, Method, StatusCode, Uri, Version,
}, },
response::ClientResponse, response::ClientResponse,
@ -171,7 +171,7 @@ impl WebsocketsRequest {
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>, <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
match HeaderName::try_from(key) { match HeaderName::try_from(key) {
Ok(key) => match value.try_into_value() { Ok(key) => match value.try_into_value() {
@ -190,7 +190,7 @@ impl WebsocketsRequest {
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>, <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
match HeaderName::try_from(key) { match HeaderName::try_from(key) {
Ok(key) => match value.try_into_value() { Ok(key) => match value.try_into_value() {
@ -209,7 +209,7 @@ impl WebsocketsRequest {
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>, <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
match HeaderName::try_from(key) { match HeaderName::try_from(key) {
Ok(key) => { Ok(key) => {

View File

@ -2,7 +2,7 @@ use std::{cell::RefCell, fmt, io::Write as _};
use actix_http::{ use actix_http::{
body::BoxBody, body::BoxBody,
header::{self, IntoHeaderValue as _}, header::{self, TryIntoHeaderValue as _},
StatusCode, StatusCode,
}; };
use bytes::{BufMut as _, BytesMut}; use bytes::{BufMut as _, BytesMut};

View File

@ -8,7 +8,7 @@ use std::{
use actix_http::{ use actix_http::{
body::BoxBody, body::BoxBody,
header::{self, IntoHeaderValue}, header::{self, TryIntoHeaderValue},
Response, StatusCode, Response, StatusCode,
}; };
use bytes::BytesMut; use bytes::BytesMut;

View File

@ -14,7 +14,7 @@ use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use super::{ExtendedValue, Header, IntoHeaderValue, Writer}; use super::{ExtendedValue, Header, TryIntoHeaderValue, Writer};
use crate::http::header; use crate::http::header;
/// Split at the index of the first `needle` if it exists or at the end. /// Split at the index of the first `needle` if it exists or at the end.
@ -454,7 +454,7 @@ impl ContentDisposition {
} }
} }
impl IntoHeaderValue for ContentDisposition { impl TryIntoHeaderValue for ContentDisposition {
type Error = header::InvalidHeaderValue; type Error = header::InvalidHeaderValue;
fn try_into_value(self) -> Result<header::HeaderValue, Self::Error> { fn try_into_value(self) -> Result<header::HeaderValue, Self::Error> {

View File

@ -3,7 +3,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer, CONTENT_RANGE}; use super::{HeaderValue, InvalidHeaderValue, TryIntoHeaderValue, Writer, CONTENT_RANGE};
use crate::error::ParseError; use crate::error::ParseError;
crate::http::header::common_header! { crate::http::header::common_header! {
@ -196,7 +196,7 @@ impl Display for ContentRangeSpec {
} }
} }
impl IntoHeaderValue for ContentRangeSpec { impl TryIntoHeaderValue for ContentRangeSpec {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
fn try_into_value(self) -> Result<HeaderValue, Self::Error> { fn try_into_value(self) -> Result<HeaderValue, Self::Error> {

View File

@ -3,7 +3,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
use super::{HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer}; use super::{HeaderValue, InvalidHeaderValue, TryIntoHeaderValue, Writer};
/// check that each char in the slice is either: /// check that each char in the slice is either:
/// 1. `%x21`, or /// 1. `%x21`, or
@ -159,7 +159,7 @@ impl FromStr for EntityTag {
} }
} }
impl IntoHeaderValue for EntityTag { impl TryIntoHeaderValue for EntityTag {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
fn try_into_value(self) -> Result<HeaderValue, Self::Error> { fn try_into_value(self) -> Result<HeaderValue, Self::Error> {

View File

@ -1,8 +1,8 @@
use std::fmt::{self, Display, Write}; use std::fmt::{self, Display, Write};
use super::{ use super::{
from_one_raw_str, EntityTag, Header, HeaderName, HeaderValue, HttpDate, IntoHeaderValue, from_one_raw_str, EntityTag, Header, HeaderName, HeaderValue, HttpDate, InvalidHeaderValue,
InvalidHeaderValue, Writer, TryIntoHeaderValue, Writer,
}; };
use crate::error::ParseError; use crate::error::ParseError;
use crate::http::header; use crate::http::header;
@ -96,7 +96,7 @@ impl Display for IfRange {
} }
} }
impl IntoHeaderValue for IfRange { impl TryIntoHeaderValue for IfRange {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
fn try_into_value(self) -> Result<HeaderValue, Self::Error> { fn try_into_value(self) -> Result<HeaderValue, Self::Error> {

View File

@ -125,7 +125,7 @@ macro_rules! common_header {
} }
} }
impl $crate::http::header::IntoHeaderValue for $id { impl $crate::http::header::TryIntoHeaderValue for $id {
type Error = $crate::http::header::InvalidHeaderValue; type Error = $crate::http::header::InvalidHeaderValue;
#[inline] #[inline]
@ -172,7 +172,7 @@ macro_rules! common_header {
} }
} }
impl $crate::http::header::IntoHeaderValue for $id { impl $crate::http::header::TryIntoHeaderValue for $id {
type Error = $crate::http::header::InvalidHeaderValue; type Error = $crate::http::header::InvalidHeaderValue;
#[inline] #[inline]
@ -211,7 +211,7 @@ macro_rules! common_header {
} }
} }
impl $crate::http::header::IntoHeaderValue for $id { impl $crate::http::header::TryIntoHeaderValue for $id {
type Error = $crate::http::header::InvalidHeaderValue; type Error = $crate::http::header::InvalidHeaderValue;
#[inline] #[inline]
@ -266,7 +266,7 @@ macro_rules! common_header {
} }
} }
impl $crate::http::header::IntoHeaderValue for $id { impl $crate::http::header::TryIntoHeaderValue for $id {
type Error = $crate::http::header::InvalidHeaderValue; type Error = $crate::http::header::InvalidHeaderValue;
#[inline] #[inline]

View File

@ -6,7 +6,7 @@ use std::{
use actix_http::{error::ParseError, header, HttpMessage}; use actix_http::{error::ParseError, header, HttpMessage};
use super::{Header, HeaderName, HeaderValue, IntoHeaderValue, InvalidHeaderValue, Writer}; use super::{Header, HeaderName, HeaderValue, InvalidHeaderValue, TryIntoHeaderValue, Writer};
/// `Range` header, defined /// `Range` header, defined
/// in [RFC 7233 §3.1](https://datatracker.ietf.org/doc/html/rfc7233#section-3.1) /// in [RFC 7233 §3.1](https://datatracker.ietf.org/doc/html/rfc7233#section-3.1)
@ -274,7 +274,7 @@ impl Header for Range {
} }
} }
impl IntoHeaderValue for Range { impl TryIntoHeaderValue for Range {
type Error = InvalidHeaderValue; type Error = InvalidHeaderValue;
fn try_into_value(self) -> Result<HeaderValue, Self::Error> { fn try_into_value(self) -> Result<HeaderValue, Self::Error> {

View File

@ -75,7 +75,10 @@ impl DefaultHeaders {
} }
#[doc(hidden)] #[doc(hidden)]
#[deprecated(since = "4.0.0", note = "Prefer `add`.")] #[deprecated(
since = "4.0.0",
note = "Prefer `.add((key, value))`. Will be removed in v5."
)]
pub fn header<K, V>(self, key: K, value: V) -> Self pub fn header<K, V>(self, key: K, value: V) -> Self
where where
HeaderName: TryFrom<K>, HeaderName: TryFrom<K>,

View File

@ -9,7 +9,7 @@ use std::{
use actix_http::{ use actix_http::{
body::{BodyStream, BoxBody, MessageBody}, body::{BodyStream, BoxBody, MessageBody},
error::HttpError, error::HttpError,
header::{self, HeaderName, IntoHeaderValue, TryIntoHeaderPair}, header::{self, HeaderName, TryIntoHeaderPair, TryIntoHeaderValue},
ConnectionType, Extensions, Response, ResponseHead, StatusCode, ConnectionType, Extensions, Response, ResponseHead, StatusCode,
}; };
use bytes::Bytes; use bytes::Bytes;
@ -112,7 +112,7 @@ impl HttpResponseBuilder {
where where
K: TryInto<HeaderName>, K: TryInto<HeaderName>,
K::Error: Into<HttpError>, K::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
if self.err.is_some() { if self.err.is_some() {
return self; return self;
@ -137,7 +137,7 @@ impl HttpResponseBuilder {
where where
K: TryInto<HeaderName>, K: TryInto<HeaderName>,
K::Error: Into<HttpError>, K::Error: Into<HttpError>,
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
if self.err.is_some() { if self.err.is_some() {
return self; return self;
@ -174,7 +174,7 @@ impl HttpResponseBuilder {
#[inline] #[inline]
pub fn upgrade<V>(&mut self, value: V) -> &mut Self pub fn upgrade<V>(&mut self, value: V) -> &mut Self
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
if let Some(parts) = self.inner() { if let Some(parts) = self.inner() {
parts.set_connection_type(ConnectionType::Upgrade); parts.set_connection_type(ConnectionType::Upgrade);
@ -212,7 +212,7 @@ impl HttpResponseBuilder {
#[inline] #[inline]
pub fn content_type<V>(&mut self, value: V) -> &mut Self pub fn content_type<V>(&mut self, value: V) -> &mut Self
where where
V: IntoHeaderValue, V: TryIntoHeaderValue,
{ {
if let Some(parts) = self.inner() { if let Some(parts) = self.inner() {
match value.try_into_value() { match value.try_into_value() {

View File

@ -48,7 +48,7 @@ pub trait Responder {
} }
#[doc(hidden)] #[doc(hidden)]
#[deprecated(since = "4.0.0", note = "Prefer `.customize().insert_header()`.")] #[deprecated(since = "4.0.0", note = "Prefer `.customize().insert_header(header)`.")]
fn with_header(self, header: impl TryIntoHeaderPair) -> CustomizeResponder<Self> fn with_header(self, header: impl TryIntoHeaderPair) -> CustomizeResponder<Self>
where where
Self: Sized, Self: Sized,