pub fn escape_controls(body: &str, max: usize) -> StringExpand description
Truncates a backend response body and escapes its control characters so it is safe to show in a diagnostic.
The function keeps the first max characters of body. It replaces each
control character among them, including newlines and carriage returns, with
its escaped form, such as \n or \u{1b}. Escaping can make the result
longer than max characters. An empty body returns the fixed marker
(empty body).
The escaping stops a backend body from forging log lines or slipping terminal control sequences into a diagnostic.
A transport passes the error body of a response with a failure status
through this function before it hands the body to
classify_http_failure. Every transport
therefore truncates and escapes a backend body by the same rule.