xref: /lighttpd1.4/src/http_header.h (revision fcf0dc3e)
1 #ifndef INCLUDED_HTTP_HEADER_H
2 #define INCLUDED_HTTP_HEADER_H
3 #include "first.h"
4 
5 #include "base_decls.h"
6 #include "buffer.h"
7 
8 /* HTTP header enum for select HTTP field-names
9  * reference:
10  *   https://www.iana.org/assignments/message-headers/message-headers.xml
11  *   https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
12  */
13 /* Note: must be kept in sync with http_header.c http_headers[] */
14 /* Note: must be kept in sync h2.c:http_header_lc[] */
15 /* Note: must be kept in sync h2.c:http_header_lshpack_idx[] */
16 /* Note: must be kept in sync h2.c:lshpack_idx_http_header[] */
17 /* Note: when adding new items, must replace OTHER in existing code for item */
18 /* Note: current implementation has limit of 64 htags
19  *       Use of htags is an optimization for quick existence checks in lighttpd.
20  *       (In the future, these values may also be used to map to HPACK indices.)
21  *       However, listing all possible headers here is highly discouraged,
22  *       as extending the bitmap greater than 64-bits may make quick bitmasks
23  *       check more expensive, and the cost for looking up unmarked headers
24  *       (HTTP_HEADER_OTHER) is not substantially more.  In the future, this
25  *       list may be revisitied and reviewed, and less frequent headers removed
26  *       or replaced.
27  */
28 enum http_header_h2_e { /* pseudo-headers */
29   HTTP_HEADER_H2_UNKNOWN         = -1
30  ,HTTP_HEADER_H2_AUTHORITY       = -2
31  ,HTTP_HEADER_H2_METHOD_GET      = -3
32  ,HTTP_HEADER_H2_METHOD_POST     = -4
33  ,HTTP_HEADER_H2_PATH            = -5
34  ,HTTP_HEADER_H2_PATH_INDEX_HTML = -6
35  ,HTTP_HEADER_H2_SCHEME_HTTP     = -7
36  ,HTTP_HEADER_H2_SCHEME_HTTPS    = -8
37  ,HTTP_HEADER_H2_PROTOCOL        = -9
38 };
39 enum http_header_e {
40   HTTP_HEADER_OTHER = 0
41  ,HTTP_HEADER_ACCEPT
42  ,HTTP_HEADER_ACCEPT_ENCODING
43  ,HTTP_HEADER_ACCEPT_LANGUAGE
44  ,HTTP_HEADER_ACCEPT_RANGES
45  ,HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
46  ,HTTP_HEADER_AGE
47  ,HTTP_HEADER_ALLOW
48  ,HTTP_HEADER_ALT_SVC
49  ,HTTP_HEADER_ALT_USED
50  ,HTTP_HEADER_AUTHORIZATION
51  ,HTTP_HEADER_CACHE_CONTROL
52  ,HTTP_HEADER_CONNECTION
53  ,HTTP_HEADER_CONTENT_ENCODING
54  ,HTTP_HEADER_CONTENT_LENGTH
55  ,HTTP_HEADER_CONTENT_LOCATION
56  ,HTTP_HEADER_CONTENT_RANGE
57  ,HTTP_HEADER_CONTENT_SECURITY_POLICY
58  ,HTTP_HEADER_CONTENT_TYPE
59  ,HTTP_HEADER_COOKIE
60  ,HTTP_HEADER_DATE
61  ,HTTP_HEADER_DNT
62  ,HTTP_HEADER_ETAG
63  ,HTTP_HEADER_EXPECT
64  ,HTTP_HEADER_EXPECT_CT
65  ,HTTP_HEADER_EXPIRES
66  ,HTTP_HEADER_FORWARDED
67  ,HTTP_HEADER_HOST
68  ,HTTP_HEADER_HTTP2_SETTINGS
69  ,HTTP_HEADER_IF_MATCH
70  ,HTTP_HEADER_IF_MODIFIED_SINCE
71  ,HTTP_HEADER_IF_NONE_MATCH
72  ,HTTP_HEADER_IF_RANGE
73  ,HTTP_HEADER_IF_UNMODIFIED_SINCE
74  ,HTTP_HEADER_LAST_MODIFIED
75  ,HTTP_HEADER_LINK
76  ,HTTP_HEADER_LOCATION
77  ,HTTP_HEADER_ONION_LOCATION
78  ,HTTP_HEADER_P3P
79  ,HTTP_HEADER_PRAGMA
80  ,HTTP_HEADER_PRIORITY
81  ,HTTP_HEADER_RANGE
82  ,HTTP_HEADER_REFERER
83  ,HTTP_HEADER_REFERRER_POLICY
84  ,HTTP_HEADER_SERVER
85  ,HTTP_HEADER_SET_COOKIE
86  ,HTTP_HEADER_STATUS
87  ,HTTP_HEADER_STRICT_TRANSPORT_SECURITY
88  ,HTTP_HEADER_TE
89  ,HTTP_HEADER_TRANSFER_ENCODING
90  ,HTTP_HEADER_UPGRADE
91  ,HTTP_HEADER_UPGRADE_INSECURE_REQUESTS
92  ,HTTP_HEADER_USER_AGENT
93  ,HTTP_HEADER_VARY
94  ,HTTP_HEADER_WWW_AUTHENTICATE
95  ,HTTP_HEADER_X_CONTENT_TYPE_OPTIONS
96  ,HTTP_HEADER_X_FORWARDED_FOR
97  ,HTTP_HEADER_X_FORWARDED_PROTO
98  ,HTTP_HEADER_X_FRAME_OPTIONS
99  ,HTTP_HEADER_X_XSS_PROTECTION
100 };
101 
102 __attribute_pure__
103 enum http_header_e http_header_hkey_get(const char *s, size_t slen);
104 __attribute_pure__
105 enum http_header_e http_header_hkey_get_lc(const char *s, size_t slen);
106 
107 __attribute_pure__
108 int http_header_str_to_code (const char * const s);
109 
110 __attribute_pure__
111 int http_header_str_contains_token (const char *s, uint32_t slen, const char *m, uint32_t mlen);
112 
113 int http_header_remove_token (buffer * const b, const char * const m, const uint32_t mlen);
114 
115 __attribute_pure__
116 buffer * http_header_response_get(const request_st *r, enum http_header_e id, const char *k, uint32_t klen);
117 __attribute_returns_nonnull__
118 buffer * http_header_response_set_ptr(request_st *r, enum http_header_e id, const char *k, uint32_t klen);
119 void http_header_response_unset(request_st *r, enum http_header_e id, const char *k, uint32_t klen);
120 void http_header_response_set(request_st *r, enum http_header_e id, const char *k, uint32_t klen, const char *v, uint32_t vlen);
121 void http_header_response_append(request_st *r, enum http_header_e id, const char *k, uint32_t klen, const char *v, uint32_t vlen);
122 void http_header_response_insert(request_st *r, enum http_header_e id, const char *k, uint32_t klen, const char *v, uint32_t vlen);
123 
124 __attribute_pure__
125 buffer * http_header_request_get(const request_st *r, enum http_header_e id, const char *k, uint32_t klen);
126 __attribute_returns_nonnull__
127 buffer * http_header_request_set_ptr(request_st *r, enum http_header_e id, const char *k, uint32_t klen);
128 void http_header_request_unset(request_st *r, enum http_header_e id, const char *k, uint32_t klen);
129 void http_header_request_set(request_st *r, enum http_header_e id, const char *k, uint32_t klen, const char *v, uint32_t vlen);
130 void http_header_request_append(request_st *r, enum http_header_e id, const char *k, uint32_t klen, const char *v, uint32_t vlen);
131 
132 __attribute_pure__
133 buffer * http_header_env_get(const request_st *r, const char *k, uint32_t klen);
134 __attribute_returns_nonnull__
135 buffer * http_header_env_set_ptr(request_st *r, const char *k, uint32_t klen);
136 void http_header_env_set(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen);
137 void http_header_env_append(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen);
138 
139 __attribute_hot__
140 uint32_t http_header_parse_hoff (const char *n, const uint32_t clen, unsigned short hoff[8192]);
141 
142 #endif
143