1 #ifndef _REQUEST_H_ 2 #define _REQUEST_H_ 3 #include "first.h" 4 5 #include <time.h> /* (struct timespec) */ 6 7 #include "base_decls.h" 8 #include "buffer.h" 9 #include "array.h" 10 #include "http_kv.h" 11 12 struct log_error_st; /* declaration */ 13 struct chunkqueue; /* declaration */ 14 struct cond_cache_t; /* declaration */ 15 struct cond_match_t; /* declaration */ 16 17 typedef struct { 18 unsigned int http_parseopts; 19 uint32_t max_request_field_size; 20 const array *mimetypes; 21 22 /* virtual-servers */ 23 const buffer *document_root; 24 const buffer *server_name; 25 const buffer *server_tag; 26 struct log_error_st *errh; 27 28 unsigned int max_request_size; 29 unsigned short max_keep_alive_requests; 30 unsigned short max_keep_alive_idle; 31 unsigned short max_read_idle; 32 unsigned short max_write_idle; 33 unsigned short stream_request_body; 34 unsigned short stream_response_body; 35 unsigned char high_precision_timestamps; 36 unsigned char allow_http11; 37 unsigned char follow_symlink; 38 unsigned char etag_flags; 39 unsigned char force_lowercase_filenames; /*(case-insensitive file systems)*/ 40 unsigned char use_xattr; 41 unsigned char range_requests; 42 unsigned char error_intercept; 43 44 unsigned char h2proto; /*(global setting copied for convenient access)*/ 45 46 /* debug */ 47 unsigned char log_file_not_found; 48 unsigned char log_request_header; 49 unsigned char log_request_handling; 50 unsigned char log_response_header; 51 unsigned char log_condition_handling; 52 unsigned char log_timeouts; 53 unsigned char log_state_handling; 54 unsigned char log_request_header_on_error; 55 56 unsigned int bytes_per_second; /* connection bytes/sec limit */ 57 unsigned int global_bytes_per_second;/*total bytes/sec limit for scope*/ 58 59 /* server-wide traffic-shaper 60 * 61 * each context has the counter which is inited once 62 * a second by the global_bytes_per_second config-var 63 * 64 * as soon as global_bytes_per_second gets below 0 65 * the connected conns are "offline" a little bit 66 * 67 * the problem: 68 * we somehow have to lose our "we are writable" signal on the way. 69 * 70 */ 71 off_t *global_bytes_per_second_cnt_ptr; /* */ 72 73 const buffer *error_handler; 74 const buffer *error_handler_404; 75 const buffer *errorfile_prefix; 76 struct log_error_st *serrh; /* script errh */ 77 } request_config; 78 79 typedef struct { 80 buffer scheme; /* scheme without colon or slashes ( "http" or "https" ) */ 81 82 /* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */ 83 buffer authority; 84 85 /* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */ 86 buffer path; 87 buffer query; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */ 88 } request_uri; 89 90 typedef struct { 91 buffer path; 92 buffer basedir; /* path = "(basedir)(.*)" */ 93 94 buffer doc_root; /* path = doc_root + rel_path */ 95 buffer rel_path; 96 97 buffer etag; 98 } physical; 99 100 typedef struct { 101 off_t gw_chunked; 102 buffer b; 103 int done; 104 } response_dechunk; 105 106 /* the order of the items should be the same as they are processed 107 * read before write as we use this later e.g. <= CON_STATE_REQUEST_END */ 108 typedef enum { 109 CON_STATE_CONNECT, 110 CON_STATE_REQUEST_START, 111 CON_STATE_READ, 112 CON_STATE_REQUEST_END, 113 CON_STATE_READ_POST, 114 CON_STATE_HANDLE_REQUEST, 115 CON_STATE_RESPONSE_START, 116 CON_STATE_WRITE, 117 CON_STATE_RESPONSE_END, 118 CON_STATE_ERROR, 119 CON_STATE_CLOSE 120 } request_state_t; 121 122 struct request_st { 123 request_state_t state; /*(modules should not modify request state)*/ 124 int http_status; 125 uint32_t h2state; /*(modules should not modify request h2state)*/ 126 uint32_t h2id; 127 int32_t h2_rwin; 128 int32_t h2_swin; 129 130 http_method_t http_method; 131 http_version_t http_version; 132 133 const plugin *handler_module; 134 void **plugin_ctx; /* plugin connection specific config */ 135 connection *con; 136 137 /* config conditions (internal) */ 138 uint32_t conditional_is_valid; 139 struct cond_cache_t *cond_cache; 140 struct cond_match_t *cond_match; 141 142 request_config conf; 143 144 /* request */ 145 uint32_t rqst_htags;/* bitfield of flagged headers present in request */ 146 uint32_t rqst_header_len; 147 array rqst_headers; 148 149 request_uri uri; 150 physical physical; 151 array env; /* used to pass lighttpd internal stuff */ 152 153 off_t reqbody_length; /* request Content-Length */ 154 off_t te_chunked; 155 struct chunkqueue *reqbody_queue; /*(might use tempfiles)*/ 156 157 buffer *http_host; /* copy of array value buffer ptr; not alloc'ed */ 158 const buffer *server_name; 159 160 buffer target; 161 buffer target_orig; 162 163 buffer pathinfo; 164 buffer server_name_buf; 165 166 /* response */ 167 off_t content_length; 168 uint32_t resp_htags; /*bitfield of flagged headers present in response*/ 169 uint32_t resp_header_len; 170 array resp_headers; 171 char resp_body_finished; 172 char resp_body_started; 173 char resp_send_chunked; 174 char resp_decode_chunked; 175 char resp_header_repeated; 176 177 char loops_per_request; /* catch endless loops in a single request */ 178 char keep_alive; /* only request.c can enable it, all other just disable */ 179 char async_callback; 180 181 struct chunkqueue *write_queue; /* HTTP response queue [ file, mem ] */ 182 struct chunkqueue *read_queue; /* HTTP request queue [ mem ] */ 183 buffer *tmp_buf; /* shared; same as srv->tmp_buf */ 184 response_dechunk *gw_dechunk; 185 186 off_t bytes_written_ckpt; /* used by mod_accesslog */ 187 off_t bytes_read_ckpt; /* used by mod_accesslog */ 188 struct timespec start_hp; 189 time_t start_ts; 190 191 int error_handler_saved_status; /* error-handler */ 192 http_method_t error_handler_saved_method; /* error-handler */ 193 }; 194 195 196 typedef struct http_header_parse_ctx { 197 char *k; 198 char *v; 199 uint32_t klen; 200 uint32_t vlen; 201 uint32_t hlen; 202 int pseudo; 203 int scheme; 204 int trailers; 205 uint32_t max_request_field_size; 206 unsigned int http_parseopts; 207 } http_header_parse_ctx; 208 209 210 int http_request_validate_pseudohdrs (request_st * restrict r, int scheme, unsigned int http_parseopts); 211 int http_request_parse_header (request_st * restrict r, http_header_parse_ctx * restrict hpctx); 212 void http_request_headers_process_h2 (request_st * restrict r, int scheme_port); 213 void http_request_headers_process (request_st * restrict r, char * restrict hdrs, const unsigned short * restrict hoff, int scheme_port); 214 int http_request_parse_target(request_st *r, int scheme_port); 215 int http_request_host_normalize(buffer *b, int scheme_port); 216 int http_request_host_policy(buffer *b, unsigned int http_parseopts, int scheme_port); 217 218 #endif 219