-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibhttp.h
More file actions
47 lines (41 loc) · 1.06 KB
/
libhttp.h
File metadata and controls
47 lines (41 loc) · 1.06 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* A simple HTTP library.
*
* Usage example:
*
* // Returns NULL if an error was encountered.
* struct http_request *request = http_request_parse(fd);
*
* ...
*
* http_start_response(fd, 200);
* http_send_header(fd, "Content-type", http_get_mime_type("index.html"));
* http_send_header(fd, "Server", "httpserver/1.0");
* http_end_headers(fd);
* http_send_string(fd, "<html><body><a href='/'>Home</a></body></html>");
*
* close(fd);
*/
#ifndef LIBHTTP_H
#define LIBHTTP_H
/*
* Functions for parsing an HTTP request.
*/
struct http_request {
char *method;
char *path;
};
struct http_request *http_request_parse(int fd);
/*
* Functions for sending an HTTP response.
*/
void http_start_response(int fd, int status_code);
void http_send_header(int fd, char *key, char *value);
void http_end_headers(int fd);
void http_send_string(int fd, char *data);
void http_send_data(int fd, char *data, size_t size);
/*
* Helper function: gets the Content-Type based on a file name.
*/
char *http_get_mime_type(char *file_name);
#endif