2005-02-20 14:27:00 +00:00
|
|
|
#ifndef _REQUEST_H_
|
|
|
|
#define _REQUEST_H_
|
2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2021-04-28 17:18:37 +00:00
|
|
|
#include "sys-time.h" /* (struct timespec) */
|
2020-01-08 03:15:36 +00:00
|
|
|
|
2018-03-25 07:45:05 +00:00
|
|
|
#include "base_decls.h"
|
|
|
|
#include "buffer.h"
|
2020-01-06 03:08:41 +00:00
|
|
|
#include "array.h"
|
2020-09-29 20:50:39 +00:00
|
|
|
#include "chunk.h"
|
2020-01-06 03:08:41 +00:00
|
|
|
#include "http_kv.h"
|
|
|
|
|
2020-01-08 05:26:12 +00:00
|
|
|
struct chunkqueue; /* declaration */
|
2020-01-09 04:35:39 +00:00
|
|
|
struct cond_cache_t; /* declaration */
|
|
|
|
struct cond_match_t; /* declaration */
|
2021-05-04 02:18:20 +00:00
|
|
|
struct stat_cache_entry;/* declaration */
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2021-06-09 08:17:40 +00:00
|
|
|
typedef struct request_config {
|
2020-01-13 02:51:12 +00:00
|
|
|
unsigned int http_parseopts;
|
|
|
|
uint32_t max_request_field_size;
|
2020-01-06 03:08:41 +00:00
|
|
|
const array *mimetypes;
|
|
|
|
|
|
|
|
/* virtual-servers */
|
|
|
|
const buffer *document_root;
|
|
|
|
const buffer *server_name;
|
|
|
|
const buffer *server_tag;
|
2021-09-12 23:13:44 +00:00
|
|
|
fdlog_st *errh;
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
unsigned int max_request_size;
|
2020-01-06 03:08:41 +00:00
|
|
|
unsigned short max_keep_alive_requests;
|
|
|
|
unsigned short max_keep_alive_idle;
|
|
|
|
unsigned short max_read_idle;
|
|
|
|
unsigned short max_write_idle;
|
|
|
|
unsigned short stream_request_body;
|
|
|
|
unsigned short stream_response_body;
|
|
|
|
unsigned char high_precision_timestamps;
|
|
|
|
unsigned char allow_http11;
|
|
|
|
unsigned char follow_symlink;
|
|
|
|
unsigned char etag_flags;
|
|
|
|
unsigned char force_lowercase_filenames; /*(case-insensitive file systems)*/
|
|
|
|
unsigned char use_xattr;
|
|
|
|
unsigned char range_requests;
|
|
|
|
unsigned char error_intercept;
|
|
|
|
|
2020-07-21 18:15:58 +00:00
|
|
|
unsigned char h2proto; /*(global setting copied for convenient access)*/
|
|
|
|
|
2020-01-06 03:08:41 +00:00
|
|
|
/* debug */
|
|
|
|
unsigned char log_file_not_found;
|
|
|
|
unsigned char log_request_header;
|
|
|
|
unsigned char log_request_handling;
|
|
|
|
unsigned char log_response_header;
|
|
|
|
unsigned char log_condition_handling;
|
|
|
|
unsigned char log_timeouts;
|
|
|
|
unsigned char log_state_handling;
|
|
|
|
unsigned char log_request_header_on_error;
|
|
|
|
|
|
|
|
unsigned int bytes_per_second; /* connection bytes/sec limit */
|
|
|
|
unsigned int global_bytes_per_second;/*total bytes/sec limit for scope*/
|
|
|
|
|
|
|
|
/* server-wide traffic-shaper
|
|
|
|
*
|
|
|
|
* each context has the counter which is inited once
|
|
|
|
* a second by the global_bytes_per_second config-var
|
|
|
|
*
|
|
|
|
* as soon as global_bytes_per_second gets below 0
|
|
|
|
* the connected conns are "offline" a little bit
|
|
|
|
*
|
|
|
|
* the problem:
|
|
|
|
* we somehow have to lose our "we are writable" signal on the way.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
off_t *global_bytes_per_second_cnt_ptr; /* */
|
|
|
|
|
|
|
|
const buffer *error_handler;
|
|
|
|
const buffer *error_handler_404;
|
|
|
|
const buffer *errorfile_prefix;
|
2021-09-12 23:13:44 +00:00
|
|
|
fdlog_st *serrh; /* script errh */
|
2020-01-06 03:08:41 +00:00
|
|
|
} request_config;
|
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
typedef struct {
|
|
|
|
buffer scheme; /* scheme without colon or slashes ( "http" or "https" ) */
|
|
|
|
|
|
|
|
/* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */
|
|
|
|
buffer authority;
|
|
|
|
|
|
|
|
/* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */
|
|
|
|
buffer path;
|
|
|
|
buffer query; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */
|
|
|
|
} request_uri;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
buffer path;
|
|
|
|
buffer basedir; /* path = "(basedir)(.*)" */
|
|
|
|
|
|
|
|
buffer doc_root; /* path = doc_root + rel_path */
|
|
|
|
buffer rel_path;
|
|
|
|
|
|
|
|
buffer etag;
|
|
|
|
} physical;
|
|
|
|
|
2020-07-28 11:32:29 +00:00
|
|
|
typedef struct {
|
|
|
|
off_t gw_chunked;
|
|
|
|
buffer b;
|
|
|
|
int done;
|
|
|
|
} response_dechunk;
|
|
|
|
|
2020-01-10 05:17:12 +00:00
|
|
|
/* the order of the items should be the same as they are processed
|
|
|
|
* read before write as we use this later e.g. <= CON_STATE_REQUEST_END */
|
|
|
|
typedef enum {
|
2020-01-13 02:51:12 +00:00
|
|
|
CON_STATE_CONNECT,
|
|
|
|
CON_STATE_REQUEST_START,
|
|
|
|
CON_STATE_READ,
|
|
|
|
CON_STATE_REQUEST_END,
|
|
|
|
CON_STATE_READ_POST,
|
|
|
|
CON_STATE_HANDLE_REQUEST,
|
|
|
|
CON_STATE_RESPONSE_START,
|
|
|
|
CON_STATE_WRITE,
|
|
|
|
CON_STATE_RESPONSE_END,
|
|
|
|
CON_STATE_ERROR,
|
|
|
|
CON_STATE_CLOSE
|
2020-01-10 05:17:12 +00:00
|
|
|
} request_state_t;
|
|
|
|
|
2020-01-06 05:03:05 +00:00
|
|
|
struct request_st {
|
2020-01-10 05:17:12 +00:00
|
|
|
request_state_t state; /*(modules should not modify request state)*/
|
2020-01-13 02:51:12 +00:00
|
|
|
int http_status;
|
2020-08-09 20:50:37 +00:00
|
|
|
uint32_t h2state; /*(modules should not modify request h2state)*/
|
|
|
|
uint32_t h2id;
|
|
|
|
int32_t h2_rwin;
|
|
|
|
int32_t h2_swin;
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
http_method_t http_method;
|
2020-01-06 03:08:41 +00:00
|
|
|
http_version_t http_version;
|
2020-01-13 02:51:12 +00:00
|
|
|
|
|
|
|
const plugin *handler_module;
|
2020-01-09 04:53:06 +00:00
|
|
|
void **plugin_ctx; /* plugin connection specific config */
|
2020-01-13 02:51:12 +00:00
|
|
|
connection *con;
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
/* config conditions (internal) */
|
|
|
|
uint32_t conditional_is_valid;
|
|
|
|
struct cond_cache_t *cond_cache;
|
|
|
|
struct cond_match_t *cond_match;
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
request_config conf;
|
|
|
|
|
|
|
|
/* request */
|
|
|
|
uint32_t rqst_header_len;
|
2020-09-13 02:23:16 +00:00
|
|
|
uint64_t rqst_htags;/* bitfield of flagged headers present in request */
|
2020-01-13 02:51:12 +00:00
|
|
|
array rqst_headers;
|
|
|
|
|
|
|
|
request_uri uri;
|
|
|
|
physical physical;
|
|
|
|
array env; /* used to pass lighttpd internal stuff */
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-07 02:50:50 +00:00
|
|
|
off_t reqbody_length; /* request Content-Length */
|
2020-01-06 03:08:41 +00:00
|
|
|
off_t te_chunked;
|
2020-12-15 05:32:24 +00:00
|
|
|
off_t resp_body_scratchpad;
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
buffer *http_host; /* copy of array value buffer ptr; not alloc'ed */
|
|
|
|
const buffer *server_name;
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
buffer target;
|
|
|
|
buffer target_orig;
|
2020-01-08 05:26:12 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
buffer pathinfo;
|
|
|
|
buffer server_name_buf;
|
2020-01-09 04:35:39 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
/* response */
|
|
|
|
uint32_t resp_header_len;
|
2020-09-13 02:23:16 +00:00
|
|
|
uint64_t resp_htags; /*bitfield of flagged headers present in response*/
|
2020-01-13 02:51:12 +00:00
|
|
|
array resp_headers;
|
|
|
|
char resp_body_finished;
|
|
|
|
char resp_body_started;
|
|
|
|
char resp_send_chunked;
|
2020-07-28 11:32:29 +00:00
|
|
|
char resp_decode_chunked;
|
2020-08-25 10:34:47 +00:00
|
|
|
char resp_header_repeated;
|
2020-01-10 04:56:40 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
char loops_per_request; /* catch endless loops in a single request */
|
2021-02-06 13:29:41 +00:00
|
|
|
int8_t keep_alive; /* only request.c can enable it, all other just disable */
|
2020-01-13 02:51:12 +00:00
|
|
|
char async_callback;
|
|
|
|
|
|
|
|
buffer *tmp_buf; /* shared; same as srv->tmp_buf */
|
2020-07-28 11:32:29 +00:00
|
|
|
response_dechunk *gw_dechunk;
|
2020-01-10 04:56:40 +00:00
|
|
|
|
2020-07-31 07:43:19 +00:00
|
|
|
off_t bytes_written_ckpt; /* used by mod_accesslog */
|
|
|
|
off_t bytes_read_ckpt; /* used by mod_accesslog */
|
2021-07-12 18:46:49 +00:00
|
|
|
unix_timespec64_t start_hp;
|
2020-01-10 04:56:40 +00:00
|
|
|
|
2020-01-13 02:51:12 +00:00
|
|
|
int error_handler_saved_status; /* error-handler */
|
|
|
|
http_method_t error_handler_saved_method; /* error-handler */
|
2020-09-29 20:50:39 +00:00
|
|
|
|
|
|
|
struct chunkqueue write_queue; /* HTTP response queue [ file, mem ] */
|
|
|
|
struct chunkqueue read_queue; /* HTTP request queue [ mem ] */
|
|
|
|
struct chunkqueue reqbody_queue; /*(might use tempfiles)*/
|
2021-05-04 02:18:20 +00:00
|
|
|
|
|
|
|
struct stat_cache_entry *tmp_sce; /*(value valid only in sequential code)*/
|
2020-01-06 05:03:05 +00:00
|
|
|
};
|
2020-01-06 03:08:41 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2020-08-27 06:50:13 +00:00
|
|
|
typedef struct http_header_parse_ctx {
|
|
|
|
char *k;
|
|
|
|
char *v;
|
|
|
|
uint32_t klen;
|
|
|
|
uint32_t vlen;
|
|
|
|
uint32_t hlen;
|
2020-09-13 05:00:02 +00:00
|
|
|
uint8_t pseudo;
|
|
|
|
uint8_t scheme;
|
|
|
|
uint8_t trailers;
|
2021-06-14 03:11:18 +00:00
|
|
|
int8_t id;
|
2020-08-27 06:50:13 +00:00
|
|
|
uint32_t max_request_field_size;
|
|
|
|
unsigned int http_parseopts;
|
|
|
|
} http_header_parse_ctx;
|
|
|
|
|
|
|
|
|
|
|
|
int http_request_validate_pseudohdrs (request_st * restrict r, int scheme, unsigned int http_parseopts);
|
|
|
|
int http_request_parse_header (request_st * restrict r, http_header_parse_ctx * restrict hpctx);
|
|
|
|
void http_request_headers_process_h2 (request_st * restrict r, int scheme_port);
|
2020-08-09 19:02:58 +00:00
|
|
|
void http_request_headers_process (request_st * restrict r, char * restrict hdrs, const unsigned short * restrict hoff, int scheme_port);
|
2020-01-20 04:43:36 +00:00
|
|
|
int http_request_parse_target(request_st *r, int scheme_port);
|
2017-04-25 15:12:53 +00:00
|
|
|
int http_request_host_normalize(buffer *b, int scheme_port);
|
2019-12-08 23:11:15 +00:00
|
|
|
int http_request_host_policy(buffer *b, unsigned int http_parseopts, int scheme_port);
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2020-12-15 06:43:44 +00:00
|
|
|
int64_t li_restricted_strtoint64 (const char *v, const uint32_t vlen, const char ** const err);
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#endif
|