-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.h
59 lines (48 loc) · 1.41 KB
/
http.h
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
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef PLXR_HTTP_H
#define PLXR_HTTP_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HTTP_MAX_HEADERS (40)
struct plxr_http_header {
char *key;
char *value;
};
struct plxr_http_request {
char *method;
char *uri;
char *version;
struct plxr_http_header headers[HTTP_MAX_HEADERS];
size_t headers_len;
};
int plxr_http_response(
char *dest, size_t size,
int status_code,
const char *content_type,
int content_length
);
/* Parses a *mutable* string buffer `src`
* into a struct plxr_http_request `dest`
*
* returns
* 1 on success
* 0 on failure
*/
int plxr_http_parse(struct plxr_http_request *dest, char *src);
/* printf()'s a request and its headers.
*/
void plxr_http_print(struct plxr_http_request *req);
/* Returns the value of a header on success or NULL on failure.
*/
char *plxr_http_header(struct plxr_http_request *req, char *key);
/* Unescapes a url at `src`, writing it to `dest`, no more than `count` bytes.
* ex. "https%3A%2F%2Fwww.google.com%2F" -> "https://www.google.com/"
*
* If an invalid hex code is encountered, -1 is returned.
* Otherwise the size of the unescaped url is returned, regardless of if
* it exceeded `count` or not.
*/
ssize_t plxr_unescape_url(char *dest, size_t count, const char *src);
ssize_t plxr_parse_scheme(char *dest, size_t count, const char *src);
ssize_t plxr_parse_path(char *dest, size_t count, const char *src);
#endif /* PLXR_HTTP_H */