1 #ifndef HTTP_REQUEST_H
2 #define HTTP_REQUEST_H
3 
4 #include "http-header.h"
5 
6 struct http_url;
7 
8 #define HTTP_REQUEST_DEFAULT_MAX_TARGET_LENGTH      (8 * 1024)
9 #define HTTP_REQUEST_DEFAULT_MAX_HEADER_SIZE        (200 * 1024)
10 #define HTTP_REQUEST_DEFAULT_MAX_HEADER_FIELD_SIZE  (8 * 1024)
11 #define HTTP_REQUEST_DEFAULT_MAX_HEADER_FIELDS      50
12 #define HTTP_REQUEST_DEFAULT_MAX_PAYLOAD_SIZE       (1 * 1024 * 1024)
13 
14 struct http_request_limits {
15 	uoff_t max_target_length;
16 	uoff_t max_payload_size;
17 
18 	struct http_header_limits header;
19 };
20 
21 enum http_request_target_format {
22 	HTTP_REQUEST_TARGET_FORMAT_ORIGIN = 0,
23 	HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
24 	HTTP_REQUEST_TARGET_FORMAT_AUTHORITY,
25 	HTTP_REQUEST_TARGET_FORMAT_ASTERISK
26 };
27 
28 struct http_request_target {
29 	enum http_request_target_format format;
30 	struct http_url *url;
31 };
32 
33 struct http_request {
34 	const char *method;
35 
36 	const char *target_raw;
37 	struct http_request_target target;
38 
39 	unsigned char version_major;
40 	unsigned char version_minor;
41 
42 	time_t date;
43 	const struct http_header *header;
44 	struct istream *payload;
45 
46 	ARRAY_TYPE(const_string) connection_options;
47 
48 	bool connection_close:1;
49 	bool expect_100_continue:1;
50 };
51 
52 static inline bool
http_request_method_is(const struct http_request * req,const char * method)53 http_request_method_is(const struct http_request *req, const char *method)
54 {
55 	if (req->method == NULL)
56 		return FALSE;
57 
58 	return (strcmp(req->method, method) == 0);
59 }
60 
61 static inline const struct http_header_field *
http_request_header_find(const struct http_request * req,const char * name)62 http_request_header_find(const struct http_request *req, const char *name)
63 {
64 	return http_header_field_find(req->header, name);
65 }
66 
67 static inline const char *
http_request_header_get(const struct http_request * req,const char * name)68 http_request_header_get(const struct http_request *req, const char *name)
69 {
70 	return http_header_field_get(req->header, name);
71 }
72 
ARRAY_TYPE(http_header_field)73 static inline const ARRAY_TYPE(http_header_field) *
74 http_request_header_get_fields(const struct http_request *req)
75 {
76 	return http_header_get_fields(req->header);
77 }
78 
79 bool http_request_has_connection_option(const struct http_request *req,
80 	const char *option);
81 int http_request_get_payload_size(const struct http_request *req,
82 	uoff_t *size_r);
83 
84 #endif
85