request.h

The request.h module provides functions for interacting with mn_request objects. Learn more at Requests.

Options

MN_REQUEST_MAX_PATH_LEN

Defaults to 2048. The maximum supported length of any incoming URI including a trailing NUL terminator. Requests with longer URIs automatically receive an HTTP 414 URI Too Long response. To update, define before including makinori:

#define MN_REQUEST_MAX_PATH_LEN 4096
#include "makinori.h"
MN_REQUEST_MAX_CAPTURES

Defaults to 16. The maximum number of captures permitted in any route. Clients using a route with more captures than this value permits will automatically receive an HTTP 501 Not Implemented response. To update, define before include makinori:

#define MN_REQUEST_MAX_CAPTURES 32
#include "makinori.h"
MN_REQUEST_MAX_QUERY_PARAMS

Defaults to 24. The maximum number of query parameters permitted in any route. Clients specifying more query parameters than this value permits will automatically receive an HTTP 501 Not Implemented response. To update, define before include makinori:

#define MN_REQUEST_MAX_QUERY_PARAMS 48
#include "makinori.h"

API

enum mn_method

An HTTP method.

unsigned int MN_METHOD_GET = 0
struct mn_query_param

A single query param. Given e.g. abc=def, the key corresponds to abc whereas value corresponds to def.

struct mn_view key
struct mn_view value
struct mn_request

A client request.

enum mn_method method

The HTTP method sent by the client.

struct mn_str uri

The path and query portion of the URI used by the client.

struct mn_view path

The path portion of the URI used by the client.

struct mn_query_param query[MN_REQUEST_MAX_QUERY_PARAMS]

The query parameters sent by the client. There are a total of query_count valid key/value parameters set.

size_t query_count

The number of query parameters sent by the client.

struct mn_view captures[MN_REQUEST_MAX_CAPTURES]

The captures pulled from the path.

size_t capture_count

The number of string fragments captured.

typedef struct mn_status mn_route_handler_t(
struct mn_request const,
struct mn_response *const
)

A type alias for a user-defined handler function.

struct mn_route

A route. These are pattern-matched against client requests. For more information, refer to Routing. The following is a typical example of how a router might be defined:

static struct mn_route route_root;
static struct mn_route route_abc;
static struct mn_route route_def;

static struct mn_route route_root = {
    .method = MN_METHOD_GET,
    .pattern = mn_str_lit("/"),
    .handler = handle_root,
    .next = &route_abc,
  };

static struct mn_route route_abc = {
    .method = MN_METHOD_GET,
    .pattern = mn_str_lit("/abc"),
    .handler = handle_abc,
    .next = &route_def,
  };

static struct mn_route route_def = {
    .method = MN_METHOD_GET,
    .pattern = mn_str_lit("/def"),
    .handler = handle_def,
  };
enum mn_method method

The method used to match against the request.

struct mn_str pattern

The pattern used to match against the request.

mn_route_handler_t *handler

The user-defined handler function to be called on a successful match.

struct mn_route *next

The next route to try matching against if this route failed to do so.