Browse Source

Remove superfluous characters in JSON

In some situations, it has been found that a specific ACME server
returns extra characters before and after the JSON, which is therefore
invalid. Although this must be fixed in the server, ACMEd should
gracefully ignore such erroneous characters instead of refusing the
response.
pull/19/head
Rodolphe Breard 5 years ago
parent
commit
9a436fc35f
  1. 12
      acmed/src/acme_proto/http.rs

12
acmed/src/acme_proto/http.rs

@ -123,6 +123,18 @@ fn post_jose_type(
let rstr = String::from_utf8_lossy(data);
cert.trace(&format!("request body: {}", rstr));
let (res, res_body) = send_request(cert, &request)?;
let lpos = res_body.find("{").unwrap_or(0);
let res_body = if lpos == 0 {
res_body
} else {
res_body.chars().skip(lpos).collect::<String>()
};
let rpos = res_body.rfind("}").unwrap_or(0);
let res_body = if rpos == 0 {
res_body
} else {
res_body.chars().take(rpos + 1).collect::<String>()
};
cert.trace(&format!("response body: {}", res_body));
Ok((res, res_body))
}

Loading…
Cancel
Save