2005-02-20 14:27:00 +00:00
|
|
|
#ifndef _BASE_H_
|
|
|
|
#define _BASE_H_
|
2016-03-19 15:14:35 +00:00
|
|
|
#include "first.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2009-10-12 10:39:36 +00:00
|
|
|
#include "settings.h"
|
2009-10-11 14:31:42 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
2009-10-11 14:31:42 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
# include <stdint.h>
|
|
|
|
#endif
|
2009-10-11 14:31:42 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
# include <inttypes.h>
|
|
|
|
#endif
|
|
|
|
|
2017-07-31 03:42:41 +00:00
|
|
|
#include "base_decls.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "array.h"
|
|
|
|
#include "chunk.h"
|
|
|
|
#include "keyvalue.h"
|
|
|
|
#include "sys-socket.h"
|
2007-07-03 18:47:00 +00:00
|
|
|
#include "etag.h"
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2017-03-28 04:04:31 +00:00
|
|
|
struct fdevents; /* declaration */
|
2017-03-28 04:28:53 +00:00
|
|
|
struct stat_cache; /* declaration */
|
2005-08-08 08:22:06 +00:00
|
|
|
|
2005-08-08 09:48:38 +00:00
|
|
|
#ifndef O_BINARY
|
|
|
|
# define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifndef O_LARGEFILE
|
|
|
|
# define O_LARGEFILE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SIZE_MAX
|
|
|
|
# ifdef SIZE_T_MAX
|
|
|
|
# define SIZE_MAX SIZE_T_MAX
|
|
|
|
# else
|
|
|
|
# define SIZE_MAX ((size_t)~0)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SSIZE_MAX
|
|
|
|
# define SSIZE_MAX ((size_t)~0 >> 1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <crt_externs.h>
|
|
|
|
#define environ (* _NSGetEnviron())
|
|
|
|
#else
|
|
|
|
extern char **environ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* for solaris 2.5 and NetBSD 1.3.x */
|
|
|
|
#ifndef HAVE_SOCKLEN_T
|
|
|
|
typedef int socklen_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* solaris and NetBSD 1.3.x again */
|
|
|
|
#if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
|
|
|
|
# define uint32_t u_int32_t
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SHUT_WR
|
|
|
|
# define SHUT_WR 1
|
|
|
|
#endif
|
|
|
|
|
2006-10-04 13:26:23 +00:00
|
|
|
typedef enum { T_CONFIG_UNSET,
|
|
|
|
T_CONFIG_STRING,
|
|
|
|
T_CONFIG_SHORT,
|
2009-06-21 17:25:24 +00:00
|
|
|
T_CONFIG_INT,
|
2006-10-04 13:26:23 +00:00
|
|
|
T_CONFIG_BOOLEAN,
|
|
|
|
T_CONFIG_ARRAY,
|
|
|
|
T_CONFIG_LOCAL,
|
2006-09-07 11:00:02 +00:00
|
|
|
T_CONFIG_DEPRECATED,
|
|
|
|
T_CONFIG_UNSUPPORTED
|
2005-02-20 14:27:00 +00:00
|
|
|
} config_values_type_t;
|
|
|
|
|
2006-10-04 13:26:23 +00:00
|
|
|
typedef enum { T_CONFIG_SCOPE_UNSET,
|
|
|
|
T_CONFIG_SCOPE_SERVER,
|
2005-02-20 14:27:00 +00:00
|
|
|
T_CONFIG_SCOPE_CONNECTION
|
|
|
|
} config_scope_type_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *key;
|
|
|
|
void *destination;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
config_values_type_t type;
|
|
|
|
config_scope_type_t scope;
|
|
|
|
} config_values_t;
|
|
|
|
|
|
|
|
typedef enum { DIRECT, EXTERNAL } connection_type;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *key;
|
|
|
|
connection_type type;
|
|
|
|
char *value;
|
|
|
|
} request_handler;
|
|
|
|
|
|
|
|
|
2017-07-31 03:42:41 +00:00
|
|
|
union sock_addr {
|
2005-02-20 14:27:00 +00:00
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
struct sockaddr_in6 ipv6;
|
|
|
|
#endif
|
|
|
|
struct sockaddr_in ipv4;
|
2005-11-23 10:46:21 +00:00
|
|
|
#ifdef HAVE_SYS_UN_H
|
|
|
|
struct sockaddr_un un;
|
|
|
|
#endif
|
2005-02-20 14:27:00 +00:00
|
|
|
struct sockaddr plain;
|
2017-07-31 03:42:41 +00:00
|
|
|
};
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
/* fcgi_response_header contains ... */
|
|
|
|
#define HTTP_STATUS BV(0)
|
|
|
|
#define HTTP_CONNECTION BV(1)
|
|
|
|
#define HTTP_CONTENT_LENGTH BV(2)
|
|
|
|
#define HTTP_DATE BV(3)
|
|
|
|
#define HTTP_LOCATION BV(4)
|
2017-02-05 01:33:45 +00:00
|
|
|
#define HTTP_TRANSFER_ENCODING BV(5)
|
[mod_proxy] simple host/url mapping in headers (fixes #152)
Provide a simple mechanism for mapping host and urlpath header strings
in proxied request and response well-known headers. This *is not*
intended as a one-size-fits-all, infinitely extensible, regex rewriting
engine. Instead, the proxy.header directive aims to provide built-in
functionality in mod_proxy for a few common use cases by performing
simple host matching or urlpath prefix matching, and using the
mapping of the first match. More complex use cases could possibly be
handled by a custom lighttpd module (which does not currently exist).
Note: the contents of the HTTP request-line and HTTP headers may or
may not be in normalized canonical forms, which may or may not influence
the simple matching performed. Admins should take care to provide safe
defaults (fail closed) if mapping is expected to occur and blindly
passing non-mapped requests is undesirable.
proxy.header = (
#"map-host-request" => (
#"-" => "...",#replace provided given Host request authority
#"..." => "-",#preserve existing authority (no further matching)
#"..." => "", #preserve existing authority (no further matching)
# #(equivalent to "xxx" => "xxx")
#"xxx" => "yyy", #map one string ("xxx") to another ("yyy")
#),
#"map-host-response" => (
#"-" => "...",#replace authority used in backend request
#"..." => "-",#replace with original authority
#"..." => "", #preserve existing authority (no further matching)
# #(equivalent to "xxx" => "xxx")
#"xxx" => "yyy", #map one string ("xxx") to another ("yyy")
#),
#"map-urlpath" => (
#"/xxx" => "/yyy",#map one urlpath prefix to another
#"/xxx/" => "/", #map one urlpath prefix to another
#"/xxx" => "", #map one urlpath prefix to another
#"/key" => "/value",
# Note: request headers have matching "key" prefix replaced with
# "value", and response headers have matching "value" prefix
# replaced with "key", with a pre-test of the "value" from the
# first-matched "key" in request headers (if there was a match)
#),
#"https-remap" => "enable",
# For https requests from client, map https:// to http://
# when map-host-request matches URI in request, and map http://
# to https:// when map-host-response matches URI in response.
# (mod_proxy currently sends all backend requests as http)
)
x-ref:
"feature to remove part of the URI when passing along requests..."
https://redmine.lighttpd.net/issues/152
2017-04-28 22:53:08 +00:00
|
|
|
#define HTTP_CONTENT_LOCATION BV(6)
|
|
|
|
#define HTTP_SET_COOKIE BV(7)
|
2017-05-06 05:23:37 +00:00
|
|
|
#define HTTP_UPGRADE BV(8)
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/** HEADER */
|
|
|
|
/* the request-line */
|
|
|
|
buffer *request;
|
|
|
|
buffer *uri;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *orig_uri;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
http_method_t http_method;
|
|
|
|
http_version_t http_version;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *request_line;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* strings to the header */
|
|
|
|
buffer *http_host; /* not alloced */
|
|
|
|
const char *http_range;
|
|
|
|
const char *http_content_type;
|
|
|
|
const char *http_if_modified_since;
|
|
|
|
const char *http_if_none_match;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
array *headers;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* CONTENT */
|
2016-12-16 16:06:29 +00:00
|
|
|
off_t content_length; /* returned by strtoll() */
|
|
|
|
off_t te_chunked;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* internal representation */
|
|
|
|
int accept_encoding;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* internal */
|
|
|
|
buffer *pathinfo;
|
|
|
|
} request;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
off_t content_length;
|
|
|
|
int keep_alive; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
array *headers;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
|
|
|
enum {
|
2005-02-20 14:27:00 +00:00
|
|
|
HTTP_TRANSFER_ENCODING_IDENTITY, HTTP_TRANSFER_ENCODING_CHUNKED
|
|
|
|
} transfer_encoding;
|
|
|
|
} response;
|
|
|
|
|
|
|
|
typedef struct {
|
2009-04-09 16:51:44 +00:00
|
|
|
buffer *scheme; /* scheme without colon or slashes ( "http" or "https" ) */
|
|
|
|
|
|
|
|
/* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *authority;
|
2009-04-09 16:51:44 +00:00
|
|
|
|
|
|
|
/* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *path;
|
2009-04-09 16:51:44 +00:00
|
|
|
buffer *path_raw; /* raw path, as sent from client. no urldecoding or path simplifying */
|
|
|
|
buffer *query; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */
|
2005-02-20 14:27:00 +00:00
|
|
|
} request_uri;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
buffer *path;
|
2005-08-08 09:42:27 +00:00
|
|
|
buffer *basedir; /* path = "(basedir)(.*)" */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *doc_root; /* path = doc_root + rel_path */
|
|
|
|
buffer *rel_path;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *etag;
|
|
|
|
} physical;
|
|
|
|
|
|
|
|
typedef struct {
|
2005-08-08 08:22:06 +00:00
|
|
|
buffer *name;
|
|
|
|
buffer *etag;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-08-08 08:22:06 +00:00
|
|
|
struct stat st;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-08-08 08:22:06 +00:00
|
|
|
time_t stat_ts;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2006-09-07 11:00:02 +00:00
|
|
|
#ifdef HAVE_LSTAT
|
|
|
|
char is_symlink;
|
|
|
|
#endif
|
|
|
|
|
2005-08-08 08:22:06 +00:00
|
|
|
#ifdef HAVE_FAM_H
|
|
|
|
int dir_version;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
buffer *content_type;
|
|
|
|
} stat_cache_entry;
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
typedef struct {
|
|
|
|
array *mimetypes;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* virtual-servers */
|
|
|
|
buffer *document_root;
|
|
|
|
buffer *server_name;
|
|
|
|
buffer *error_handler;
|
[core] server.error-handler new directive for error pages (fixes #2702)
server.error-handler preserves HTTP status error code when error page
is static, and allows dynamic handlers to change HTTP status code
when error page is provided by dynamic handler. server.error-handler
intercepts all HTTP status codes >= 400 except when the content is
generated by a dynamic handler (cgi, ssi, fastcgi, scgi, proxy, lua).
The request method is unconditionally changed to GET for the request
to service the error handler, and the original request method is
later restored (for logging purposes). request body from the
original request, if present, is discarded.
server.error-handler is somewhat similar to server.error-handler-404,
but server.error-handler-404 is now deprecated, intercepts only 404
and 403 HTTP status codes, and returns 200 OK for static error pages,
a source of confusion for some admins. On the other hand, the new
server.error-handler, when set, will intercept all HTTP status error
codes >= 400. server.error-handler takes precedence over
server.error-handler-404 when both are set.
NOTE: a major difference between server.error-handler and the
now-deprecated server.error-handler-404 is that the values of the
non-standard CGI environment variables REQUEST_URI and REDIRECT_URI
have been swapped. Since REDIRECT_STATUS is the original HTTP
status code, REDIRECT_URI is now the original request, and REQUEST_URI
is the current request (e.g. the URI/URL to the error handler).
The prior behavior -- which reversed REQUEST_URI and REDIRECT_URI values
from those described above -- is preserved for server.error-handler-404.
Additionally, REDIRECT_STATUS is now available to mod_magnet, which
continues to have access to request.uri and request.orig_uri.
See further discussion at https://redmine.lighttpd.net/issues/2702
and https://redmine.lighttpd.net/issues/1828
github: closes #36
2016-03-01 05:57:48 +00:00
|
|
|
buffer *error_handler_404;
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *server_tag;
|
2005-06-26 10:40:54 +00:00
|
|
|
buffer *dirlist_encoding;
|
2005-07-15 13:26:16 +00:00
|
|
|
buffer *errorfile_prefix;
|
2017-06-13 03:40:31 +00:00
|
|
|
buffer *socket_perms;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-07-13 00:41:53 +00:00
|
|
|
unsigned short high_precision_timestamps;
|
2005-02-20 14:27:00 +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 use_xattr;
|
|
|
|
unsigned short follow_symlink;
|
2005-07-28 21:05:16 +00:00
|
|
|
unsigned short range_requests;
|
2016-06-04 14:56:06 +00:00
|
|
|
unsigned short stream_request_body;
|
|
|
|
unsigned short stream_response_body;
|
2017-02-11 19:35:28 +00:00
|
|
|
unsigned short error_intercept;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* debug */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short log_file_not_found;
|
|
|
|
unsigned short log_request_header;
|
|
|
|
unsigned short log_request_handling;
|
|
|
|
unsigned short log_response_header;
|
2005-08-08 13:48:33 +00:00
|
|
|
unsigned short log_condition_handling;
|
2009-02-05 21:54:47 +00:00
|
|
|
unsigned short log_timeouts;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* server wide */
|
2010-08-07 13:16:16 +00:00
|
|
|
unsigned short use_ipv6, set_v6only; /* set_v6only is only a temporary option */
|
2009-04-26 17:59:55 +00:00
|
|
|
unsigned short defer_accept;
|
2013-07-31 20:23:21 +00:00
|
|
|
unsigned short ssl_enabled; /* only interesting for setting up listening sockets. don't use at runtime */
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short allow_http11;
|
2007-06-15 15:51:16 +00:00
|
|
|
unsigned short etag_use_inode;
|
|
|
|
unsigned short etag_use_mtime;
|
|
|
|
unsigned short etag_use_size;
|
2006-01-11 23:05:06 +00:00
|
|
|
unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
|
[config] opts for http header parsing strictness (fixes #551, fixes #1086, fixes #1184, fixes #2143, #2258, #2281, fixes #946, fixes #1330, fixes #602, #1016)
server.http-parseopt-header-strict = "enable"
server.http-parseopt-host-strict = "enable" (implies host-normalize)
server.http-parseopt-host-normalize = "disable"
defaults retain current behavior, which is strict header parsing
and strict host parsing, with enhancement to normalize IPv4 address
and port number strings.
For lighttpd tests, these need to be enabled (and are by default)
For marginally faster HTTP header parsing for benchmarks, disable these.
To allow
- underscores in hostname
- hypen ('-') at beginning of hostname
- all-numeric TLDs
server.http-parseopt-host-strict = "disable"
x-ref:
"lighttpd doesn't allow underscores in host names"
https://redmine.lighttpd.net/issues/551
"hyphen in hostname"
https://redmine.lighttpd.net/issues/1086
"a numeric tld"
https://redmine.lighttpd.net/issues/1184
"Numeric tld's"
https://redmine.lighttpd.net/issues/2143
"Bad Request"
https://redmine.lighttpd.net/issues/2258
"400 Bad Request when using Numeric TLDs"
https://redmine.lighttpd.net/issues/2281
To allow a variety of numerical formats to be converted to IP addresses
server.http-parseopt-host-strict = "disable"
server.http-parseopt-host-normalize = "enable"
x-ref:
"URL encoding leads to "400 - Bad Request""
https://redmine.lighttpd.net/issues/946
"400 Bad Request when using IP's numeric value ("ip2long()")"
https://redmine.lighttpd.net/issues/1330
To allow most 8-bit and 7-bit chars in headers
server.http-parseopt-header-strict = "disable" (not recommended)
x-ref:
"Russian letters not alowed?"
https://redmine.lighttpd.net/issues/602
"header Content-Disposition with russian '?' (CP1251, ascii code 255) causes error"
https://redmine.lighttpd.net/issues/1016
2016-05-18 09:42:42 +00:00
|
|
|
unsigned int http_parseopts;
|
2009-06-21 17:25:30 +00:00
|
|
|
unsigned int max_request_size;
|
2016-03-30 20:17:17 +00:00
|
|
|
int listen_backlog;
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
unsigned short kbytes_per_second; /* connection kb/s limit */
|
|
|
|
|
|
|
|
/* configside */
|
|
|
|
unsigned short global_kbytes_per_second; /* */
|
|
|
|
|
2006-10-04 13:26:23 +00:00
|
|
|
off_t global_bytes_per_second_cnt;
|
2005-02-20 14:27:00 +00:00
|
|
|
/* server-wide traffic-shaper
|
2006-10-04 13:26:23 +00:00
|
|
|
*
|
2005-02-20 14:27:00 +00:00
|
|
|
* each context has the counter which is inited once
|
|
|
|
* a second by the global_kbytes_per_second config-var
|
|
|
|
*
|
|
|
|
* as soon as global_kbytes_per_second gets below 0
|
|
|
|
* the connected conns are "offline" a little bit
|
|
|
|
*
|
|
|
|
* the problem:
|
2006-10-04 13:26:23 +00:00
|
|
|
* we somehow have to loose our "we are writable" signal
|
2005-02-20 14:27:00 +00:00
|
|
|
* on the way.
|
2006-10-04 13:26:23 +00:00
|
|
|
*
|
2005-02-20 14:27:00 +00:00
|
|
|
*/
|
|
|
|
off_t *global_bytes_per_second_cnt_ptr; /* */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2016-06-04 17:47:27 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) \
|
2016-08-20 18:15:14 +00:00
|
|
|
|| defined(__OpenBSD__) || defined(__DragonFly__)
|
2016-06-04 17:47:27 +00:00
|
|
|
buffer *bsd_accept_filter;
|
|
|
|
#endif
|
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
} specific_config;
|
|
|
|
|
2006-01-04 23:28:09 +00:00
|
|
|
/* the order of the items should be the same as they are processed
|
|
|
|
* read before write as we use this later */
|
2006-10-04 13:26:23 +00:00
|
|
|
typedef enum {
|
|
|
|
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
|
2006-01-04 23:28:09 +00:00
|
|
|
} connection_state_t;
|
2005-02-20 14:27:00 +00:00
|
|
|
|
2016-02-21 18:32:14 +00:00
|
|
|
typedef enum {
|
|
|
|
/* condition not active at the moment because itself or some
|
|
|
|
* pre-condition depends on data not available yet
|
|
|
|
*/
|
|
|
|
COND_RESULT_UNSET,
|
|
|
|
|
|
|
|
/* special "unset" for branches not selected due to pre-conditions
|
|
|
|
* not met (but pre-conditions are not "unset" anymore)
|
|
|
|
*/
|
|
|
|
COND_RESULT_SKIP,
|
|
|
|
|
|
|
|
/* actually evaluated the condition itself */
|
|
|
|
COND_RESULT_FALSE, /* not active */
|
|
|
|
COND_RESULT_TRUE, /* active */
|
|
|
|
} cond_result_t;
|
|
|
|
|
2005-08-09 06:42:33 +00:00
|
|
|
typedef struct {
|
2016-02-21 18:32:14 +00:00
|
|
|
/* current result (with preconditions) */
|
2005-08-09 06:42:33 +00:00
|
|
|
cond_result_t result;
|
2016-02-21 18:32:14 +00:00
|
|
|
/* result without preconditions (must never be "skip") */
|
|
|
|
cond_result_t local_result;
|
2005-08-09 06:42:33 +00:00
|
|
|
int patterncount;
|
|
|
|
int matches[3 * 10];
|
|
|
|
buffer *comp_value; /* just a pointer */
|
|
|
|
} cond_cache_t;
|
|
|
|
|
2017-07-31 03:42:41 +00:00
|
|
|
struct connection {
|
2005-02-20 14:27:00 +00:00
|
|
|
connection_state_t state;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* timestamps */
|
|
|
|
time_t read_idle_ts;
|
|
|
|
time_t close_timeout_ts;
|
|
|
|
time_t write_request_ts;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
time_t connection_start;
|
|
|
|
time_t request_start;
|
2016-07-13 00:41:53 +00:00
|
|
|
struct timespec request_start_hp;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
size_t request_count; /* number of requests handled in this connection */
|
2005-07-23 20:42:34 +00:00
|
|
|
size_t loops_per_request; /* to catch endless loops in a single request
|
2006-10-04 13:26:23 +00:00
|
|
|
*
|
2005-07-23 20:42:34 +00:00
|
|
|
* used by mod_rewrite, mod_fastcgi, ... and others
|
|
|
|
* this is self-protection
|
|
|
|
*/
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int fd; /* the FD for this connection */
|
|
|
|
int fde_ndx; /* index for the fdevent-handler */
|
|
|
|
int ndx; /* reverse mapping to server->connection[ndx] */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* fd states */
|
|
|
|
int is_readable;
|
|
|
|
int is_writable;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2009-10-11 13:16:03 +00:00
|
|
|
int keep_alive; /* only request.c can enable it, all other just disable */
|
|
|
|
int keep_alive_idle; /* remember max_keep_alive_idle from config */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int file_started;
|
|
|
|
int file_finished;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-09-26 08:56:39 +00:00
|
|
|
chunkqueue *write_queue; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
|
|
|
|
chunkqueue *read_queue; /* a small queue for low-level read ( HTTP request ) [ mem ] */
|
|
|
|
chunkqueue *request_content_queue; /* takes request-content into tempfile if necessary [ tempfile, mem ]*/
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int traffic_limit_reached;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
off_t bytes_written; /* used by mod_accesslog, mod_rrd */
|
|
|
|
off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */
|
|
|
|
off_t bytes_read; /* used by mod_accesslog, mod_rrd */
|
|
|
|
off_t bytes_header;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int http_status;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
sock_addr dst_addr;
|
2005-08-09 06:42:33 +00:00
|
|
|
buffer *dst_addr_buf;
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
/* request */
|
|
|
|
buffer *parse_request;
|
|
|
|
unsigned int parsed_response; /* bitfield which contains the important header-fields of the parsed response header */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
request request;
|
|
|
|
request_uri uri;
|
2006-10-04 13:26:23 +00:00
|
|
|
physical physical;
|
2005-02-20 14:27:00 +00:00
|
|
|
response response;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
size_t header_len;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
array *environment; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
connection_type mode;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
void **plugin_ctx; /* plugin connection specific config */
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
specific_config conf; /* global connection specific config */
|
2005-08-09 06:42:33 +00:00
|
|
|
cond_cache_t *cond_cache;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *server_name;
|
2017-04-06 01:37:10 +00:00
|
|
|
buffer *proto;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* error-handler */
|
|
|
|
int error_handler_saved_status;
|
[core] server.error-handler new directive for error pages (fixes #2702)
server.error-handler preserves HTTP status error code when error page
is static, and allows dynamic handlers to change HTTP status code
when error page is provided by dynamic handler. server.error-handler
intercepts all HTTP status codes >= 400 except when the content is
generated by a dynamic handler (cgi, ssi, fastcgi, scgi, proxy, lua).
The request method is unconditionally changed to GET for the request
to service the error handler, and the original request method is
later restored (for logging purposes). request body from the
original request, if present, is discarded.
server.error-handler is somewhat similar to server.error-handler-404,
but server.error-handler-404 is now deprecated, intercepts only 404
and 403 HTTP status codes, and returns 200 OK for static error pages,
a source of confusion for some admins. On the other hand, the new
server.error-handler, when set, will intercept all HTTP status error
codes >= 400. server.error-handler takes precedence over
server.error-handler-404 when both are set.
NOTE: a major difference between server.error-handler and the
now-deprecated server.error-handler-404 is that the values of the
non-standard CGI environment variables REQUEST_URI and REDIRECT_URI
have been swapped. Since REDIRECT_STATUS is the original HTTP
status code, REDIRECT_URI is now the original request, and REQUEST_URI
is the current request (e.g. the URI/URL to the error handler).
The prior behavior -- which reversed REQUEST_URI and REDIRECT_URI values
from those described above -- is preserved for server.error-handler-404.
Additionally, REDIRECT_STATUS is now available to mod_magnet, which
continues to have access to request.uri and request.orig_uri.
See further discussion at https://redmine.lighttpd.net/issues/2702
and https://redmine.lighttpd.net/issues/1828
github: closes #36
2016-03-01 05:57:48 +00:00
|
|
|
http_method_t error_handler_saved_method;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2013-07-31 20:23:21 +00:00
|
|
|
struct server_socket *srv_socket; /* reference to the server-socket */
|
2016-12-21 02:57:08 +00:00
|
|
|
int (* network_write)(struct server *srv, struct connection *con, chunkqueue *cq, off_t max_bytes);
|
|
|
|
int (* network_read)(struct server *srv, struct connection *con, chunkqueue *cq, off_t max_bytes);
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2007-07-03 18:47:00 +00:00
|
|
|
/* etag handling */
|
|
|
|
etag_flags_t etag_flags;
|
2007-08-18 09:27:11 +00:00
|
|
|
|
|
|
|
int conditional_is_valid[COMP_LAST_ELEMENT];
|
2017-07-31 03:42:41 +00:00
|
|
|
};
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
connection **ptr;
|
|
|
|
size_t size;
|
|
|
|
size_t used;
|
|
|
|
} connections;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
buffer *uri;
|
|
|
|
time_t mtime;
|
|
|
|
int http_status;
|
|
|
|
} realpath_cache_type;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
time_t mtime; /* the key */
|
|
|
|
buffer *str; /* a buffer for the string represenation */
|
|
|
|
} mtime_cache_type;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
void *ptr;
|
|
|
|
size_t used;
|
|
|
|
size_t size;
|
|
|
|
} buffer_plugin;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned short port;
|
|
|
|
buffer *bindhost;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-26 08:26:28 +00:00
|
|
|
buffer *errorlog_file;
|
|
|
|
unsigned short errorlog_use_syslog;
|
2009-06-21 17:25:39 +00:00
|
|
|
buffer *breakagelog_file;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short dont_daemonize;
|
2016-03-26 13:39:54 +00:00
|
|
|
unsigned short preflight_check;
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *changeroot;
|
|
|
|
buffer *username;
|
|
|
|
buffer *groupname;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *pid_file;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *event_handler;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-08-27 14:43:45 +00:00
|
|
|
buffer *modules_dir;
|
2005-10-31 15:34:00 +00:00
|
|
|
buffer *network_backend;
|
2005-02-20 14:27:00 +00:00
|
|
|
array *modules;
|
2005-11-01 07:50:08 +00:00
|
|
|
array *upload_tempdirs;
|
2015-11-07 12:51:14 +00:00
|
|
|
unsigned int upload_temp_file_size;
|
2016-10-06 04:16:06 +00:00
|
|
|
unsigned int max_request_field_size;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short max_worker;
|
|
|
|
unsigned short max_fds;
|
2005-08-31 09:16:18 +00:00
|
|
|
unsigned short max_conns;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short log_request_header_on_error;
|
|
|
|
unsigned short log_state_handling;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
|
|
|
enum { STAT_CACHE_ENGINE_UNSET,
|
|
|
|
STAT_CACHE_ENGINE_NONE,
|
2009-03-07 13:54:10 +00:00
|
|
|
STAT_CACHE_ENGINE_SIMPLE
|
2007-02-19 13:55:07 +00:00
|
|
|
#ifdef HAVE_FAM_H
|
2009-03-07 13:54:10 +00:00
|
|
|
, STAT_CACHE_ENGINE_FAM
|
2007-02-19 13:55:07 +00:00
|
|
|
#endif
|
2005-08-08 08:22:06 +00:00
|
|
|
} stat_cache_engine;
|
2005-12-15 14:30:46 +00:00
|
|
|
unsigned short enable_cores;
|
2009-02-04 15:16:29 +00:00
|
|
|
unsigned short reject_expect_100_with_417;
|
2016-03-26 13:49:43 +00:00
|
|
|
buffer *xattr_name;
|
[config] opts for http header parsing strictness (fixes #551, fixes #1086, fixes #1184, fixes #2143, #2258, #2281, fixes #946, fixes #1330, fixes #602, #1016)
server.http-parseopt-header-strict = "enable"
server.http-parseopt-host-strict = "enable" (implies host-normalize)
server.http-parseopt-host-normalize = "disable"
defaults retain current behavior, which is strict header parsing
and strict host parsing, with enhancement to normalize IPv4 address
and port number strings.
For lighttpd tests, these need to be enabled (and are by default)
For marginally faster HTTP header parsing for benchmarks, disable these.
To allow
- underscores in hostname
- hypen ('-') at beginning of hostname
- all-numeric TLDs
server.http-parseopt-host-strict = "disable"
x-ref:
"lighttpd doesn't allow underscores in host names"
https://redmine.lighttpd.net/issues/551
"hyphen in hostname"
https://redmine.lighttpd.net/issues/1086
"a numeric tld"
https://redmine.lighttpd.net/issues/1184
"Numeric tld's"
https://redmine.lighttpd.net/issues/2143
"Bad Request"
https://redmine.lighttpd.net/issues/2258
"400 Bad Request when using Numeric TLDs"
https://redmine.lighttpd.net/issues/2281
To allow a variety of numerical formats to be converted to IP addresses
server.http-parseopt-host-strict = "disable"
server.http-parseopt-host-normalize = "enable"
x-ref:
"URL encoding leads to "400 - Bad Request""
https://redmine.lighttpd.net/issues/946
"400 Bad Request when using IP's numeric value ("ip2long()")"
https://redmine.lighttpd.net/issues/1330
To allow most 8-bit and 7-bit chars in headers
server.http-parseopt-header-strict = "disable" (not recommended)
x-ref:
"Russian letters not alowed?"
https://redmine.lighttpd.net/issues/602
"header Content-Disposition with russian '?' (CP1251, ascii code 255) causes error"
https://redmine.lighttpd.net/issues/1016
2016-05-18 09:42:42 +00:00
|
|
|
|
|
|
|
unsigned short http_header_strict;
|
|
|
|
unsigned short http_host_strict;
|
|
|
|
unsigned short http_host_normalize;
|
2016-07-13 00:41:53 +00:00
|
|
|
unsigned short high_precision_timestamps;
|
2016-10-19 20:09:29 +00:00
|
|
|
time_t loadts;
|
|
|
|
double loadavg[3];
|
2017-03-19 21:56:59 +00:00
|
|
|
buffer *syslog_facility;
|
2005-02-20 14:27:00 +00:00
|
|
|
} server_config;
|
|
|
|
|
2013-07-31 20:23:21 +00:00
|
|
|
typedef struct server_socket {
|
2005-02-20 14:27:00 +00:00
|
|
|
sock_addr addr;
|
|
|
|
int fd;
|
|
|
|
int fde_ndx;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
unsigned short is_ssl;
|
2016-12-22 01:23:43 +00:00
|
|
|
unsigned short sidx;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *srv_token;
|
|
|
|
} server_socket;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
server_socket **ptr;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
size_t size;
|
|
|
|
size_t used;
|
|
|
|
} server_socket_array;
|
|
|
|
|
2017-07-31 03:42:41 +00:00
|
|
|
struct server {
|
2005-02-20 14:27:00 +00:00
|
|
|
server_socket_array srv_sockets;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-26 08:26:28 +00:00
|
|
|
/* the errorlog */
|
|
|
|
int errorlog_fd;
|
2009-06-21 17:25:39 +00:00
|
|
|
enum { ERRORLOG_FILE, ERRORLOG_FD, ERRORLOG_SYSLOG, ERRORLOG_PIPE } errorlog_mode;
|
2005-07-26 08:26:28 +00:00
|
|
|
buffer *errorlog_buf;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2017-03-28 04:04:31 +00:00
|
|
|
struct fdevents *ev;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer_plugin plugins;
|
|
|
|
void *plugin_slots;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-07-26 08:26:28 +00:00
|
|
|
/* counters */
|
2005-02-20 14:27:00 +00:00
|
|
|
int con_opened;
|
|
|
|
int con_read;
|
|
|
|
int con_written;
|
|
|
|
int con_closed;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
int max_fds; /* max possible fds */
|
|
|
|
int cur_fds; /* currently used fds */
|
|
|
|
int want_fds; /* waiting fds */
|
|
|
|
int sockets_disabled;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-11-17 14:38:50 +00:00
|
|
|
size_t max_conns;
|
2005-08-31 09:16:18 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* buffers */
|
|
|
|
buffer *parse_full_path;
|
|
|
|
buffer *response_header;
|
|
|
|
buffer *response_range;
|
|
|
|
buffer *tmp_buf;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *tmp_chunk_len;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-09-29 14:42:35 +00:00
|
|
|
buffer *empty_string; /* is necessary for cond_match */
|
|
|
|
|
2005-08-15 09:55:23 +00:00
|
|
|
buffer *cond_check_buf;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* caches */
|
|
|
|
mtime_cache_type mtime_cache[FILE_CACHE_MAX];
|
|
|
|
|
|
|
|
array *split_vals;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* Timestamps */
|
|
|
|
time_t cur_ts;
|
|
|
|
time_t last_generated_date_ts;
|
|
|
|
time_t last_generated_debug_ts;
|
|
|
|
time_t startup_ts;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
buffer *ts_debug_str;
|
|
|
|
buffer *ts_date_str;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
/* config-file */
|
|
|
|
array *config_touched;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
array *config_context;
|
|
|
|
specific_config **config_storage;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
server_config srvconf;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2006-09-07 11:00:02 +00:00
|
|
|
short int config_deprecated;
|
|
|
|
short int config_unsupported;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2005-02-20 14:27:00 +00:00
|
|
|
connections *conns;
|
|
|
|
connections *joblist;
|
|
|
|
connections *fdwaitqueue;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2017-03-28 04:28:53 +00:00
|
|
|
struct stat_cache *stat_cache;
|
2006-01-02 23:15:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The status array can carry all the status information you want
|
|
|
|
* the key to the array is <module-prefix>.<name>
|
|
|
|
* and the values are counters
|
|
|
|
*
|
|
|
|
* example:
|
|
|
|
* fastcgi.backends = 10
|
|
|
|
* fastcgi.active-backends = 6
|
|
|
|
* fastcgi.backend.<key>.load = 24
|
|
|
|
* fastcgi.backend.<key>....
|
|
|
|
*
|
|
|
|
* fastcgi.backend.<key>.disconnects = ...
|
|
|
|
*/
|
|
|
|
array *status;
|
2006-10-04 13:26:23 +00:00
|
|
|
|
2017-03-28 04:04:31 +00:00
|
|
|
int event_handler;
|
2005-09-02 17:07:30 +00:00
|
|
|
|
2011-08-22 15:12:28 +00:00
|
|
|
int (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq, off_t max_bytes);
|
2016-12-21 05:07:12 +00:00
|
|
|
handler_t (* request_env)(struct server *srv, connection *con);
|
2005-10-31 15:34:00 +00:00
|
|
|
|
2005-09-02 17:07:30 +00:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2017-07-31 03:42:41 +00:00
|
|
|
};
|
2005-02-20 14:27:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|