liveBook · Manning

Payload

As explained in Rust Servers, Services, and Apps

An HTTP message body is the optional content payload carried after an HTTP message's headers.

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

How Rust Servers, Services, and Apps covers it

How deep it goes
Shows request-body storage and response-body serialization, without detailing body-content processing.
Examples
Uses an order-shipping status string as a response body in construction and serialization tests.
What you can do after
Build and test Rust structures that store request bodies and serialize response bodies.
How it connects
Connects HTTP message bodies with headers, request parsing, response serialization, and Content-Length.

Also explained in

Compare how 8 books explain payload →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.