http.c improvements
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef CWS_HTTP_H
|
||||
#define CWS_HTTP_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "utils/config.h"
|
||||
#include "utils/hashmap.h"
|
||||
|
||||
@@ -16,6 +18,12 @@ typedef enum cws_http_method_t {
|
||||
CWS_HTTP_HEAD,
|
||||
} cws_http_method;
|
||||
|
||||
typedef enum cws_http_status_t {
|
||||
CWS_HTTP_OK,
|
||||
CWS_HTTP_NOT_FOUND,
|
||||
CWS_HTTP_NOT_IMPLEMENTED,
|
||||
} cws_http_status;
|
||||
|
||||
/**
|
||||
* @brief HTTP request struct
|
||||
*
|
||||
@@ -40,12 +48,21 @@ typedef struct cws_http_t {
|
||||
*/
|
||||
cws_http *cws_http_parse(char *request_str, int sockfd, cws_config *config);
|
||||
|
||||
void cws_http_parse_method(cws_http *request, const char *method);
|
||||
int cws_http_parse_method(cws_http *request, const char *method);
|
||||
void cws_http_get_content_type(cws_http *request, char *content_type);
|
||||
char *cws_http_status_string(cws_http_status status);
|
||||
|
||||
void cws_http_send_response(cws_http *request);
|
||||
void cws_http_send_not_found(cws_http *request);
|
||||
void cws_http_send_not_implemented(cws_http *request);
|
||||
/**
|
||||
* @brief Build the http response
|
||||
*
|
||||
* @return Returns the size of the response
|
||||
*/
|
||||
size_t cws_http_response_builder(char **response, char *http_version, cws_http_status status, char *content_type, char *connection, char *body,
|
||||
size_t body_len_bytes);
|
||||
|
||||
void cws_http_send_response(cws_http *request, cws_http_status status);
|
||||
void cws_http_send_resource(cws_http *request);
|
||||
void cws_http_send_error_page(cws_http *request, cws_http_status status, char *title, char *description);
|
||||
|
||||
void cws_http_free(cws_http *request);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <netdb.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "utils/config.h"
|
||||
@@ -19,7 +20,7 @@
|
||||
#define CWS_SERVER_EPOLL_TIMEOUT -1
|
||||
|
||||
/* Main server loop */
|
||||
extern volatile bool cws_server_run;
|
||||
extern volatile sig_atomic_t cws_server_run;
|
||||
|
||||
/**
|
||||
* @brief Runs the server
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EVELOPER
|
||||
#define CWS_LOG_DEBUG(msg, ...) fprintf(stdout, _DEBUG " " msg "\n", ##__VA_ARGS__)
|
||||
#define CWS_LOG_DEBUG(msg, ...) fprintf(stdout, _DEBUG " [%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define CWS_LOG_DEBUG(msg, ...)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user