From f4fc20921a9549b8d8fb4e7f86f08636e4871ce7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 11 Oct 2020 13:14:04 +0200 Subject: [PATCH] Mark response headers optional in media GET endpoints --- ruma-client-api/src/r0/media/create_content.rs | 9 ++++----- ruma-client-api/src/r0/media/get_content.rs | 10 +++++----- .../src/r0/media/get_content_as_filename.rs | 11 ++++++----- ruma-client-api/src/r0/media/get_content_thumbnail.rs | 8 ++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ruma-client-api/src/r0/media/create_content.rs b/ruma-client-api/src/r0/media/create_content.rs index f519c710..9916b49f 100644 --- a/ruma-client-api/src/r0/media/create_content.rs +++ b/ruma-client-api/src/r0/media/create_content.rs @@ -19,9 +19,8 @@ ruma_api! { pub filename: Option<&'a str>, /// The content type of the file being uploaded. - // TODO: This should be optional. #[ruma_api(header = CONTENT_TYPE)] - pub content_type: &'a str, + pub content_type: Option<&'a str>, /// The file contents to upload. #[ruma_api(raw_body)] @@ -37,9 +36,9 @@ ruma_api! { } impl<'a> Request<'a> { - /// Creates a new `Request` with the given content type and file contents. - pub fn new(content_type: &'a str, file: Vec) -> Self { - Self { filename: None, content_type, file } + /// Creates a new `Request` with the given file contents. + pub fn new(file: Vec) -> Self { + Self { file, filename: None, content_type: None } } } diff --git a/ruma-client-api/src/r0/media/get_content.rs b/ruma-client-api/src/r0/media/get_content.rs index 742df560..7ab4cccf 100644 --- a/ruma-client-api/src/r0/media/get_content.rs +++ b/ruma-client-api/src/r0/media/get_content.rs @@ -37,11 +37,11 @@ ruma_api! { /// The content type of the file that was previously uploaded. #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, + pub content_type: Option, /// The name of the file that was previously uploaded, if set. #[ruma_api(header = CONTENT_DISPOSITION)] - pub content_disposition: String, + pub content_disposition: Option, } error: crate::Error @@ -55,8 +55,8 @@ impl<'a> Request<'a> { } impl Response { - /// Creates a new `Response` with the given file contents, content type and filename. - pub fn new(file: Vec, content_type: String, content_disposition: String) -> Self { - Self { file, content_type, content_disposition } + /// Creates a new `Response` with the given file contents. + pub fn new(file: Vec) -> Self { + Self { file, content_type: None, content_disposition: None } } } diff --git a/ruma-client-api/src/r0/media/get_content_as_filename.rs b/ruma-client-api/src/r0/media/get_content_as_filename.rs index b14aa9f5..51f72a39 100644 --- a/ruma-client-api/src/r0/media/get_content_as_filename.rs +++ b/ruma-client-api/src/r0/media/get_content_as_filename.rs @@ -41,11 +41,12 @@ ruma_api! { /// The content type of the file that was previously uploaded. #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, + // Potentially not actually optional – https://github.com/matrix-org/matrix-doc/pull/2818 + pub content_type: Option, /// The name of the file that was previously uploaded, if set. #[ruma_api(header = CONTENT_DISPOSITION)] - pub content_disposition: String, + pub content_disposition: Option, } error: crate::Error @@ -59,8 +60,8 @@ impl<'a> Request<'a> { } impl Response { - /// Creates a new `Response` with the given file, content type and filename. - pub fn new(file: Vec, content_type: String, content_disposition: String) -> Self { - Self { file, content_type, content_disposition } + /// Creates a new `Response` with the given file. + pub fn new(file: Vec) -> Self { + Self { file, content_type: None, content_disposition: None } } } diff --git a/ruma-client-api/src/r0/media/get_content_thumbnail.rs b/ruma-client-api/src/r0/media/get_content_thumbnail.rs index 0738951e..7a654911 100644 --- a/ruma-client-api/src/r0/media/get_content_thumbnail.rs +++ b/ruma-client-api/src/r0/media/get_content_thumbnail.rs @@ -61,7 +61,7 @@ ruma_api! { response: { /// The content type of the thumbnail. #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, + pub content_type: Option, /// A thumbnail of the requested content. #[ruma_api(raw_body)] @@ -80,8 +80,8 @@ impl<'a> Request<'a> { } impl Response { - /// Creates a new `Response` with the given content type and thumbnail. - pub fn new(content_type: String, file: Vec) -> Self { - Self { content_type, file } + /// Creates a new `Response` with the given thumbnail. + pub fn new(file: Vec) -> Self { + Self { file, content_type: None } } }