Crate uhttp_response_header [] [src]

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.


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:` header field.
    let mut h = HeaderLines::new(&mut cursor);
    write!(h.line(), "{} {}", "HTTP/1.1", "200 OK").unwrap();
    write!(h.line(), "Host: {}", "").unwrap();

// Now write the body.
write!(&mut cursor, "hello").unwrap();

assert_eq!(cursor.into_inner(), &b"HTTP/1.1 200 OK\r\nHost:\r\n\r\nhello"[..]);



Writes out a header line.


Writes out the lines in an HTTP response header.