Expand description
§httpp
A library for parsing HTTP requests and responses. The focus is on speed and safety. It is intentionally strict to prevent possible HTTP attacks
§Working with Request
You can parse a request as follows:
use http::Request;
let req = b"GET /index.html HTTP/1.1\r\n\r\n";
let parsed = Request::parse(req).unwrap();
assert!(parsed.method() == htpp::Method::Get);
assert!(parsed.path() == "/index.html");
You can create a request as follows:
use http::{Method, Request, Header};
let method = Method::Get;
let path = "/index.html";
let headers = vec![Header::new("Accept", "*/*")];
let req = Request::new(method, path, headers);
§Working with Response
You can parse a response as follows:
use http::Response;
let req = b"HTTP/1.1 200 OK GET\r\n\r\n";
let parsed = Response::parse(req).unwrap();
assert!(parsed.status() == 200);
assert!(parsed.reason() == "OK");
You can create a response as follows:
use http::{Response, Header};
let status = 200;
let reason = "OK";
let headers = vec![Header::new("Connection", "keep-alive")];
let req = Response::new(method, path, headers);
Structs§
- An HTTP header
- A parsed HTTP request
- A parsed http response
Enums§
- All parsing errors possible
- Possible http versions
- The http method of a request. Only GET, POST, and PUT are supported
Type Aliases§
- A result holding a parse error