xref: /lighttpd1.4/src/http_header.h (revision 3fbb5773)
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_e {
29   HTTP_HEADER_OTHER = 0
30  ,HTTP_HEADER_ACCEPT
31  ,HTTP_HEADER_ACCEPT_ENCODING
32  ,HTTP_HEADER_ACCEPT_LANGUAGE
33  ,HTTP_HEADER_ACCEPT_RANGES
34  ,HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
35  ,HTTP_HEADER_AGE
36  ,HTTP_HEADER_ALLOW
37  ,HTTP_HEADER_ALT_SVC
38  ,HTTP_HEADER_ALT_USED
39  ,HTTP_HEADER_AUTHORIZATION
40  ,HTTP_HEADER_CACHE_CONTROL
41  ,HTTP_HEADER_CONNECTION
42  ,HTTP_HEADER_CONTENT_ENCODING
43  ,HTTP_HEADER_CONTENT_LENGTH
44  ,HTTP_HEADER_CONTENT_LOCATION
45  ,HTTP_HEADER_CONTENT_RANGE
46  ,HTTP_HEADER_CONTENT_SECURITY_POLICY
47  ,HTTP_HEADER_CONTENT_TYPE
48  ,HTTP_HEADER_COOKIE
49  ,HTTP_HEADER_DATE
50  ,HTTP_HEADER_DNT
51  ,HTTP_HEADER_ETAG
52  ,HTTP_HEADER_EXPECT
53  ,HTTP_HEADER_EXPECT_CT
54  ,HTTP_HEADER_EXPIRES
55  ,HTTP_HEADER_FORWARDED
56  ,HTTP_HEADER_HOST
57  ,HTTP_HEADER_HTTP2_SETTINGS
58  ,HTTP_HEADER_IF_MATCH
59  ,HTTP_HEADER_IF_MODIFIED_SINCE
60  ,HTTP_HEADER_IF_NONE_MATCH
61  ,HTTP_HEADER_IF_RANGE
62  ,HTTP_HEADER_IF_UNMODIFIED_SINCE
63  ,HTTP_HEADER_LAST_MODIFIED
64  ,HTTP_HEADER_LINK
65  ,HTTP_HEADER_LOCATION
66  ,HTTP_HEADER_ONION_LOCATION
67  ,HTTP_HEADER_P3P
68  ,HTTP_HEADER_PRAGMA
69  ,HTTP_HEADER_RANGE
70  ,HTTP_HEADER_REFERER
71  ,HTTP_HEADER_REFERRER_POLICY
72  ,HTTP_HEADER_SERVER
73  ,HTTP_HEADER_SET_COOKIE
74  ,HTTP_HEADER_STATUS
75  ,HTTP_HEADER_STRICT_TRANSPORT_SECURITY
76  ,HTTP_HEADER_TE
77  ,HTTP_HEADER_TRANSFER_ENCODING
78  ,HTTP_HEADER_UPGRADE
79  ,HTTP_HEADER_UPGRADE_INSECURE_REQUESTS
80  ,HTTP_HEADER_USER_AGENT
81  ,HTTP_HEADER_VARY
82  ,HTTP_HEADER_WWW_AUTHENTICATE
83  ,HTTP_HEADER_X_CONTENT_TYPE_OPTIONS
84  ,HTTP_HEADER_X_FORWARDED_FOR
85  ,HTTP_HEADER_X_FORWARDED_PROTO
86  ,HTTP_HEADER_X_FRAME_OPTIONS
87  ,HTTP_HEADER_X_XSS_PROTECTION
88 };
89 
90 __attribute_pure__
91 enum http_header_e http_header_hkey_get(const char *s, uint32_t slen);
92 __attribute_pure__
93 enum http_header_e http_header_hkey_get_lc(const char *s, uint32_t slen);
94 
95 __attribute_pure__
96 int http_header_str_to_code (const char * const s);
97 
98 __attribute_pure__
99 int http_header_str_contains_token (const char *s, uint32_t slen, const char *m, uint32_t mlen);
100 
101 int http_header_remove_token (buffer * const b, const char * const m, const uint32_t mlen);
102 
103 __attribute_pure__
104 buffer * http_header_response_get(const request_st *r, enum http_header_e id, const char *k, uint32_t klen);
105 void http_header_response_unset(request_st *r, enum http_header_e id, const char *k, uint32_t klen);
106 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);
107 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);
108 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);
109 
110 __attribute_pure__
111 buffer * http_header_request_get(const request_st *r, enum http_header_e id, const char *k, uint32_t klen);
112 void http_header_request_unset(request_st *r, enum http_header_e id, const char *k, uint32_t klen);
113 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);
114 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);
115 
116 __attribute_pure__
117 buffer * http_header_env_get(const request_st *r, const char *k, uint32_t klen);
118 void http_header_env_set(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen);
119 void http_header_env_append(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen);
120 
121 __attribute_hot__
122 uint32_t http_header_parse_hoff (const char *n, const uint32_t clen, unsigned short hoff[8192]);
123 
124 #endif
125