response.h

The response.h module provides functions for interacting with mn_response objects. Learn more at Responses.

API

struct mn_response

An opaque object representing the response to send back to the client.

struct mn_status mn_response_suspend(struct mn_response *const res)

To be invoked within an mn_route_handler_t. Suspends the current handler, yielding control back to the event loop.

Status Codes

enum mn_http_code

An HTTP status code.

unsigned int MN_HTTP_CONTINUE = 100
unsigned int MN_HTTP_SWITCHING_PROTOCOLS = 101
unsigned int MN_HTTP_PROCESSING = 102
unsigned int MN_HTTP_EARLY_HINTS = 103
unsigned int MN_HTTP_CODE_OK = 200
unsigned int MN_HTTP_CODE_CREATED = 201
unsigned int MN_HTTP_ACCEPTED = 202
unsigned int MN_HTTP_NON_AUTH_INFO = 203
unsigned int MN_HTTP_NO_CONTENT = 204
unsigned int MN_HTTP_RESET_CONTENT = 205
unsigned int MN_HTTP_PARTIAL_CONTENT = 206
unsigned int MN_HTTP_MULTI_STATUS = 207
unsigned int MN_HTTP_ALREADY_REPORTED = 208
unsigned int MN_HTTP_IM_USED = 226
unsigned int MN_HTTP_MULTIPLE_CHOICES = 300
unsigned int MN_HTTP_MOVED_PERMANENTLY = 301
unsigned int MN_HTTP_FOUND = 302
unsigned int MN_HTTP_SEE_OTHER = 303
unsigned int MN_HTTP_NOT_MODIFIED = 304
unsigned int MN_HTTP_USE_PROXY = 305
unsigned int MN_HTTP_TEMPORARY_REDIRECT = 307
unsigned int MN_HTTP_PERMANENT_REDIRECT = 308
unsigned int MN_HTTP_BAD_REQUEST = 400
unsigned int MN_HTTP_UNAUTHORIZED = 401
unsigned int MN_HTTP_PAYMENT_REQUIRED = 402
unsigned int MN_HTTP_FORBIDDEN = 403
unsigned int MN_HTTP_NOT_FOUND = 404
unsigned int MN_HTTP_METHOD_NOT_ALLOWED = 405
unsigned int MN_HTTP_NOT_ACCEPTABLE = 406
unsigned int MN_HTTP_PROXY_AUTH_REQUIRED = 407
unsigned int MN_HTTP_REQUEST_TIMEOUT = 408
unsigned int MN_HTTP_CONFLICT = 409
unsigned int MN_HTTP_GONE = 410
unsigned int MN_HTTP_LENGTH_REQUIRED = 411
unsigned int MN_HTTP_PRECONDITION_FAILED = 412
unsigned int MN_HTTP_CONTENT_TOO_LARGE = 413
unsigned int MN_HTTP_URI_TOO_LONG = 414
unsigned int MN_HTTP_UNSUPPORTED_MEDIA_TYPE = 415
unsigned int MN_HTTP_RANGE_NOT_SATISFIABLE = 416
unsigned int MN_HTTP_EXPECTATION_FAILED = 417
unsigned int MN_HTTP_IM_A_TEAPOT = 418
unsigned int MN_HTTP_MISDIRECTED_REQUEST = 421
unsigned int MN_HTTP_UNPROCESSABLE_CONTENT = 422
unsigned int MN_HTTP_LOCKED = 423
unsigned int MN_HTTP_FAILED_DEPENDENCY = 424
unsigned int MN_HTTP_TOO_EARLY = 425
unsigned int MN_HTTP_UPGRADE_REQUIRED = 426
unsigned int MN_HTTP_PRECONDITION_REQUIRED = 428
unsigned int MN_HTTP_TOO_MANY_REQUESTS = 429
unsigned int MN_HTTP_FIELDS_TOO_LARGE = 432
unsigned int MN_HTTP_INTERNAL_SERVER_ERROR = 500
unsigned int MN_HTTP_NOT_IMPLEMENTED = 501
unsigned int MN_HTTP_BAD_GATEWAY = 502
unsigned int MN_HTTP_SERVICE_UNAVAILABLE = 503
unsigned int MN_HTTP_GATEWAY_TIMEOUT = 504
unsigned int MN_HTTP_VERSION_NOT_SUPPORTED = 505
unsigned int MN_HTTP_VARIANT_ALSO_NEGOTIATES = 506
unsigned int MN_HTTP_INSUFFICIENT_STORAGE = 507
unsigned int MN_HTTP_LOOP_DETECTED = 508
unsigned int MN_HTTP_NOT_EXTENDED = 510
unsigned int MN_HTTP_NETWORK_AUTH_REQUIRED = 511

Body

struct mn_status mn_response_write(
struct mn_response *const res,
struct mn_str const content
)

Write the contents of output to the mn_response.

Parameters:
  • res – The response object to write to.

  • output – The content to append to the body.

Returns:

An mn_status with value:
- MN_ERROR_NONE on success;
- MN_ERROR_IMMUTABLE if the response body is immutable.

struct mn_status mn_response_write_file(
struct mn_response *const,
struct mn_str const path
)

Write the entirety of the file at path to the mn_response.

Parameters:
  • res – The response object to write to.

  • path – The path of the file to write to the response body.

Returns:

An mn_status with value:
- MN_ERROR_NONE on success;
- MN_ERROR_INVALID_ARG if a file could not be found at path or the file could not be opened (e.g. is a directory);
- MN_ERROR_IMMUTABLE if the body is immutable.

struct mn_status mn_response_write_buffer(
struct mn_response *const,
char const buffer[static const 1],
size_t const len
)

Write the contents of buffer to the mn_response.

Parameters:
  • res – The response object to write to.

  • buffer – The content to append to the response body.

  • len – The number of bytes to append to the body from buffer.

Returns:

An mn_status with value:
- MN_ERROR_NONE on success;
- MN_ERROR_IMMUTABLE if the body is immutable.