Crate mini_server

source ·

Structs§

  • The HTTPRequest struct represents an HTTP request received by the web server. It encapsulates various components of an HTTP request, including the HTTP method, request path, headers, and body.
  • The HTTPResponse struct represents an HTTP response that the web server can send to clients. It encapsulates various components of an HTTP response, including the response body, headers, status code, status text, and the HTTP version.
  • HTTPServer

Enums§

Constants§

  • CRLF represents the Carriage Return (CR) and Line Feed (LF) characters combined (“\r\n”). It is commonly used as the end-of-line sequence in HTTP requests and responses.
  • MAX_BUFFER defines the maximum size, in bytes, for a request in your web server. Requests exceeding this size may be rejected or handled differently based on your server’s implementation.

Traits§

Functions§

  • The parse_http_req function takes a string representing an entire HTTP request and parses it into a HTTPRequest struct, extracting information such as the HTTP method, path, headers, and body.
  • The parse_path function takes a string representing an HTTP request path and extracts the path and URL parameters (if any) from it. It returns a tuple containing the path and a URLSearchParams (HashMap<String, String>) representing the parsed URL parameters.
  • The vec_to_string function converts a vector of bytes (Vec<u8>) into a UTF-8 encoded string.

Type Aliases§

  • EventHandler type is a function type that defines the signature for handling events triggered by HTTP requests. It takes references to an HTTPRequest and a mutable HTTPResponse as parameters.
  • The Headers type alias represents a collection of HTTP headers in key-value pairs. It is implemented as a HashMap<String, String>, where keys are header names, and values are header values.
  • RequestHandler type is a function type that defines the signature for handling HTTP requests. It takes an HTTPRequest as a parameter and returns an HTTPResponse
  • The SoftEventHandler type is a function type that defines the signature for handling soft events, typically without specific request or response parameters.
  • The URLSearchParams type alias represents a collection of URL parameters parsed from an HTTP request’s query string. It is implemented as a HashMap<String, String> where keys are parameter names, and values are parameter values.