lander/include/http/res.h

70 lines
1.7 KiB
C

#ifndef LANDER_HTTP_RES
#define LANDER_HTTP_RES
#include <stdbool.h>
#include <stdio.h>
#include "http/types.h"
/**
* Struct describing a header for the response.
*/
typedef struct http_response_header {
http_header type;
const char *value;
bool owned;
} http_response_header;
/**
* Struct representing an HTTP response.
*/
typedef struct http_response {
http_status status;
const char *head;
size_t head_len;
size_t head_written;
http_body body;
http_response_header headers[4];
size_t header_count;
} http_response;
/**
* Set the request body to the given buffer.
*
* @param res response to modify
* @param body pointer to the buf containing the body
* @param body_len length of the body
* @owned whether the body should be freed after processing the request
*/
void http_res_set_body_buf(http_response *res, const char *body,
size_t body_len, bool owned);
/**
* Set the request body to the given filename.
*
* @param res response to modify
* @param filename path to the file to return
*/
void http_res_set_body_file(http_response *res, const char *filename);
/**
* Add a header to the response.
*
* @param res response to modify
* @param type type of the header
* @param value value of the header
* @param owned whether the value should be freed after processing the request
*/
void http_res_add_header(http_response *res, http_header type,
const char *value, bool owned);
/**
* Add a Content-Type header corresponding to the mime type.
*
* @param res response to modiy
* @param mime_type mime type of the response
*/
void http_res_set_mime_type(http_response *res, http_mime_type mime_type);
#endif