Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

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