Expand description
This crate provides a simple formatter for building the lines of an HTTP
response header. The result can be
written directly into a TcpStream
or any other object that implements Write
.
§Example
use uhttp_response_header::HeaderLines;
use std::io::{Cursor, Write};
let mut buf = [0; 40];
let mut cursor = Cursor::new(&mut buf[..]);
// Write a header with response code `200` and a `Host: iana.org` header field.
{
let mut h = HeaderLines::new(&mut cursor);
write!(h.line(), "{} {}", "HTTP/1.1", "200 OK").unwrap();
write!(h.line(), "Host: {}", "iana.org").unwrap();
}
// Now write the body.
write!(&mut cursor, "hello").unwrap();
assert_eq!(cursor.into_inner(), &b"HTTP/1.1 200 OK\r\nHost: iana.org\r\n\r\nhello"[..]);
Structs§
- Header
Line - Writes out a header line.
- Header
Lines - Writes out the lines in an HTTP response header.