Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_HTTP_CORE_H_INCLUDED_
0009 #define _NGX_HTTP_CORE_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 #include <ngx_http.h>
0015 
0016 #if (NGX_THREADS)
0017 #include <ngx_thread_pool.h>
0018 #elif (NGX_COMPAT)
0019 typedef struct ngx_thread_pool_s  ngx_thread_pool_t;
0020 #endif
0021 
0022 
0023 #define NGX_HTTP_GZIP_PROXIED_OFF       0x0002
0024 #define NGX_HTTP_GZIP_PROXIED_EXPIRED   0x0004
0025 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE  0x0008
0026 #define NGX_HTTP_GZIP_PROXIED_NO_STORE  0x0010
0027 #define NGX_HTTP_GZIP_PROXIED_PRIVATE   0x0020
0028 #define NGX_HTTP_GZIP_PROXIED_NO_LM     0x0040
0029 #define NGX_HTTP_GZIP_PROXIED_NO_ETAG   0x0080
0030 #define NGX_HTTP_GZIP_PROXIED_AUTH      0x0100
0031 #define NGX_HTTP_GZIP_PROXIED_ANY       0x0200
0032 
0033 
0034 #define NGX_HTTP_AIO_OFF                0
0035 #define NGX_HTTP_AIO_ON                 1
0036 #define NGX_HTTP_AIO_THREADS            2
0037 
0038 
0039 #define NGX_HTTP_SATISFY_ALL            0
0040 #define NGX_HTTP_SATISFY_ANY            1
0041 
0042 
0043 #define NGX_HTTP_LINGERING_OFF          0
0044 #define NGX_HTTP_LINGERING_ON           1
0045 #define NGX_HTTP_LINGERING_ALWAYS       2
0046 
0047 
0048 #define NGX_HTTP_IMS_OFF                0
0049 #define NGX_HTTP_IMS_EXACT              1
0050 #define NGX_HTTP_IMS_BEFORE             2
0051 
0052 
0053 #define NGX_HTTP_KEEPALIVE_DISABLE_NONE    0x0002
0054 #define NGX_HTTP_KEEPALIVE_DISABLE_MSIE6   0x0004
0055 #define NGX_HTTP_KEEPALIVE_DISABLE_SAFARI  0x0008
0056 
0057 
0058 #define NGX_HTTP_SERVER_TOKENS_OFF      0
0059 #define NGX_HTTP_SERVER_TOKENS_ON       1
0060 #define NGX_HTTP_SERVER_TOKENS_BUILD    2
0061 
0062 
0063 typedef struct ngx_http_location_tree_node_s  ngx_http_location_tree_node_t;
0064 typedef struct ngx_http_core_loc_conf_s  ngx_http_core_loc_conf_t;
0065 
0066 
0067 typedef struct {
0068     struct sockaddr           *sockaddr;
0069     socklen_t                  socklen;
0070     ngx_str_t                  addr_text;
0071 
0072     unsigned                   set:1;
0073     unsigned                   default_server:1;
0074     unsigned                   bind:1;
0075     unsigned                   wildcard:1;
0076     unsigned                   ssl:1;
0077     unsigned                   http2:1;
0078 #if (NGX_HAVE_INET6)
0079     unsigned                   ipv6only:1;
0080 #endif
0081     unsigned                   deferred_accept:1;
0082     unsigned                   reuseport:1;
0083     unsigned                   so_keepalive:2;
0084     unsigned                   proxy_protocol:1;
0085 
0086     int                        backlog;
0087     int                        rcvbuf;
0088     int                        sndbuf;
0089 #if (NGX_HAVE_SETFIB)
0090     int                        setfib;
0091 #endif
0092 #if (NGX_HAVE_TCP_FASTOPEN)
0093     int                        fastopen;
0094 #endif
0095 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
0096     int                        tcp_keepidle;
0097     int                        tcp_keepintvl;
0098     int                        tcp_keepcnt;
0099 #endif
0100 
0101 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
0102     char                      *accept_filter;
0103 #endif
0104 } ngx_http_listen_opt_t;
0105 
0106 
0107 typedef enum {
0108     NGX_HTTP_POST_READ_PHASE = 0,
0109 
0110     NGX_HTTP_SERVER_REWRITE_PHASE,
0111 
0112     NGX_HTTP_FIND_CONFIG_PHASE,
0113     NGX_HTTP_REWRITE_PHASE,
0114     NGX_HTTP_POST_REWRITE_PHASE,
0115 
0116     NGX_HTTP_PREACCESS_PHASE,
0117 
0118     NGX_HTTP_ACCESS_PHASE,
0119     NGX_HTTP_POST_ACCESS_PHASE,
0120 
0121     NGX_HTTP_PRECONTENT_PHASE,
0122 
0123     NGX_HTTP_CONTENT_PHASE,
0124 
0125     NGX_HTTP_LOG_PHASE
0126 } ngx_http_phases;
0127 
0128 typedef struct ngx_http_phase_handler_s  ngx_http_phase_handler_t;
0129 
0130 typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
0131     ngx_http_phase_handler_t *ph);
0132 
0133 struct ngx_http_phase_handler_s {
0134     ngx_http_phase_handler_pt  checker;
0135     ngx_http_handler_pt        handler;
0136     ngx_uint_t                 next;
0137 };
0138 
0139 
0140 typedef struct {
0141     ngx_http_phase_handler_t  *handlers;
0142     ngx_uint_t                 server_rewrite_index;
0143     ngx_uint_t                 location_rewrite_index;
0144 } ngx_http_phase_engine_t;
0145 
0146 
0147 typedef struct {
0148     ngx_array_t                handlers;
0149 } ngx_http_phase_t;
0150 
0151 
0152 typedef struct {
0153     ngx_array_t                servers;         /* ngx_http_core_srv_conf_t */
0154 
0155     ngx_http_phase_engine_t    phase_engine;
0156 
0157     ngx_hash_t                 headers_in_hash;
0158 
0159     ngx_hash_t                 variables_hash;
0160 
0161     ngx_array_t                variables;         /* ngx_http_variable_t */
0162     ngx_array_t                prefix_variables;  /* ngx_http_variable_t */
0163     ngx_uint_t                 ncaptures;
0164 
0165     ngx_uint_t                 server_names_hash_max_size;
0166     ngx_uint_t                 server_names_hash_bucket_size;
0167 
0168     ngx_uint_t                 variables_hash_max_size;
0169     ngx_uint_t                 variables_hash_bucket_size;
0170 
0171     ngx_hash_keys_arrays_t    *variables_keys;
0172 
0173     ngx_array_t               *ports;
0174 
0175     ngx_http_phase_t           phases[NGX_HTTP_LOG_PHASE + 1];
0176 } ngx_http_core_main_conf_t;
0177 
0178 
0179 typedef struct {
0180     /* array of the ngx_http_server_name_t, "server_name" directive */
0181     ngx_array_t                 server_names;
0182 
0183     /* server ctx */
0184     ngx_http_conf_ctx_t        *ctx;
0185 
0186     u_char                     *file_name;
0187     ngx_uint_t                  line;
0188 
0189     ngx_str_t                   server_name;
0190 
0191     size_t                      connection_pool_size;
0192     size_t                      request_pool_size;
0193     size_t                      client_header_buffer_size;
0194 
0195     ngx_bufs_t                  large_client_header_buffers;
0196 
0197     ngx_msec_t                  client_header_timeout;
0198 
0199     ngx_flag_t                  ignore_invalid_headers;
0200     ngx_flag_t                  merge_slashes;
0201     ngx_flag_t                  underscores_in_headers;
0202 
0203     unsigned                    listen:1;
0204 #if (NGX_PCRE)
0205     unsigned                    captures:1;
0206 #endif
0207 
0208     ngx_http_core_loc_conf_t  **named_locations;
0209 } ngx_http_core_srv_conf_t;
0210 
0211 
0212 /* list of structures to find core_srv_conf quickly at run time */
0213 
0214 
0215 typedef struct {
0216 #if (NGX_PCRE)
0217     ngx_http_regex_t          *regex;
0218 #endif
0219     ngx_http_core_srv_conf_t  *server;   /* virtual name server conf */
0220     ngx_str_t                  name;
0221 } ngx_http_server_name_t;
0222 
0223 
0224 typedef struct {
0225     ngx_hash_combined_t        names;
0226 
0227     ngx_uint_t                 nregex;
0228     ngx_http_server_name_t    *regex;
0229 } ngx_http_virtual_names_t;
0230 
0231 
0232 struct ngx_http_addr_conf_s {
0233     /* the default server configuration for this address:port */
0234     ngx_http_core_srv_conf_t  *default_server;
0235 
0236     ngx_http_virtual_names_t  *virtual_names;
0237 
0238     unsigned                   ssl:1;
0239     unsigned                   http2:1;
0240     unsigned                   proxy_protocol:1;
0241 };
0242 
0243 
0244 typedef struct {
0245     in_addr_t                  addr;
0246     ngx_http_addr_conf_t       conf;
0247 } ngx_http_in_addr_t;
0248 
0249 
0250 #if (NGX_HAVE_INET6)
0251 
0252 typedef struct {
0253     struct in6_addr            addr6;
0254     ngx_http_addr_conf_t       conf;
0255 } ngx_http_in6_addr_t;
0256 
0257 #endif
0258 
0259 
0260 typedef struct {
0261     /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
0262     void                      *addrs;
0263     ngx_uint_t                 naddrs;
0264 } ngx_http_port_t;
0265 
0266 
0267 typedef struct {
0268     ngx_int_t                  family;
0269     in_port_t                  port;
0270     ngx_array_t                addrs;     /* array of ngx_http_conf_addr_t */
0271 } ngx_http_conf_port_t;
0272 
0273 
0274 typedef struct {
0275     ngx_http_listen_opt_t      opt;
0276 
0277     ngx_hash_t                 hash;
0278     ngx_hash_wildcard_t       *wc_head;
0279     ngx_hash_wildcard_t       *wc_tail;
0280 
0281 #if (NGX_PCRE)
0282     ngx_uint_t                 nregex;
0283     ngx_http_server_name_t    *regex;
0284 #endif
0285 
0286     /* the default server configuration for this address:port */
0287     ngx_http_core_srv_conf_t  *default_server;
0288     ngx_array_t                servers;  /* array of ngx_http_core_srv_conf_t */
0289 } ngx_http_conf_addr_t;
0290 
0291 
0292 typedef struct {
0293     ngx_int_t                  status;
0294     ngx_int_t                  overwrite;
0295     ngx_http_complex_value_t   value;
0296     ngx_str_t                  args;
0297 } ngx_http_err_page_t;
0298 
0299 
0300 struct ngx_http_core_loc_conf_s {
0301     ngx_str_t     name;          /* location name */
0302 
0303 #if (NGX_PCRE)
0304     ngx_http_regex_t  *regex;
0305 #endif
0306 
0307     unsigned      noname:1;   /* "if () {}" block or limit_except */
0308     unsigned      lmt_excpt:1;
0309     unsigned      named:1;
0310 
0311     unsigned      exact_match:1;
0312     unsigned      noregex:1;
0313 
0314     unsigned      auto_redirect:1;
0315 #if (NGX_HTTP_GZIP)
0316     unsigned      gzip_disable_msie6:2;
0317     unsigned      gzip_disable_degradation:2;
0318 #endif
0319 
0320     ngx_http_location_tree_node_t   *static_locations;
0321 #if (NGX_PCRE)
0322     ngx_http_core_loc_conf_t       **regex_locations;
0323 #endif
0324 
0325     /* pointer to the modules' loc_conf */
0326     void        **loc_conf;
0327 
0328     uint32_t      limit_except;
0329     void        **limit_except_loc_conf;
0330 
0331     ngx_http_handler_pt  handler;
0332 
0333     /* location name length for inclusive location with inherited alias */
0334     size_t        alias;
0335     ngx_str_t     root;                    /* root, alias */
0336     ngx_str_t     post_action;
0337 
0338     ngx_array_t  *root_lengths;
0339     ngx_array_t  *root_values;
0340 
0341     ngx_array_t  *types;
0342     ngx_hash_t    types_hash;
0343     ngx_str_t     default_type;
0344 
0345     off_t         client_max_body_size;    /* client_max_body_size */
0346     off_t         directio;                /* directio */
0347     off_t         directio_alignment;      /* directio_alignment */
0348 
0349     size_t        client_body_buffer_size; /* client_body_buffer_size */
0350     size_t        send_lowat;              /* send_lowat */
0351     size_t        postpone_output;         /* postpone_output */
0352     size_t        limit_rate;              /* limit_rate */
0353     size_t        limit_rate_after;        /* limit_rate_after */
0354     size_t        sendfile_max_chunk;      /* sendfile_max_chunk */
0355     size_t        read_ahead;              /* read_ahead */
0356     size_t        subrequest_output_buffer_size;
0357                                            /* subrequest_output_buffer_size */
0358 
0359     ngx_msec_t    client_body_timeout;     /* client_body_timeout */
0360     ngx_msec_t    send_timeout;            /* send_timeout */
0361     ngx_msec_t    keepalive_timeout;       /* keepalive_timeout */
0362     ngx_msec_t    lingering_time;          /* lingering_time */
0363     ngx_msec_t    lingering_timeout;       /* lingering_timeout */
0364     ngx_msec_t    resolver_timeout;        /* resolver_timeout */
0365 
0366     ngx_resolver_t  *resolver;             /* resolver */
0367 
0368     time_t        keepalive_header;        /* keepalive_timeout */
0369 
0370     ngx_uint_t    keepalive_requests;      /* keepalive_requests */
0371     ngx_uint_t    keepalive_disable;       /* keepalive_disable */
0372     ngx_uint_t    satisfy;                 /* satisfy */
0373     ngx_uint_t    lingering_close;         /* lingering_close */
0374     ngx_uint_t    if_modified_since;       /* if_modified_since */
0375     ngx_uint_t    max_ranges;              /* max_ranges */
0376     ngx_uint_t    client_body_in_file_only; /* client_body_in_file_only */
0377 
0378     ngx_flag_t    client_body_in_single_buffer;
0379                                            /* client_body_in_singe_buffer */
0380     ngx_flag_t    internal;                /* internal */
0381     ngx_flag_t    sendfile;                /* sendfile */
0382     ngx_flag_t    aio;                     /* aio */
0383     ngx_flag_t    aio_write;               /* aio_write */
0384     ngx_flag_t    tcp_nopush;              /* tcp_nopush */
0385     ngx_flag_t    tcp_nodelay;             /* tcp_nodelay */
0386     ngx_flag_t    reset_timedout_connection; /* reset_timedout_connection */
0387     ngx_flag_t    absolute_redirect;       /* absolute_redirect */
0388     ngx_flag_t    server_name_in_redirect; /* server_name_in_redirect */
0389     ngx_flag_t    port_in_redirect;        /* port_in_redirect */
0390     ngx_flag_t    msie_padding;            /* msie_padding */
0391     ngx_flag_t    msie_refresh;            /* msie_refresh */
0392     ngx_flag_t    log_not_found;           /* log_not_found */
0393     ngx_flag_t    log_subrequest;          /* log_subrequest */
0394     ngx_flag_t    recursive_error_pages;   /* recursive_error_pages */
0395     ngx_uint_t    server_tokens;           /* server_tokens */
0396     ngx_flag_t    chunked_transfer_encoding; /* chunked_transfer_encoding */
0397     ngx_flag_t    etag;                    /* etag */
0398 
0399 #if (NGX_HTTP_GZIP)
0400     ngx_flag_t    gzip_vary;               /* gzip_vary */
0401 
0402     ngx_uint_t    gzip_http_version;       /* gzip_http_version */
0403     ngx_uint_t    gzip_proxied;            /* gzip_proxied */
0404 
0405 #if (NGX_PCRE)
0406     ngx_array_t  *gzip_disable;            /* gzip_disable */
0407 #endif
0408 #endif
0409 
0410 #if (NGX_THREADS || NGX_COMPAT)
0411     ngx_thread_pool_t         *thread_pool;
0412     ngx_http_complex_value_t  *thread_pool_value;
0413 #endif
0414 
0415 #if (NGX_HAVE_OPENAT)
0416     ngx_uint_t    disable_symlinks;        /* disable_symlinks */
0417     ngx_http_complex_value_t  *disable_symlinks_from;
0418 #endif
0419 
0420     ngx_array_t  *error_pages;             /* error_page */
0421 
0422     ngx_path_t   *client_body_temp_path;   /* client_body_temp_path */
0423 
0424     ngx_open_file_cache_t  *open_file_cache;
0425     time_t        open_file_cache_valid;
0426     ngx_uint_t    open_file_cache_min_uses;
0427     ngx_flag_t    open_file_cache_errors;
0428     ngx_flag_t    open_file_cache_events;
0429 
0430     ngx_log_t    *error_log;
0431 
0432     ngx_uint_t    types_hash_max_size;
0433     ngx_uint_t    types_hash_bucket_size;
0434 
0435     ngx_queue_t  *locations;
0436 
0437 #if 0
0438     ngx_http_core_loc_conf_t  *prev_location;
0439 #endif
0440 };
0441 
0442 
0443 typedef struct {
0444     ngx_queue_t                      queue;
0445     ngx_http_core_loc_conf_t        *exact;
0446     ngx_http_core_loc_conf_t        *inclusive;
0447     ngx_str_t                       *name;
0448     u_char                          *file_name;
0449     ngx_uint_t                       line;
0450     ngx_queue_t                      list;
0451 } ngx_http_location_queue_t;
0452 
0453 
0454 struct ngx_http_location_tree_node_s {
0455     ngx_http_location_tree_node_t   *left;
0456     ngx_http_location_tree_node_t   *right;
0457     ngx_http_location_tree_node_t   *tree;
0458 
0459     ngx_http_core_loc_conf_t        *exact;
0460     ngx_http_core_loc_conf_t        *inclusive;
0461 
0462     u_char                           auto_redirect;
0463     u_char                           len;
0464     u_char                           name[1];
0465 };
0466 
0467 
0468 void ngx_http_core_run_phases(ngx_http_request_t *r);
0469 ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
0470     ngx_http_phase_handler_t *ph);
0471 ngx_int_t ngx_http_core_rewrite_phase(ngx_http_request_t *r,
0472     ngx_http_phase_handler_t *ph);
0473 ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
0474     ngx_http_phase_handler_t *ph);
0475 ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
0476     ngx_http_phase_handler_t *ph);
0477 ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
0478     ngx_http_phase_handler_t *ph);
0479 ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
0480     ngx_http_phase_handler_t *ph);
0481 ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
0482     ngx_http_phase_handler_t *ph);
0483 
0484 
0485 void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash);
0486 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
0487 void ngx_http_set_exten(ngx_http_request_t *r);
0488 ngx_int_t ngx_http_set_etag(ngx_http_request_t *r);
0489 void ngx_http_weak_etag(ngx_http_request_t *r);
0490 ngx_int_t ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
0491     ngx_str_t *ct, ngx_http_complex_value_t *cv);
0492 u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
0493     size_t *root_length, size_t reserved);
0494 ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
0495 #if (NGX_HTTP_GZIP)
0496 ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
0497 #endif
0498 
0499 
0500 ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
0501     ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr,
0502     ngx_http_post_subrequest_t *psr, ngx_uint_t flags);
0503 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
0504     ngx_str_t *uri, ngx_str_t *args);
0505 ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);
0506 
0507 
0508 ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
0509 
0510 
0511 typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
0512 typedef ngx_int_t (*ngx_http_output_body_filter_pt)
0513     (ngx_http_request_t *r, ngx_chain_t *chain);
0514 typedef ngx_int_t (*ngx_http_request_body_filter_pt)
0515     (ngx_http_request_t *r, ngx_chain_t *chain);
0516 
0517 
0518 ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
0519 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
0520 ngx_int_t ngx_http_request_body_save_filter(ngx_http_request_t *r,
0521     ngx_chain_t *chain);
0522 
0523 
0524 ngx_int_t ngx_http_set_disable_symlinks(ngx_http_request_t *r,
0525     ngx_http_core_loc_conf_t *clcf, ngx_str_t *path, ngx_open_file_info_t *of);
0526 
0527 ngx_int_t ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
0528     ngx_array_t *headers, ngx_str_t *value, ngx_array_t *proxies,
0529     int recursive);
0530 
0531 
0532 extern ngx_module_t  ngx_http_core_module;
0533 
0534 extern ngx_uint_t ngx_http_max_module;
0535 
0536 extern ngx_str_t  ngx_http_core_get_method;
0537 
0538 
0539 #define ngx_http_clear_content_length(r)                                      \
0540                                                                               \
0541     r->headers_out.content_length_n = -1;                                     \
0542     if (r->headers_out.content_length) {                                      \
0543         r->headers_out.content_length->hash = 0;                              \
0544         r->headers_out.content_length = NULL;                                 \
0545     }
0546 
0547 #define ngx_http_clear_accept_ranges(r)                                       \
0548                                                                               \
0549     r->allow_ranges = 0;                                                      \
0550     if (r->headers_out.accept_ranges) {                                       \
0551         r->headers_out.accept_ranges->hash = 0;                               \
0552         r->headers_out.accept_ranges = NULL;                                  \
0553     }
0554 
0555 #define ngx_http_clear_last_modified(r)                                       \
0556                                                                               \
0557     r->headers_out.last_modified_time = -1;                                   \
0558     if (r->headers_out.last_modified) {                                       \
0559         r->headers_out.last_modified->hash = 0;                               \
0560         r->headers_out.last_modified = NULL;                                  \
0561     }
0562 
0563 #define ngx_http_clear_location(r)                                            \
0564                                                                               \
0565     if (r->headers_out.location) {                                            \
0566         r->headers_out.location->hash = 0;                                    \
0567         r->headers_out.location = NULL;                                       \
0568     }
0569 
0570 #define ngx_http_clear_etag(r)                                                \
0571                                                                               \
0572     if (r->headers_out.etag) {                                                \
0573         r->headers_out.etag->hash = 0;                                        \
0574         r->headers_out.etag = NULL;                                           \
0575     }
0576 
0577 
0578 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */