src/http/ngx_http_core_module.h - nginx

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_HTTP_CORE_H_INCLUDED_
  6. #define _NGX_HTTP_CORE_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>
  9. #include <ngx_http.h>

  10. #if (NGX_THREADS)
  11. #include <ngx_thread_pool.h>
  12. #elif (NGX_COMPAT)
  13. typedef struct ngx_thread_pool_s  ngx_thread_pool_t;
  14. #endif


  15. #define NGX_HTTP_GZIP_PROXIED_OFF       0x0002
  16. #define NGX_HTTP_GZIP_PROXIED_EXPIRED   0x0004
  17. #define NGX_HTTP_GZIP_PROXIED_NO_CACHE  0x0008
  18. #define NGX_HTTP_GZIP_PROXIED_NO_STORE  0x0010
  19. #define NGX_HTTP_GZIP_PROXIED_PRIVATE   0x0020
  20. #define NGX_HTTP_GZIP_PROXIED_NO_LM     0x0040
  21. #define NGX_HTTP_GZIP_PROXIED_NO_ETAG   0x0080
  22. #define NGX_HTTP_GZIP_PROXIED_AUTH      0x0100
  23. #define NGX_HTTP_GZIP_PROXIED_ANY       0x0200


  24. #define NGX_HTTP_AIO_OFF                0
  25. #define NGX_HTTP_AIO_ON                 1
  26. #define NGX_HTTP_AIO_THREADS            2


  27. #define NGX_HTTP_SATISFY_ALL            0
  28. #define NGX_HTTP_SATISFY_ANY            1


  29. #define NGX_HTTP_LINGERING_OFF          0
  30. #define NGX_HTTP_LINGERING_ON           1
  31. #define NGX_HTTP_LINGERING_ALWAYS       2


  32. #define NGX_HTTP_IMS_OFF                0
  33. #define NGX_HTTP_IMS_EXACT              1
  34. #define NGX_HTTP_IMS_BEFORE             2


  35. #define NGX_HTTP_KEEPALIVE_DISABLE_NONE    0x0002
  36. #define NGX_HTTP_KEEPALIVE_DISABLE_MSIE6   0x0004
  37. #define NGX_HTTP_KEEPALIVE_DISABLE_SAFARI  0x0008


  38. #define NGX_HTTP_SERVER_TOKENS_OFF      0
  39. #define NGX_HTTP_SERVER_TOKENS_ON       1
  40. #define NGX_HTTP_SERVER_TOKENS_BUILD    2


  41. typedef struct ngx_http_location_tree_node_s  ngx_http_location_tree_node_t;
  42. typedef struct ngx_http_core_loc_conf_s  ngx_http_core_loc_conf_t;


  43. typedef struct {
  44.     struct sockaddr           *sockaddr;
  45.     socklen_t                  socklen;
  46.     ngx_str_t                  addr_text;

  47.     unsigned                   set:1;
  48.     unsigned                   default_server:1;
  49.     unsigned                   bind:1;
  50.     unsigned                   wildcard:1;
  51.     unsigned                   ssl:1;
  52.     unsigned                   http2:1;
  53.     unsigned                   quic:1;
  54. #if (NGX_HAVE_INET6)
  55.     unsigned                   ipv6only:1;
  56. #endif
  57.     unsigned                   deferred_accept:1;
  58.     unsigned                   reuseport:1;
  59.     unsigned                   so_keepalive:2;
  60.     unsigned                   proxy_protocol:1;

  61.     int                        backlog;
  62.     int                        rcvbuf;
  63.     int                        sndbuf;
  64.     int                        type;
  65.     int                        protocol;
  66. #if (NGX_HAVE_SETFIB)
  67.     int                        setfib;
  68. #endif
  69. #if (NGX_HAVE_TCP_FASTOPEN)
  70.     int                        fastopen;
  71. #endif
  72. #if (NGX_HAVE_KEEPALIVE_TUNABLE)
  73.     int                        tcp_keepidle;
  74.     int                        tcp_keepintvl;
  75.     int                        tcp_keepcnt;
  76. #endif

  77. #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
  78.     char                      *accept_filter;
  79. #endif
  80. } ngx_http_listen_opt_t;


  81. typedef enum {
  82.     NGX_HTTP_POST_READ_PHASE = 0,

  83.     NGX_HTTP_SERVER_REWRITE_PHASE,

  84.     NGX_HTTP_FIND_CONFIG_PHASE,
  85.     NGX_HTTP_REWRITE_PHASE,
  86.     NGX_HTTP_POST_REWRITE_PHASE,

  87.     NGX_HTTP_PREACCESS_PHASE,

  88.     NGX_HTTP_ACCESS_PHASE,
  89.     NGX_HTTP_POST_ACCESS_PHASE,

  90.     NGX_HTTP_PRECONTENT_PHASE,

  91.     NGX_HTTP_CONTENT_PHASE,

  92.     NGX_HTTP_LOG_PHASE
  93. } ngx_http_phases;

  94. typedef struct ngx_http_phase_handler_s  ngx_http_phase_handler_t;

  95. typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
  96.     ngx_http_phase_handler_t *ph);

  97. struct ngx_http_phase_handler_s {
  98.     ngx_http_phase_handler_pt  checker;
  99.     ngx_http_handler_pt        handler;
  100.     ngx_uint_t                 next;
  101. };


  102. typedef struct {
  103.     ngx_http_phase_handler_t  *handlers;
  104.     ngx_uint_t                 server_rewrite_index;
  105.     ngx_uint_t                 location_rewrite_index;
  106. } ngx_http_phase_engine_t;


  107. typedef struct {
  108.     ngx_array_t                handlers;
  109. } ngx_http_phase_t;


  110. typedef struct {
  111.     ngx_array_t                servers;         /* ngx_http_core_srv_conf_t */

  112.     ngx_http_phase_engine_t    phase_engine;

  113.     ngx_hash_t                 headers_in_hash;

  114.     ngx_hash_t                 variables_hash;

  115.     ngx_array_t                variables;         /* ngx_http_variable_t */
  116.     ngx_array_t                prefix_variables;  /* ngx_http_variable_t */
  117.     ngx_uint_t                 ncaptures;

  118.     ngx_uint_t                 server_names_hash_max_size;
  119.     ngx_uint_t                 server_names_hash_bucket_size;

  120.     ngx_uint_t                 variables_hash_max_size;
  121.     ngx_uint_t                 variables_hash_bucket_size;

  122.     ngx_hash_keys_arrays_t    *variables_keys;

  123.     ngx_array_t               *ports;

  124.     ngx_http_phase_t           phases[NGX_HTTP_LOG_PHASE + 1];
  125. } ngx_http_core_main_conf_t;


  126. typedef struct {
  127.     /* array of the ngx_http_server_name_t, "server_name" directive */
  128.     ngx_array_t                 server_names;

  129.     /* server ctx */
  130.     ngx_http_conf_ctx_t        *ctx;

  131.     u_char                     *file_name;
  132.     ngx_uint_t                  line;

  133.     ngx_str_t                   server_name;

  134.     size_t                      connection_pool_size;
  135.     size_t                      request_pool_size;
  136.     size_t                      client_header_buffer_size;

  137.     ngx_bufs_t                  large_client_header_buffers;

  138.     ngx_msec_t                  client_header_timeout;

  139.     ngx_uint_t                  max_headers;

  140.     ngx_flag_t                  ignore_invalid_headers;
  141.     ngx_flag_t                  merge_slashes;
  142.     ngx_flag_t                  underscores_in_headers;

  143.     unsigned                    listen:1;
  144. #if (NGX_PCRE)
  145.     unsigned                    captures:1;
  146. #endif
  147.     unsigned                    allow_connect:1;

  148.     ngx_http_core_loc_conf_t  **named_locations;
  149. } ngx_http_core_srv_conf_t;


  150. /* list of structures to find core_srv_conf quickly at run time */


  151. typedef struct {
  152. #if (NGX_PCRE)
  153.     ngx_http_regex_t          *regex;
  154. #endif
  155.     ngx_http_core_srv_conf_t  *server;   /* virtual name server conf */
  156.     ngx_str_t                  name;
  157. } ngx_http_server_name_t;


  158. typedef struct {
  159.     ngx_hash_combined_t        names;

  160.     ngx_uint_t                 nregex;
  161.     ngx_http_server_name_t    *regex;
  162. } ngx_http_virtual_names_t;


  163. struct ngx_http_addr_conf_s {
  164.     /* the default server configuration for this address:port */
  165.     ngx_http_core_srv_conf_t  *default_server;

  166.     ngx_http_virtual_names_t  *virtual_names;

  167.     unsigned                   ssl:1;
  168.     unsigned                   http2:1;
  169.     unsigned                   quic:1;
  170.     unsigned                   proxy_protocol:1;
  171. };


  172. typedef struct {
  173.     in_addr_t                  addr;
  174.     ngx_http_addr_conf_t       conf;
  175. } ngx_http_in_addr_t;


  176. #if (NGX_HAVE_INET6)

  177. typedef struct {
  178.     struct in6_addr            addr6;
  179.     ngx_http_addr_conf_t       conf;
  180. } ngx_http_in6_addr_t;

  181. #endif


  182. typedef struct {
  183.     /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
  184.     void                      *addrs;
  185.     ngx_uint_t                 naddrs;
  186. } ngx_http_port_t;


  187. typedef struct {
  188.     ngx_int_t                  family;
  189.     ngx_int_t                  type;
  190.     in_port_t                  port;
  191.     ngx_array_t                addrs;     /* array of ngx_http_conf_addr_t */
  192. } ngx_http_conf_port_t;


  193. typedef struct {
  194.     ngx_http_listen_opt_t      opt;

  195.     unsigned                   protocols:3;
  196.     unsigned                   protocols_set:1;
  197.     unsigned                   protocols_changed:1;

  198.     ngx_hash_t                 hash;
  199.     ngx_hash_wildcard_t       *wc_head;
  200.     ngx_hash_wildcard_t       *wc_tail;

  201. #if (NGX_PCRE)
  202.     ngx_uint_t                 nregex;
  203.     ngx_http_server_name_t    *regex;
  204. #endif

  205.     /* the default server configuration for this address:port */
  206.     ngx_http_core_srv_conf_t  *default_server;
  207.     ngx_array_t                servers;  /* array of ngx_http_core_srv_conf_t */
  208. } ngx_http_conf_addr_t;


  209. typedef struct {
  210.     ngx_int_t                  status;
  211.     ngx_int_t                  overwrite;
  212.     ngx_http_complex_value_t   value;
  213.     ngx_str_t                  args;
  214. } ngx_http_err_page_t;


  215. struct ngx_http_core_loc_conf_s {
  216.     ngx_str_t     name;          /* location name */
  217.     ngx_str_t     escaped_name;

  218. #if (NGX_PCRE)
  219.     ngx_http_regex_t  *regex;
  220. #endif

  221.     unsigned      noname:1;   /* "if () {}" block or limit_except */
  222.     unsigned      lmt_excpt:1;
  223.     unsigned      named:1;

  224.     unsigned      exact_match:1;
  225.     unsigned      noregex:1;

  226.     unsigned      auto_redirect:1;
  227. #if (NGX_HTTP_GZIP)
  228.     unsigned      gzip_disable_msie6:2;
  229.     unsigned      gzip_disable_degradation:2;
  230. #endif

  231.     ngx_http_location_tree_node_t   *static_locations;
  232. #if (NGX_PCRE)
  233.     ngx_http_core_loc_conf_t       **regex_locations;
  234. #endif

  235.     /* pointer to the modules' loc_conf */
  236.     void        **loc_conf;

  237.     uint32_t      limit_except;
  238.     void        **limit_except_loc_conf;

  239.     ngx_http_handler_pt  handler;

  240.     /* location name length for inclusive location with inherited alias */
  241.     size_t        alias;
  242.     ngx_str_t     root;                    /* root, alias */
  243.     ngx_str_t     post_action;

  244.     ngx_array_t  *root_lengths;
  245.     ngx_array_t  *root_values;

  246.     ngx_array_t  *types;
  247.     ngx_hash_t    types_hash;
  248.     ngx_str_t     default_type;

  249.     off_t         client_max_body_size;    /* client_max_body_size */
  250.     off_t         directio;                /* directio */
  251.     off_t         directio_alignment;      /* directio_alignment */

  252.     size_t        client_body_buffer_size; /* client_body_buffer_size */
  253.     size_t        send_lowat;              /* send_lowat */
  254.     size_t        postpone_output;         /* postpone_output */
  255.     size_t        sendfile_max_chunk;      /* sendfile_max_chunk */
  256.     size_t        read_ahead;              /* read_ahead */
  257.     size_t        subrequest_output_buffer_size;
  258.                                            /* subrequest_output_buffer_size */

  259.     ngx_http_complex_value_t  *limit_rate; /* limit_rate */
  260.     ngx_http_complex_value_t  *limit_rate_after; /* limit_rate_after */

  261.     ngx_msec_t    client_body_timeout;     /* client_body_timeout */
  262.     ngx_msec_t    send_timeout;            /* send_timeout */
  263.     ngx_msec_t    keepalive_time;          /* keepalive_time */
  264.     ngx_msec_t    keepalive_timeout;       /* keepalive_timeout */
  265.     ngx_msec_t    keepalive_min_timeout;   /* keepalive_min_timeout */
  266.     ngx_msec_t    lingering_time;          /* lingering_time */
  267.     ngx_msec_t    lingering_timeout;       /* lingering_timeout */
  268.     ngx_msec_t    resolver_timeout;        /* resolver_timeout */
  269.     ngx_msec_t    auth_delay;              /* auth_delay */

  270.     ngx_resolver_t  *resolver;             /* resolver */

  271.     time_t        keepalive_header;        /* keepalive_timeout */

  272.     ngx_uint_t    keepalive_requests;      /* keepalive_requests */
  273.     ngx_uint_t    keepalive_disable;       /* keepalive_disable */
  274.     ngx_uint_t    satisfy;                 /* satisfy */
  275.     ngx_uint_t    lingering_close;         /* lingering_close */
  276.     ngx_uint_t    if_modified_since;       /* if_modified_since */
  277.     ngx_uint_t    max_ranges;              /* max_ranges */
  278.     ngx_uint_t    client_body_in_file_only; /* client_body_in_file_only */

  279.     ngx_flag_t    client_body_in_single_buffer;
  280.                                            /* client_body_in_singe_buffer */
  281.     ngx_flag_t    internal;                /* internal */
  282.     ngx_flag_t    sendfile;                /* sendfile */
  283.     ngx_flag_t    aio;                     /* aio */
  284.     ngx_flag_t    aio_write;               /* aio_write */
  285.     ngx_flag_t    tcp_nopush;              /* tcp_nopush */
  286.     ngx_flag_t    tcp_nodelay;             /* tcp_nodelay */
  287.     ngx_flag_t    reset_timedout_connection; /* reset_timedout_connection */
  288.     ngx_flag_t    absolute_redirect;       /* absolute_redirect */
  289.     ngx_flag_t    server_name_in_redirect; /* server_name_in_redirect */
  290.     ngx_flag_t    port_in_redirect;        /* port_in_redirect */
  291.     ngx_flag_t    msie_padding;            /* msie_padding */
  292.     ngx_flag_t    msie_refresh;            /* msie_refresh */
  293.     ngx_flag_t    log_not_found;           /* log_not_found */
  294.     ngx_flag_t    log_subrequest;          /* log_subrequest */
  295.     ngx_flag_t    recursive_error_pages;   /* recursive_error_pages */
  296.     ngx_uint_t    server_tokens;           /* server_tokens */
  297.     ngx_flag_t    chunked_transfer_encoding; /* chunked_transfer_encoding */
  298.     ngx_flag_t    etag;                    /* etag */

  299. #if (NGX_HTTP_GZIP)
  300.     ngx_flag_t    gzip_vary;               /* gzip_vary */

  301.     ngx_uint_t    gzip_http_version;       /* gzip_http_version */
  302.     ngx_uint_t    gzip_proxied;            /* gzip_proxied */

  303. #if (NGX_PCRE)
  304.     ngx_array_t  *gzip_disable;            /* gzip_disable */
  305. #endif
  306. #endif

  307. #if (NGX_THREADS || NGX_COMPAT)
  308.     ngx_thread_pool_t         *thread_pool;
  309.     ngx_http_complex_value_t  *thread_pool_value;
  310. #endif

  311. #if (NGX_HAVE_OPENAT)
  312.     ngx_uint_t    disable_symlinks;        /* disable_symlinks */
  313.     ngx_http_complex_value_t  *disable_symlinks_from;
  314. #endif

  315.     ngx_array_t  *early_hints;             /* early_hints */

  316.     ngx_array_t  *error_pages;             /* error_page */

  317.     ngx_path_t   *client_body_temp_path;   /* client_body_temp_path */

  318.     ngx_open_file_cache_t  *open_file_cache;
  319.     time_t        open_file_cache_valid;
  320.     ngx_uint_t    open_file_cache_min_uses;
  321.     ngx_flag_t    open_file_cache_errors;
  322.     ngx_flag_t    open_file_cache_events;

  323.     ngx_log_t    *error_log;

  324.     ngx_uint_t    types_hash_max_size;
  325.     ngx_uint_t    types_hash_bucket_size;

  326.     ngx_queue_t  *locations;

  327. #if 0
  328.     ngx_http_core_loc_conf_t  *prev_location;
  329. #endif
  330. };


  331. typedef struct {
  332.     ngx_queue_t                      queue;
  333.     ngx_http_core_loc_conf_t        *exact;
  334.     ngx_http_core_loc_conf_t        *inclusive;
  335.     ngx_str_t                       *name;
  336.     u_char                          *file_name;
  337.     ngx_uint_t                       line;
  338.     ngx_queue_t                      list;
  339. } ngx_http_location_queue_t;


  340. struct ngx_http_location_tree_node_s {
  341.     ngx_http_location_tree_node_t   *left;
  342.     ngx_http_location_tree_node_t   *right;
  343.     ngx_http_location_tree_node_t   *tree;

  344.     ngx_http_core_loc_conf_t        *exact;
  345.     ngx_http_core_loc_conf_t        *inclusive;

  346.     u_short                          len;
  347.     u_char                           auto_redirect;
  348.     u_char                           name[1];
  349. };


  350. void ngx_http_core_run_phases(ngx_http_request_t *r);
  351. ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
  352.     ngx_http_phase_handler_t *ph);
  353. ngx_int_t ngx_http_core_rewrite_phase(ngx_http_request_t *r,
  354.     ngx_http_phase_handler_t *ph);
  355. ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
  356.     ngx_http_phase_handler_t *ph);
  357. ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
  358.     ngx_http_phase_handler_t *ph);
  359. ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
  360.     ngx_http_phase_handler_t *ph);
  361. ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
  362.     ngx_http_phase_handler_t *ph);
  363. ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
  364.     ngx_http_phase_handler_t *ph);


  365. void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash);
  366. ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
  367. void ngx_http_set_exten(ngx_http_request_t *r);
  368. ngx_int_t ngx_http_set_etag(ngx_http_request_t *r);
  369. void ngx_http_weak_etag(ngx_http_request_t *r);
  370. ngx_int_t ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
  371.     ngx_str_t *ct, ngx_http_complex_value_t *cv);
  372. u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
  373.     size_t *root_length, size_t reserved);
  374. ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
  375. #if (NGX_HTTP_GZIP)
  376. ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
  377. #endif


  378. ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
  379.     ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
  380.     ngx_http_post_subrequest_t *ps, ngx_uint_t flags);
  381. ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
  382.     ngx_str_t *uri, ngx_str_t *args);
  383. ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);


  384. ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);


  385. typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
  386. typedef ngx_int_t (*ngx_http_output_body_filter_pt)
  387.     (ngx_http_request_t *r, ngx_chain_t *chain);
  388. typedef ngx_int_t (*ngx_http_request_body_filter_pt)
  389.     (ngx_http_request_t *r, ngx_chain_t *chain);


  390. ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
  391. ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
  392. ngx_int_t ngx_http_request_body_save_filter(ngx_http_request_t *r,
  393.     ngx_chain_t *chain);


  394. ngx_int_t ngx_http_set_disable_symlinks(ngx_http_request_t *r,
  395.     ngx_http_core_loc_conf_t *clcf, ngx_str_t *path, ngx_open_file_info_t *of);

  396. ngx_int_t ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
  397.     ngx_table_elt_t *headers, ngx_str_t *value, ngx_array_t *proxies,
  398.     int recursive);

  399. ngx_int_t ngx_http_link_multi_headers(ngx_http_request_t *r);


  400. extern ngx_module_t  ngx_http_core_module;

  401. extern ngx_uint_t ngx_http_max_module;

  402. extern ngx_str_t  ngx_http_core_get_method;


  403. #define ngx_http_clear_content_length(r)                                      \
  404.                                                                               \
  405.     r->headers_out.content_length_n = -1;                                     \
  406.     if (r->headers_out.content_length) {                                      \
  407.         r->headers_out.content_length->hash = 0;                              \
  408.         r->headers_out.content_length = NULL;                                 \
  409.     }

  410. #define ngx_http_clear_accept_ranges(r)                                       \
  411.                                                                               \
  412.     r->allow_ranges = 0;                                                      \
  413.     if (r->headers_out.accept_ranges) {                                       \
  414.         r->headers_out.accept_ranges->hash = 0;                               \
  415.         r->headers_out.accept_ranges = NULL;                                  \
  416.     }

  417. #define ngx_http_clear_last_modified(r)                                       \
  418.                                                                               \
  419.     r->headers_out.last_modified_time = -1;                                   \
  420.     if (r->headers_out.last_modified) {                                       \
  421.         r->headers_out.last_modified->hash = 0;                               \
  422.         r->headers_out.last_modified = NULL;                                  \
  423.     }

  424. #define ngx_http_clear_location(r)                                            \
  425.                                                                               \
  426.     if (r->headers_out.location) {                                            \
  427.         r->headers_out.location->hash = 0;                                    \
  428.         r->headers_out.location = NULL;                                       \
  429.     }

  430. #define ngx_http_clear_etag(r)                                                \
  431.                                                                               \
  432.     if (r->headers_out.etag) {                                                \
  433.         r->headers_out.etag->hash = 0;                                        \
  434.         r->headers_out.etag = NULL;                                           \
  435.     }


  436. #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */