lighttpd 1.4.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
6.9 KiB

#ifndef _REQUEST_H_
#define _REQUEST_H_
#include "first.h"
#include "sys-time.h" /* (struct timespec) */
#include "base_decls.h"
#include "buffer.h"
#include "array.h"
#include "chunk.h"
#include "http_kv.h"
struct log_error_st; /* declaration */
struct chunkqueue; /* declaration */
struct cond_cache_t; /* declaration */
struct cond_match_t; /* declaration */
struct stat_cache_entry;/* declaration */
typedef struct request_config {
unsigned int http_parseopts;
uint32_t max_request_field_size;
const array *mimetypes;
/* virtual-servers */
const buffer *document_root;
const buffer *server_name;
const buffer *server_tag;
struct log_error_st *errh;
unsigned int max_request_size;
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;
unsigned char h2proto; /*(global setting copied for convenient access)*/
/* 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;
struct log_error_st *serrh; /* script errh */
} request_config;
typedef struct {
buffer scheme; /* scheme without colon or slashes ( "http" or "https" ) */
/* authority with optional portnumber ("" or "" ) 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;
typedef struct {
off_t gw_chunked;
buffer b;
int done;
} response_dechunk;
/* 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 {
} request_state_t;
struct request_st {
request_state_t state; /*(modules should not modify request state)*/
int http_status;
uint32_t h2state; /*(modules should not modify request h2state)*/
uint32_t h2id;
int32_t h2_rwin;
int32_t h2_swin;
http_method_t http_method;
http_version_t http_version;
const plugin *handler_module;
void **plugin_ctx; /* plugin connection specific config */
connection *con;
/* config conditions (internal) */
uint32_t conditional_is_valid;
struct cond_cache_t *cond_cache;
struct cond_match_t *cond_match;
request_config conf;
/* request */
uint32_t rqst_header_len;
uint64_t rqst_htags;/* bitfield of flagged headers present in request */
array rqst_headers;
request_uri uri;
physical physical;
array env; /* used to pass lighttpd internal stuff */
off_t reqbody_length; /* request Content-Length */
off_t te_chunked;
off_t resp_body_scratchpad;
buffer *http_host; /* copy of array value buffer ptr; not alloc'ed */
const buffer *server_name;
buffer target;
buffer target_orig;
buffer pathinfo;
buffer server_name_buf;
/* response */
uint32_t resp_header_len;
uint64_t resp_htags; /*bitfield of flagged headers present in response*/
array resp_headers;
char resp_body_finished;
char resp_body_started;
char resp_send_chunked;
char resp_decode_chunked;
char resp_header_repeated;
char loops_per_request; /* catch endless loops in a single request */
int8_t keep_alive; /* only request.c can enable it, all other just disable */
char async_callback;
buffer *tmp_buf; /* shared; same as srv->tmp_buf */
response_dechunk *gw_dechunk;
off_t bytes_written_ckpt; /* used by mod_accesslog */
off_t bytes_read_ckpt; /* used by mod_accesslog */
[multiple] Y2038 32-bit signed time_t mitigations Most OS platforms have already provided solutions to Y2038 32-bit signed time_t 5 - 10 years ago (or more!) Notable exceptions are Linux i686 and FreeBSD i386. Since 32-bit systems tend to be embedded systems, and since many distros take years to pick up new software, this commit aims to provide Y2038 mitigations for lighttpd running on 32-bit systems with Y2038-unsafe 32-bit signed time_t * Y2038: lighttpd 1.4.60 and later report Y2038 safety $ lighttpd -V + Y2038 support # Y2038-SAFE $ lighttpd -V - Y2038 support (unsafe 32-bit signed time_t) # Y2038-UNSAFE * Y2038: general platform info * Y2038-SAFE: lighttpd 64-bit builds on platforms using 64-bit time_t - all major 64-bit platforms (known to this author) use 64-bit time_t * Y2038-SAFE: lighttpd 32-bit builds on platforms using 64-bit time_t - Linux x32 ABI (different from i686) - FreeBSD all 32-bit and 64-bit architectures *except* 32-bit i386 - NetBSD 6.0 (released Oct 2012) all 32-bit and 64-bit architectures - OpenBSD 5.5 (released May 2014) all 32-bit and 64-bit architectures - Microsoft Windows XP and Visual Studio 2005 (? unsure ?) Another reference suggests Visual Studio 2015 defaults to 64-bit time_t - MacOS 10.15 Catalina (released 2019) drops support for 32-bit apps * Y2038-SAFE: lighttpd 32-bit builds on platforms using 32-bit unsigned time_t - e.g. OpenVMS (unknown if lighttpd builds on this platform) * Y2038-UNSAFE: lighttpd 32-bit builds on platforms using 32-bit signed time_t - Linux 32-bit (including i686) - glibc 32-bit library support not yet available for 64-bit time_t - - Linux kernel 5.6 on 32-bit platforms does support 64-bit time_t - "Note: at this point, 64-bit time support in dual-time configurations is work-in-progress, so for these configurations, the public API only makes the 32-bit time support available. In a later change, the public API will allow user code to choose the time size for a given compilation unit." - compiling with -D_TIME_BITS=64 currently has no effect - glibc recent (Jul 2021) mailing list discussion - - FreeBSD i386 - DragonFlyBSD 32-bit * Y2038 mitigations attempted on Y2038-UNSAFE platforms (32-bit signed time_t) * lighttpd prefers system monotonic clock instead of realtime clock in places where realtime clock is not required * lighttpd treats negative time_t values as after 19 Jan 2038 03:14:07 GMT * (lighttpd presumes that lighttpd will not encounter dates before 1970 during normal operation.) * lighttpd casts struct stat st.st_mtime (and st.st_*time) through uint64_t to convert negative timestamps for comparisions with 64-bit timestamps (treating negative timestamp values as after 19 Jan 2038 03:14:07 GMT) * lighttpd provides unix_time64_t (int64_t) and * lighttpd provides struct unix_timespec64 (unix_timespec64_t) (struct timespec equivalent using unix_time64_t tv_sec member) * lighttpd provides gmtime64_r() and localtime64_r() wrappers for platforms 32-bit platforms using 32-bit time_t and lighttpd temporarily shifts the year in order to use gmtime_r() and localtime_r() (or gmtime() and localtime()) from standard libraries, before readjusting year and passing struct tm to formatting functions such as strftime() * lighttpd provides TIME64_CAST() macro to cast signed 32-bit time_t to unsigned 32-bit and then to unix_time64_t * Note: while lighttpd tries handle times past 19 Jan 2038 03:14:07 GMT on 32-bit platforms using 32-bit signed time_t, underlying libraries and underlying filesystems might not behave properly after 32-bit signed time_t overflows (19 Jan 2038 03:14:08 GMT). If a given 32-bit OS does not work properly using negative time_t values, then lighttpd likely will not work properly on that system. * Other references and blogs - - -
12 months ago
unix_timespec64_t start_hp;
int error_handler_saved_status; /* error-handler */
http_method_t error_handler_saved_method; /* error-handler */
struct chunkqueue write_queue; /* HTTP response queue [ file, mem ] */
struct chunkqueue read_queue; /* HTTP request queue [ mem ] */
struct chunkqueue reqbody_queue; /*(might use tempfiles)*/
struct stat_cache_entry *tmp_sce; /*(value valid only in sequential code)*/
typedef struct http_header_parse_ctx {
char *k;
char *v;
uint32_t klen;
uint32_t vlen;
uint32_t hlen;
uint8_t pseudo;
uint8_t scheme;
uint8_t trailers;
int8_t id;
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);
void http_request_headers_process (request_st * restrict r, char * restrict hdrs, const unsigned short * restrict hoff, int scheme_port);
int http_request_parse_target(request_st *r, int scheme_port);
int http_request_host_normalize(buffer *b, int scheme_port);
int http_request_host_policy(buffer *b, unsigned int http_parseopts, int scheme_port);
int64_t li_restricted_strtoint64 (const char *v, const uint32_t vlen, const char ** const err);