add missing corp/cache-control headers to authenticated media

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-08-12 23:03:07 +00:00
parent fd11fee88d
commit 9d25b0d5c2
3 changed files with 78 additions and 7 deletions

View File

@ -9,12 +9,14 @@ pub mod v1 {
use std::{borrow::Cow, time::Duration};
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY;
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: true,
@ -68,6 +70,22 @@ 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>>,
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
///
/// See [MDN] for the syntax.
///
/// [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>>,
/// The value of the `Cache-Control` HTTP header.
///
/// See [MDN] for the syntax.
///
/// [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>>,
}
impl Request {
@ -87,7 +105,13 @@ pub mod v1 {
impl Response {
/// Creates a new `Response` with the given file contents.
pub fn new(file: Vec<u8>) -> Self {
Self { file, content_type: None, content_disposition: None }
Self {
file,
content_type: None,
content_disposition: None,
cross_origin_resource_policy: None,
cache_control: None,
}
}
}
}

View File

@ -9,12 +9,14 @@ pub mod v1 {
use std::{borrow::Cow, time::Duration};
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use http::header::{CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY;
const METADATA: Metadata = metadata! {
method: GET,
rate_limited: true,
@ -72,6 +74,22 @@ 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>>,
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
///
/// See [MDN] for the syntax.
///
/// [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>>,
/// The value of the `Cache-Control` HTTP header.
///
/// See [MDN] for the syntax.
///
/// [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>>,
}
impl Request {
@ -96,7 +114,13 @@ pub mod v1 {
impl Response {
/// Creates a new `Response` with the given file.
pub fn new(file: Vec<u8>) -> Self {
Self { file, content_type: None, content_disposition: None }
Self {
file,
content_type: None,
content_disposition: None,
cross_origin_resource_policy: None,
cache_control: None,
}
}
}
}

View File

@ -9,14 +9,16 @@ pub mod v1 {
use std::{borrow::Cow, time::Duration};
use http::header::CONTENT_TYPE;
use http::header::{CACHE_CONTROL, CONTENT_TYPE};
use js_int::UInt;
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
};
use crate::media::get_content_thumbnail::v3::Method;
use crate::{
http_headers::CROSS_ORIGIN_RESOURCE_POLICY, media::get_content_thumbnail::v3::Method,
};
const METADATA: Metadata = metadata! {
method: GET,
@ -88,6 +90,22 @@ pub mod v1 {
/// The content type of the thumbnail.
#[ruma_api(header = CONTENT_TYPE)]
pub content_type: Option<Cow<'static, str>>,
/// The value of the `Cross-Origin-Resource-Policy` HTTP header.
///
/// See [MDN] for the syntax.
///
/// [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>>,
/// The value of the `Cache-Control` HTTP header.
///
/// See [MDN] for the syntax.
///
/// [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>>,
}
impl Request {
@ -122,7 +140,12 @@ pub mod v1 {
impl Response {
/// Creates a new `Response` with the given thumbnail.
pub fn new(file: Vec<u8>) -> Self {
Self { file, content_type: None }
Self {
file,
content_type: None,
cross_origin_resource_policy: None,
cache_control: None,
}
}
}
}