server: add Content-Length header to response

This commit is contained in:
Peter Cai 2021-04-06 08:11:23 +08:00
parent 94ce9142b2
commit 74719956c1
1 changed files with 4 additions and 1 deletions

View File

@ -89,7 +89,7 @@ impl Server {
let mut resp_body = err_response!(match &resp_format {
&DnsResponseFormat::WireFormat =>
Self::build_answer_wireformat(query_id, questions, records)
.map(|x| x.as_slice().to_owned()),
.map(|x| x.into_octets()),
&DnsResponseFormat::JsonFormat => Err("JSON is not supported yet".to_string()),
});
let resp_content_type = match resp_format {
@ -103,6 +103,9 @@ impl Server {
err_response!(resp_headers
.append("Content-Type", resp_content_type)
.map_err(|_| "Could not create headers".to_string()));
err_response!(resp_headers
.append("Content-Length", &resp_body.len().to_string())
.map_err(|_| "Could not create headers".to_string()));
let mut resp_init = ResponseInit::new();
resp_init.status(200).headers(&resp_headers);
return Response::new_with_opt_u8_array_and_init(Some(&mut resp_body), &resp_init).unwrap();