diff --git a/crates/ruma-common/tests/it/api/required_headers.rs b/crates/ruma-common/tests/it/api/required_headers.rs index 1d8576d6..e813399f 100644 --- a/crates/ruma-common/tests/it/api/required_headers.rs +++ b/crates/ruma-common/tests/it/api/required_headers.rs @@ -28,7 +28,7 @@ pub struct Request { #[ruma_api(header = LOCATION)] pub location: String, #[ruma_api(header = CONTENT_DISPOSITION)] - pub content_disposition: ContentDisposition, + pub content_disposition: Option, } /// Response type for the `required_headers` endpoint. @@ -37,7 +37,7 @@ pub struct Response { #[ruma_api(header = LOCATION)] pub stuff: String, #[ruma_api(header = CONTENT_DISPOSITION)] - pub content_disposition: ContentDisposition, + pub content_disposition: Option, } #[test] @@ -45,8 +45,10 @@ fn request_serde() { let location = "https://other.tld/page/"; let content_disposition = ContentDisposition::new(ContentDispositionType::Attachment) .with_filename(Some("my_file".to_owned())); - let req = - Request { location: location.to_owned(), content_disposition: content_disposition.clone() }; + let req = Request { + location: location.to_owned(), + content_disposition: Some(content_disposition.clone()), + }; let mut http_req = req .clone() @@ -61,7 +63,7 @@ fn request_serde() { let req2 = Request::try_from_http_request::<_, &str>(http_req.clone(), &[]).unwrap(); assert_eq!(req2.location, location); - assert_eq!(req2.content_disposition, content_disposition); + assert_eq!(req2.content_disposition, Some(content_disposition)); // Try removing the headers. http_req.headers_mut().remove(LOCATION).unwrap(); @@ -93,8 +95,10 @@ fn response_serde() { let location = "https://other.tld/page/"; let content_disposition = ContentDisposition::new(ContentDispositionType::Attachment) .with_filename(Some("my_file".to_owned())); - let res = - Response { stuff: location.to_owned(), content_disposition: content_disposition.clone() }; + let res = Response { + stuff: location.to_owned(), + content_disposition: Some(content_disposition.clone()), + }; let mut http_res = res.clone().try_into_http_response::>().unwrap(); assert_matches!(http_res.headers().get(LOCATION), Some(_)); @@ -102,7 +106,7 @@ fn response_serde() { let res2 = Response::try_from_http_response(http_res.clone()).unwrap(); assert_eq!(res2.stuff, location); - assert_eq!(res2.content_disposition, content_disposition); + assert_eq!(res2.content_disposition, Some(content_disposition)); // Try removing the headers. http_res.headers_mut().remove(LOCATION).unwrap(); diff --git a/crates/ruma-federation-api/src/authenticated_media.rs b/crates/ruma-federation-api/src/authenticated_media.rs index f19e9f57..3d0c45de 100644 --- a/crates/ruma-federation-api/src/authenticated_media.rs +++ b/crates/ruma-federation-api/src/authenticated_media.rs @@ -313,7 +313,7 @@ mod tests { let outgoing_metadata = ContentMetadata::new(); let outgoing_content = FileOrLocation::File(Content { file: file.to_vec(), - content_type: Some(content_type.to_owned()), + content_type: Some(content_type.into()), content_disposition: Some(content_disposition.clone()), }); @@ -340,7 +340,7 @@ mod tests { let outgoing_metadata = ContentMetadata::new(); let outgoing_content = FileOrLocation::File(Content { file: file.to_vec(), - content_type: Some(content_type.to_owned()), + content_type: Some(content_type.into()), content_disposition: Some(content_disposition.clone()), }); diff --git a/crates/ruma-macros/src/api/response/incoming.rs b/crates/ruma-macros/src/api/response/incoming.rs index e960215a..75699ef8 100644 --- a/crates/ruma-macros/src/api/response/incoming.rs +++ b/crates/ruma-macros/src/api/response/incoming.rs @@ -64,7 +64,7 @@ impl Response { let syn::GenericArgument::Type(field_type) = option_args.first().unwrap() else { panic!("Option brackets should contain type"); }; - let syn::Type::Path(syn::TypePath { path: syn::Path { segments, .. }, .. }) = field_type else { + let Type::Path(syn::TypePath { path: syn::Path { segments, .. }, .. }) = field_type else { panic!("Option type should have a path") }; let ident = &segments.last().expect("Option type should have path segments").ident;