lander/include/http/res.h

70 lines
1.7 KiB
C
Raw Normal View History

#ifndef LANDER_HTTP_RES
#define LANDER_HTTP_RES
#include <stdbool.h>
#include <stdio.h>
#include "http/types.h"
2023-05-31 16:49:15 +02:00
/**
* Struct describing a header for the response.
*/
typedef struct http_response_header {
http_header type;
const char *value;
bool owned;
} http_response_header;
2023-05-31 16:49:15 +02:00
/**
* Struct representing an HTTP response.
*/
typedef struct http_response {
http_status status;
const char *head;
size_t head_len;
size_t head_written;
2023-05-31 11:46:34 +02:00
http_body body;
http_response_header headers[4];
size_t header_count;
} http_response;
2023-05-31 16:49:15 +02:00
/**
* 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);
2023-05-31 16:49:15 +02:00
/**
* Set the request body to the given filename.
2023-05-31 16:49:15 +02:00
*
* @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);
2023-05-31 16:49:15 +02:00
/**
* Add a header to the response.
2023-05-31 16:49:15 +02:00
*
* @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);
2023-05-31 16:49:15 +02:00
/**
* Add a Content-Type header corresponding to the mime type.
2023-05-31 16:49:15 +02:00
*
* @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