Function
http_response_with_headers
(
status: &str,
content_type: &str,
body: &str,
headers: &[(&str, &str)],
)
Source from the content-addressed store, hash-verified
| 392 | } |
| 393 | |
| 394 | fn http_response_with_headers( |
| 395 | status: &str, |
| 396 | content_type: &str, |
| 397 | body: &str, |
| 398 | headers: &[(&str, &str)], |
| 399 | ) -> String { |
| 400 | let mut extra_headers = String::new(); |
| 401 | for (name, value) in headers { |
| 402 | use std::fmt::Write as _; |
| 403 | write!(&mut extra_headers, "{name}: {value}\r\n").expect("header write should succeed"); |
| 404 | } |
| 405 | format!( |
| 406 | "HTTP/1.1 {status}\r\ncontent-type: {content_type}\r\n{extra_headers}content-length: {}\r\nconnection: close\r\n\r\n{body}", |
| 407 | body.len() |
| 408 | ) |
| 409 | } |
| 410 | |
| 411 | fn sample_request(stream: bool) -> MessageRequest { |
| 412 | MessageRequest { |
Tested by
no test coverage detected