40 lines
1.2 KiB
C
40 lines
1.2 KiB
C
#ifndef HTTP_RESPONSE_H
|
|
#define HTTP_RESPONSE_H
|
|
|
|
#include "http_content_type.h"
|
|
#include "http_server.h"
|
|
#include "http_status.h"
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
typedef struct {
|
|
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;
|
|
|
|
// 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);
|
|
|
|
// Envoie la réponse au client.
|
|
void http_respond(HttpResponse *__res, int clientfd);
|
|
|
|
// Lit un fichier et renvoie son contenu.
|
|
char *read_file(const char *__path);
|
|
|
|
// 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
|