forked from JeffreytheCoder/Simple-HTTP-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.h
More file actions
27 lines (22 loc) · 982 Bytes
/
http.h
File metadata and controls
27 lines (22 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef HTTP_RESPONSE_H
#define HTTP_RESPONSE_H
#include <stdio.h>
/**
* @brief maximum number of characters in buffer.
*/
extern const int BUFFER_SIZE;
/**
* @brief Take a file extension as input and return the corresponding MIME type.
* Currently supports; .html; .txt; .jpg; .jpeg; .png and application/octet-stream as default.
* @returns string of the mime type.
*/
const char *get_mime_type(const char *file_ext);
/**
* @brief builds an HTTP response based on the given file name and extension.
* It first constructs the HTTP header, including the appropriate MIME type based on the file extension.
* If the file doesn't exist, it sets the response to a "404 Not Found" message.
* Otherwise, it opens the file, reads its contents, and appends them to the response buffer.
* The final response length is stored in the response_len parameter.
*/
void build_http_response(const char *file_name, const char *file_ext, char *response, size_t *response_len);
#endif