Skip to content

Commit e2a2f89

Browse files
authored
fix(rust/signed-doc): Content type (#197)
* fix(sign-doc): content type Signed-off-by: bkioshn <[email protected]> * test(signed-doc): content type string Signed-off-by: bkioshn <[email protected]> --------- Signed-off-by: bkioshn <[email protected]>
1 parent 7080c53 commit e2a2f89

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

rust/signed_doc/src/metadata/content_type.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ impl ContentType {
4040
impl Display for ContentType {
4141
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
4242
match self {
43-
Self::Cbor => write!(f, "cbor"),
44-
Self::Json => write!(f, "json"),
43+
Self::Cbor => write!(f, "application/cbor"),
44+
Self::Json => write!(f, "application/json"),
4545
}
4646
}
4747
}
@@ -51,8 +51,8 @@ impl FromStr for ContentType {
5151

5252
fn from_str(s: &str) -> Result<Self, Self::Err> {
5353
match s {
54-
"cbor" => Ok(Self::Cbor),
55-
"json" => Ok(Self::Json),
54+
"application/cbor" => Ok(Self::Cbor),
55+
"application/json" => Ok(Self::Json),
5656
_ => {
5757
anyhow::bail!(
5858
"Unsupported Content Type: {s:?}, Supported only: {:?}",
@@ -112,4 +112,24 @@ mod tests {
112112
assert!(ContentType::Json.validate(&cbor_bytes).is_err());
113113
assert!(ContentType::Cbor.validate(&cbor_bytes).is_ok());
114114
}
115+
116+
#[test]
117+
fn content_type_string_test() {
118+
assert_eq!(
119+
ContentType::from_str("application/cbor").unwrap(),
120+
ContentType::Cbor
121+
);
122+
assert_eq!(
123+
ContentType::from_str("application/json").unwrap(),
124+
ContentType::Json
125+
);
126+
assert_eq!(
127+
"application/cbor".parse::<ContentType>().unwrap(),
128+
ContentType::Cbor
129+
);
130+
assert_eq!(
131+
"application/json".parse::<ContentType>().unwrap(),
132+
ContentType::Json
133+
);
134+
}
115135
}

0 commit comments

Comments
 (0)