Module afire::extension

source ·
Expand description

Useful extensions to the base afire. Includes helpful middleware like Serve Static, Rate Limit and Logger.

All Feature

NameDescription
DateAdd the Date header to responses. Required by HTTP.
HeadAdd support for HTTP HEAD requests.
LoggerLog incoming requests to the console / file.
RateLimiterLimit how many requests can be handled from a source.
RealIpGet the real IP of a client through a reverse proxy
RequestIdAdd a Request-Id header to all requests.
ServeStaticServe static files from a dir.
TraceAdd support for the HTTP TRACE method.

Modules

  • Middleware to add the HTTP Date header (as defined in RFC 9110, Section 5.6.7). This is technically required for all servers that have a clock, so I may move it to the core library at some point.
  • Log requests to the console or a file.
  • Serve Static Content from the file system.

Structs

  • Middleware to add the HTTP Date header (as defined in RFC 9110, Section 5.6.7). This is technically required for all servers that have a clock, so I may move it to the core library at some point.
  • Middleware to add support for the HTTP HEAD method. It does this by changing the method to GET and adding a special header (afire::head). Once the response is processed by the normal route handler, the middleware will check if the header is present. If it is, any body data will be discarded and the [Content-Length] header will be added, if it is not already present. On static responses, the length is already known, but with streaming responses, the stream will be read to the end to get the length (by default).
  • Log requests to the console or a file.
  • Limit the amount of requests handled by the server.
  • Add an id to every incoming Request
  • Serve Static Content
  • Adds support for the HTTP TRACE method. It echos the request (Status line + Headers) back to the client as the response body. The Cookie header is excluded by default because it could contain sensitive information. Read more about it in RFC-9110.

Traits

  • Trait that adds methods for getting the real IP of a client through a reverse proxy. If you are using the “X-Forwarded-For” header you can use req.real_ip() but if you are using a different header you will have to use req.real_ip_header(...).