Expand description
§A simple Blocking HTTP server library
No async, No runtime, just a dead simple blocking http server
§Usage example:
use blocking_http_server::*;
fn main() -> anyhow::Result<()> {
let mut server = Server::bind("127.0.0.1:8000")?;
for req in server.incoming() {
let mut req = match req {
Ok(req) => req,
Err(e) => {
eprintln!("Error: {}", e);
continue;
}
};
match (req.method(), req.uri().path()) {
(&Method::GET, "/") => {
let _ = req.respond(Response::new("hello world"));
}
_ => {
let _ = req.respond(
Response::builder()
.status(StatusCode::NOT_FOUND)
.body("404 Not Found")
.unwrap(),
);
}
}
}
Ok(())
}
Modules§
- header
- HTTP header types
- method
- The HTTP request method
- request
- HTTP request types.
- response
- HTTP response types.
- status
- HTTP status codes
- uri
- URI component of request and response lines
- version
- HTTP version
Structs§
- Error
- A generic “error” for HTTP connections
- Extensions
- A type map of protocol extensions.
- Header
Map - A set of HTTP headers
- Header
Name - Represents an HTTP header field name
- Header
Value - Represents an HTTP header field value.
- Http
Request - Incoming
- Method
- The Request Method (VERB)
- Request
- Represents an HTTP request.
- Response
- Represents an HTTP response
- Server
- Status
Code - An HTTP status code (
status-code
in RFC 9110 et al.). - Uri
- The URI component of a request.
- Version
- Represents a version of the HTTP spec.
Type Aliases§
- Result
- A
Result
typedef to use with thehttp::Error
type