Crate safehttp

Source
Expand description

A slow (but simple, safe and strict) HTTP/1.1 parser for Rust

See RFC 7230.

§Simple example

extern crate http;
extern crate safehttp;
use std::io;

let mut source = io::Cursor::new(
    b"GET /index.html HTTP/1.1\r\nHost: example.com\r\n\r\n".to_vec()
);
let config = &safehttp::Config::DEFAULT;
let request = safehttp::parse_request(&mut source, config).unwrap();

assert_eq!(request.method(), http::Method::GET);
assert_eq!(request.uri(), "/index.html");
assert_eq!(request.headers().get("host").unwrap(), "example.com");

Structs§

ChunkReader
Decoder for chunked transfer encoding.
Config
Parser configuration.

Enums§

Body
Either an HTTP body or nothing.
BodyReader
Abstraction for parsing streamed payloads.
Error
Errors that can be raised during HTTP parsing.

Functions§

parse_request
Parses an HTTP request.
parse_request_head
Parses the request line and the headers of an HTTP request.
parse_response
Parses an HTTP response.
unparse_request
Serializes an HTTP request into a stream.
unparse_request_head
Serializes a request line and headers.
unparse_request_head_parts
Serializes a request line and headers.
unparse_request_sync
Serializes an HTTP request into a byte array.
unparse_response
Serializes an HTTP response into a stream.
unparse_response_head
Serializes a status line and headers.
unparse_response_head_parts
Serializes a status line and headers.
unparse_response_sync
Serializes an HTTP response into a byte array.