Skip to main content

Module builder

Module builder 

Source
Expand description

Fluent builders for serialising HTTP/1.x request and response messages.

Both builders produce a complete, CRLF-terminated byte representation suitable for transmission over a TCP stream.

§Examples

use stackforge_core::layer::http::builder::{HttpRequestBuilder, HttpResponseBuilder};

// Build a simple GET request.
let bytes = HttpRequestBuilder::new()
    .method("GET")
    .uri("/index.html")
    .header("Host", "example.com")
    .header("Accept", "*/*")
    .build();

assert!(bytes.starts_with(b"GET /index.html HTTP/1.1\r\n"));

// Build a 200 OK response with a body.
let body = b"Hello, World!";
let bytes = HttpResponseBuilder::new()
    .status(200, "OK")
    .header("Content-Type", "text/plain")
    .body(body.to_vec())
    .build();

assert!(bytes.starts_with(b"HTTP/1.1 200 OK\r\n"));

Structs§

HttpRequestBuilder
Builder for HTTP/1.x request messages.
HttpResponseBuilder
Builder for HTTP/1.x response messages.