expression
Content-Type versus Accept
Content-Type describes the representation actually supplied. Accept expresses a recipient’s media-type preferences. A request may contain both; neither header automatically validates or transforms bytes. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): text/plain application/json Common mistake: Assuming Accept changes the format of the request body.
Formal Syntax & Structure
rust syntaxrust
http::header::{CONTENT_TYPE, ACCEPT}Working Example
Example Snippetrust
fn main() { use http::{Request, header::{CONTENT_TYPE, ACCEPT}}; let req = Request::builder().method("POST").uri("/notes").header(CONTENT_TYPE, "text/plain").header(ACCEPT, "application/json").body("note").unwrap(); println!("{} {}", req.headers()[CONTENT_TYPE].to_str().unwrap(), req.headers()[ACCEPT].to_str().unwrap());}