optimize for optional static response headers zero-copy zero-alloc
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
a6e340e24d
commit
fd11fee88d
@ -7,7 +7,7 @@ pub mod v1 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediadownloadservernamemediaid
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediadownloadservernamemediaid
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{borrow::Cow, time::Duration};
|
||||||
|
|
||||||
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
|
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -58,7 +58,7 @@ pub mod v1 {
|
|||||||
|
|
||||||
/// The content type of the file that was previously uploaded.
|
/// The content type of the file that was previously uploaded.
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||||
/// file that was previously uploaded.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: Option<String>,
|
pub content_disposition: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
@ -7,7 +7,7 @@ pub mod v1 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediadownloadservernamemediaidfilename
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediadownloadservernamemediaidfilename
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{borrow::Cow, time::Duration};
|
||||||
|
|
||||||
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
|
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -62,7 +62,7 @@ pub mod v1 {
|
|||||||
|
|
||||||
/// The content type of the file that was previously uploaded.
|
/// The content type of the file that was previously uploaded.
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||||
/// file that was previously uploaded.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: Option<String>,
|
pub content_disposition: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
@ -7,7 +7,7 @@ pub mod v1 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediathumbnailservernamemediaid
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv1mediathumbnailservernamemediaid
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{borrow::Cow, time::Duration};
|
||||||
|
|
||||||
use http::header::CONTENT_TYPE;
|
use http::header::CONTENT_TYPE;
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
@ -87,7 +87,7 @@ pub mod v1 {
|
|||||||
|
|
||||||
/// The content type of the thumbnail.
|
/// The content type of the thumbnail.
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaid
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaid
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{borrow::Cow, time::Duration};
|
||||||
|
|
||||||
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
|
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -83,7 +83,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
/// The content type of the file that was previously uploaded.
|
/// The content type of the file that was previously uploaded.
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||||
/// file that was previously uploaded.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: Option<String>,
|
pub content_disposition: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
|
||||||
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
|
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
|
||||||
pub cross_origin_resource_policy: Option<String>,
|
pub cross_origin_resource_policy: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Cache-Control` HTTP header.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#syntax
|
||||||
#[ruma_api(header = CACHE_CONTROL)]
|
#[ruma_api(header = CACHE_CONTROL)]
|
||||||
pub cache_control: Option<String>,
|
pub cache_control: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
@ -141,7 +141,7 @@ pub mod v3 {
|
|||||||
file,
|
file,
|
||||||
content_type: None,
|
content_type: None,
|
||||||
content_disposition: None,
|
content_disposition: None,
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".into()),
|
||||||
cache_control: None,
|
cache_control: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{borrow::Cow, time::Duration};
|
||||||
|
|
||||||
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
|
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -87,7 +87,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
/// The content type of the file that was previously uploaded.
|
/// The content type of the file that was previously uploaded.
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||||
/// file that was previously uploaded.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: Option<String>,
|
pub content_disposition: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
|
||||||
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
|
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
|
||||||
pub cross_origin_resource_policy: Option<String>,
|
pub cross_origin_resource_policy: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Cache-Control` HTTP header.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#syntax
|
||||||
#[ruma_api(header = CACHE_CONTROL)]
|
#[ruma_api(header = CACHE_CONTROL)]
|
||||||
pub cache_control: Option<String>,
|
pub cache_control: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
@ -146,7 +146,7 @@ pub mod v3 {
|
|||||||
file,
|
file,
|
||||||
content_type: None,
|
content_type: None,
|
||||||
content_disposition: None,
|
content_disposition: None,
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".into()),
|
||||||
cache_control: None,
|
cache_control: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3thumbnailservernamemediaid
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3thumbnailservernamemediaid
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::{borrow::Cow, time::Duration};
|
||||||
|
|
||||||
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
|
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
@ -112,7 +112,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
/// The content type of the thumbnail.
|
/// The content type of the thumbnail.
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub content_type: Option<String>,
|
pub content_type: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax
|
||||||
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
|
#[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)]
|
||||||
pub cross_origin_resource_policy: Option<String>,
|
pub cross_origin_resource_policy: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Cache-Control` HTTP header.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#syntax
|
||||||
#[ruma_api(header = CACHE_CONTROL)]
|
#[ruma_api(header = CACHE_CONTROL)]
|
||||||
pub cache_control: Option<String>,
|
pub cache_control: Option<Cow<'static, str>>,
|
||||||
|
|
||||||
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
/// The value of the `Content-Disposition` HTTP header, possibly containing the name of the
|
||||||
/// file that was previously uploaded.
|
/// 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
|
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: Option<String>,
|
pub content_disposition: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
@ -180,7 +180,7 @@ pub mod v3 {
|
|||||||
Self {
|
Self {
|
||||||
file,
|
file,
|
||||||
content_type: None,
|
content_type: None,
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".into()),
|
||||||
cache_control: None,
|
cache_control: None,
|
||||||
content_disposition: None,
|
content_disposition: None,
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ pub mod v3 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3loginssoredirect
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3loginssoredirect
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use http::header::{LOCATION, SET_COOKIE};
|
use http::header::{LOCATION, SET_COOKIE};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::{request, response, Metadata},
|
api::{request, response, Metadata},
|
||||||
@ -40,7 +42,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
/// Cookie storing state to secure the SSO process.
|
/// Cookie storing state to secure the SSO process.
|
||||||
#[ruma_api(header = SET_COOKIE)]
|
#[ruma_api(header = SET_COOKIE)]
|
||||||
pub cookie: Option<String>,
|
pub cookie: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
@ -7,6 +7,8 @@ pub mod v3 {
|
|||||||
//!
|
//!
|
||||||
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3loginssoredirectidpid
|
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3loginssoredirectidpid
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use http::header::{LOCATION, SET_COOKIE};
|
use http::header::{LOCATION, SET_COOKIE};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::{request, response, Metadata},
|
api::{request, response, Metadata},
|
||||||
@ -46,7 +48,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
/// Cookie storing state to secure the SSO process.
|
/// Cookie storing state to secure the SSO process.
|
||||||
#[ruma_api(header = SET_COOKIE)]
|
#[ruma_api(header = SET_COOKIE)]
|
||||||
pub cookie: Option<String>,
|
pub cookie: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
@ -23,10 +23,16 @@ impl Response {
|
|||||||
if segments.last().unwrap().ident == "Option" =>
|
if segments.last().unwrap().ident == "Option" =>
|
||||||
{
|
{
|
||||||
quote! {
|
quote! {
|
||||||
if let Some(header) = self.#field_name {
|
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)?,
|
||||||
|
};
|
||||||
headers.insert(
|
headers.insert(
|
||||||
#header_name,
|
#header_name,
|
||||||
header.parse()?,
|
header,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user