summaryrefslogtreecommitdiffstats
path: root/src/lib-http/http-request.h
blob: feee28fba1e4771eb761c390affc6126499ed8d9 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef HTTP_REQUEST_H
#define HTTP_REQUEST_H

#include "http-header.h"

struct http_url;

#define HTTP_REQUEST_DEFAULT_MAX_TARGET_LENGTH      (8 * 1024)
#define HTTP_REQUEST_DEFAULT_MAX_HEADER_SIZE        (200 * 1024)
#define HTTP_REQUEST_DEFAULT_MAX_HEADER_FIELD_SIZE  (8 * 1024)
#define HTTP_REQUEST_DEFAULT_MAX_HEADER_FIELDS      50
#define HTTP_REQUEST_DEFAULT_MAX_PAYLOAD_SIZE       (1 * 1024 * 1024)

struct http_request_limits {
	uoff_t max_target_length;
	uoff_t max_payload_size;

	struct http_header_limits header;
};

enum http_request_target_format {
	HTTP_REQUEST_TARGET_FORMAT_ORIGIN = 0,
	HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
	HTTP_REQUEST_TARGET_FORMAT_AUTHORITY,
	HTTP_REQUEST_TARGET_FORMAT_ASTERISK
};

struct http_request_target {
	enum http_request_target_format format;
	struct http_url *url;
};

struct http_request {
	const char *method;

	const char *target_raw;
	struct http_request_target target;

	unsigned char version_major;
	unsigned char version_minor;

	time_t date;
	const struct http_header *header;
	struct istream *payload;

	ARRAY_TYPE(const_string) connection_options;

	bool connection_close:1;
	bool expect_100_continue:1;
};

static inline bool
http_request_method_is(const struct http_request *req, const char *method)
{
	if (req->method == NULL)
		return FALSE;

	return (strcmp(req->method, method) == 0);
}

static inline const struct http_header_field *
http_request_header_find(const struct http_request *req, const char *name)
{
	return http_header_field_find(req->header, name);
}

static inline const char *
http_request_header_get(const struct http_request *req, const char *name)
{
	return http_header_field_get(req->header, name);
}

static inline const ARRAY_TYPE(http_header_field) *
http_request_header_get_fields(const struct http_request *req)
{
	return http_header_get_fields(req->header);
}

bool http_request_has_connection_option(const struct http_request *req,
	const char *option);
int http_request_get_payload_size(const struct http_request *req,
	uoff_t *size_r);

#endif