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