Accept charset=* in Content-Type for masterserver

You should generally not send a `charset=*` parameter for `Content-Type:
application/json` because no parameters are defined for it:
https://datatracker.ietf.org/doc/html/rfc7158#section-11.

Fixes #6955.
This commit is contained in:
heinrich5991 2024-01-31 20:34:21 +01:00
parent 349eb38ebf
commit 1d638707b2
3 changed files with 5 additions and 2 deletions

View file

@ -443,6 +443,7 @@ dependencies = [
"hex",
"ipnet",
"log",
"mime",
"rand",
"serde",
"serde_json",

View file

@ -22,6 +22,7 @@ headers = "0.3.7"
hex = "0.4.3"
ipnet = { version = "2.5.0", features = ["serde"] }
log = "0.4.17"
mime = "0.3.16"
rand = "0.8.4"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = { version = "1.0.64", features = [

View file

@ -823,8 +823,9 @@ fn register_from_headers(
challenge_token: parse_opt(headers, "Challenge-Token")?,
info_serial: parse(headers, "Info-Serial")?,
info: if !info.is_empty() {
if headers.typed_get() != Some(headers::ContentType::json()) {
return Err(RegisterError::unsupported_media_type());
match headers.typed_get::<headers::ContentType>().map(mime::Mime::from) {
Some(mime) if mime.essence_str() == mime::APPLICATION_JSON => {}
_ => return Err(RegisterError::unsupported_media_type()),
}
Some(json::from_slice(info).map_err(|e| {
RegisterError::new(format!("Request body deserialize error: {}", e))