diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 8b1b1476b8..59d46286cf 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -815,9 +815,8 @@ impl Server { header::CONTENT_TYPE, inscription .content_type() - .unwrap_or("application/octet-stream") - .parse() - .unwrap(), + .and_then(|content_type| content_type.parse().ok()) + .unwrap_or(HeaderValue::from_static("application/octet-stream")), ); headers.insert( header::CONTENT_SECURITY_POLICY, @@ -2201,6 +2200,18 @@ mod tests { assert!(body.is_empty()); } + #[test] + fn content_response_bad_content_type() { + let (headers, body) = Server::content_response(Inscription::new( + Some("\n".as_bytes().to_vec()), + Some(Vec::new()), + )) + .unwrap(); + + assert_eq!(headers["content-type"], "application/octet-stream"); + assert!(body.is_empty()); + } + #[test] fn text_preview() { let server = TestServer::new_with_regtest();