An HTTP message body is optional content carried after the headers. A request parser stores a present body as a string; an HTTP response represents its body as an optional string. section 2.3.1 section 2.3.2
The body has a role in each direction:
- In a request, it follows the header separator and is stored in the HttpRequest structure. section 2.3.1
- In a response, it follows the serialized headers and Content-Length; the body may be absent. section 2.3.2
Listing 2.6 Data structures for the HTTP request
use std::collections::HashMap;
#[derive(Debug, PartialEq)]
pub enum Resource {
Path(String),
}
#[derive(Debug)]
pub struct HttpRequest {
pub method: Method,
pub version: Version,
pub resource: Resource,
pub headers: HashMap<String, String>,
pub msg_body: String,
}
The request structure represents its body with the msg_body string field. section 2.3.1
Response body
A response test uses “Item was shipped on 21st Dec 2020” as its body and checks that serialization places it after the headers and blank line. section 2.3.2







