The Content-Length header declares a response body's size in bytes. When a response body is provided without chunked encoding, set the status and length before sending the headers. section 4.6
let headers = &mut request.headers_out; #1
headers.status = status_code;
let response_bytes = response_body.as_bytes(); #2
headers.content_length_n = response_bytes.len() as off_t; #3
let rc = ngx_http_send_header(request);
if rc != 0 {
return Err("failed to send headers");
}
Convert the response string to bytes, count them with len(), cast the count to NGINX's offset type, and send the headers. section 4.6
Setting the response length
For response_body, obtain response_body.as_bytes(), assign response_bytes.len() as off_t to headers.content_length_n, then call ngx_http_send_header(request). section 4.6
