Revert "optimize for optional static response headers zero-copy zero-alloc"

This reverts commit fd11fee88d937d69f557fa3d6ef09639c7b2e2f7.
This commit is contained in:
strawberry 2024-08-14 01:46:35 -04:00
parent 959048c0c4
commit 6bdc5ad326
9 changed files with 30 additions and 40 deletions

View File

@ -7,7 +7,7 @@ pub mod v1 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediadownloadservernamemediaid
use std::{borrow::Cow, time::Duration};
use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
@ -58,7 +58,7 @@ pub mod v1 {
/// The content type of the file that was previously uploaded.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
pub content_type: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
@ -67,7 +67,7 @@ pub mod v1 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<Cow<'static, str>>,
pub content_disposition: Option<String>,
}
impl Request {

View File

@ -7,7 +7,7 @@ pub mod v1 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediadownloadservernamemediaidfilename
use std::{borrow::Cow, time::Duration};
use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
@ -62,7 +62,7 @@ pub mod v1 {
/// The content type of the file that was previously uploaded.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
pub content_type: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
@ -71,7 +71,7 @@ pub mod v1 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<Cow<'static, str>>,
pub content_disposition: Option<String>,
}
impl Request {

View File

@ -7,7 +7,7 @@ pub mod v1 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediathumbnailservernamemediaid
use std::{borrow::Cow, time::Duration};
use std::time::Duration;
use http::header::CONTENT_TYPE;
use js_int::UInt;
@ -87,7 +87,7 @@ pub mod v1 {
/// The content type of the thumbnail.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
pub content_type: Option<String>,
}
impl Request {

View File

@ -7,7 +7,7 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaid
use std::{borrow::Cow, time::Duration};
use std::time::Duration;
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
@ -83,7 +83,7 @@ pub mod v3 {
/// The content type of the file that was previously uploaded.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
pub content_type: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
@ -92,7 +92,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<Cow<'static, str>>,
pub content_disposition: Option<String>,
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
///
@ -100,7 +100,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
pub cross_origin_resource_policy: Option<Cow<'static, str>>,
pub cross_origin_resource_policy: Option<String>,
/// The value of the `Cache-Control` HTTP header.
///
@ -108,7 +108,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#syntax
#[ruma_api(header = CACHE_CONTROL)]
pub cache_control: Option<Cow<'static, str>>,
pub cache_control: Option<String>,
}
#[allow(deprecated)]
@ -141,7 +141,7 @@ pub mod v3 {
file,
content_type: None,
content_disposition: None,
cross_origin_resource_policy: Some("cross-origin".into()),
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cache_control: None,
}
}

View File

@ -7,7 +7,7 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename
use std::{borrow::Cow, time::Duration};
use std::time::Duration;
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
@ -87,7 +87,7 @@ pub mod v3 {
/// The content type of the file that was previously uploaded.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
pub content_type: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
@ -96,7 +96,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<Cow<'static, str>>,
pub content_disposition: Option<String>,
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
///
@ -104,7 +104,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
pub cross_origin_resource_policy: Option<Cow<'static, str>>,
pub cross_origin_resource_policy: Option<String>,
/// The value of the `Cache-Control` HTTP header.
///
@ -112,7 +112,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#syntax
#[ruma_api(header = CACHE_CONTROL)]
pub cache_control: Option<Cow<'static, str>>,
pub cache_control: Option<String>,
}
#[allow(deprecated)]
@ -146,7 +146,7 @@ pub mod v3 {
file,
content_type: None,
content_disposition: None,
cross_origin_resource_policy: Some("cross-origin".into()),
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cache_control: None,
}
}

View File

@ -7,7 +7,7 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3thumbnailservernamemediaid
use std::{borrow::Cow, time::Duration};
use std::time::Duration;
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
use js_int::UInt;
@ -112,7 +112,7 @@ pub mod v3 {
/// The content type of the thumbnail.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
pub content_type: Option<String>,
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
///
@ -120,7 +120,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
pub cross_origin_resource_policy: Option<Cow<'static, str>>,
pub cross_origin_resource_policy: Option<String>,
/// The value of the `Cache-Control` HTTP header.
///
@ -128,7 +128,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#syntax
#[ruma_api(header = CACHE_CONTROL)]
pub cache_control: Option<Cow<'static, str>>,
pub cache_control: Option<String>,
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
/// file that was previously uploaded.
@ -137,7 +137,7 @@ pub mod v3 {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
#[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: Option<Cow<'static, str>>,
pub content_disposition: Option<String>,
}
#[allow(deprecated)]
@ -180,7 +180,7 @@ pub mod v3 {
Self {
file,
content_type: None,
cross_origin_resource_policy: Some("cross-origin".into()),
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cache_control: None,
content_disposition: None,
}

View File

@ -5,8 +5,6 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3loginssoredirect
use std::borrow::Cow;
use http::header::{LOCATION, SET_COOKIE};
use ruma_common::{
api::{request, response, Metadata},
@ -42,7 +40,7 @@ pub mod v3 {
/// Cookie storing state to secure the SSO process.
#[ruma_api(header = SET_COOKIE)]
pub cookie: Option<Cow<'static, str>>,
pub cookie: Option<String>,
}
impl Request {

View File

@ -7,8 +7,6 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3loginssoredirectidpid
use std::borrow::Cow;
use http::header::{LOCATION, SET_COOKIE};
use ruma_common::{
api::{request, response, Metadata},
@ -48,7 +46,7 @@ pub mod v3 {
/// Cookie storing state to secure the SSO process.
#[ruma_api(header = SET_COOKIE)]
pub cookie: Option<Cow<'static, str>>,
pub cookie: Option<String>,
}
impl Request {

View File

@ -19,16 +19,10 @@ impl Response {
if segments.last().unwrap().ident == "Option" =>
{
quote! {
if let Some(ref header) = self.#field_name {
let header = match header {
::std::borrow::Cow::Borrowed(ref header) =>
#http::header::HeaderValue::from_static(header),
::std::borrow::Cow::Owned(ref header) =>
#http::header::HeaderValue::from_str(&header)?,
};
if let Some(header) = self.#field_name {
headers.insert(
#header_name,
header,
header.parse()?,
);
}
}