This commit is contained in:
cdricms
2024-11-20 00:04:49 +01:00
parent 7b52f5de7d
commit cdae291dd8
8 changed files with 145 additions and 71 deletions

View File

@@ -6,28 +6,34 @@
#include "http_status.h"
#include <stdbool.h>
#include <stddef.h>
#include <sys/wait.h>
typedef struct {
HttpStatus status_code;
HttpContentType content_type;
size_t content_length;
char *body;
bool body_in_heap;
HttpStatus status_code; // Code HTTP, ex. 200
HttpContentType content_type; // ex. HTTP_CT_HTML => text/html
size_t content_length; // Taille du contenu en bytes
char *body; // Contenu de la réponse
bool body_in_heap; // Si le contenu est défini dans le heap, alors on pourra
// libérer sa mémoire
} HttpResponse;
// It will create a string respecting the Hypertext Transfer Protocol.
//
// To then be sent to the client.
// Cela crée une chaîne de caractères respectant le protocole HTTP selon la
// réponse donnée.
bool construct_response(HttpResponse __res, char *out);
// Respond a http response to the client (clientfd);
// Envoie la réponse au client.
void http_respond(HttpResponse *__res, int clientfd);
// Read a file from a specified path
// Lit un fichier et renvoie son contenu.
char *read_file(const char *__path);
// Given a path will return a HttpResponse
// Lit un fichier à un chemin donné et forme une réponse HTTP.
HttpResponse *from_file(const char *__path);
// Libère tout ce qui est nécessaire en rapport avec la structure HttpResponse.
void free_response(HttpResponse *__res);
// Execute un programme python à un chemin donné et envoie son STDOUT au socket
// client.
HttpServerRunStatus cgi(const char *__path, int clientfd);
#endif