Skip to content

Commit

Permalink
Ignore invalid content type header values (#2326)
Browse files Browse the repository at this point in the history
Fixes #2322.
  • Loading branch information
casey authored Aug 13, 2023
1 parent 13c7592 commit f3a5182
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f3a5182

Please sign in to comment.