src/http/ngx_http_core_module.h - nginx-1.7.10

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. #define NGX_HTTP_GZIP_PROXIED_OFF       0x0002
  11. #define NGX_HTTP_GZIP_PROXIED_EXPIRED   0x0004
  12. #define NGX_HTTP_GZIP_PROXIED_NO_CACHE  0x0008
  13. #define NGX_HTTP_GZIP_PROXIED_NO_STORE  0x0010
  14. #define NGX_HTTP_GZIP_PROXIED_PRIVATE   0x0020
  15. #define NGX_HTTP_GZIP_PROXIED_NO_LM     0x0040
  16. #define NGX_HTTP_GZIP_PROXIED_NO_ETAG   0x0080
  17. #define NGX_HTTP_GZIP_PROXIED_AUTH      0x0100
  18. #define NGX_HTTP_GZIP_PROXIED_ANY       0x0200


  19. #define NGX_HTTP_AIO_OFF                0
  20. #define NGX_HTTP_AIO_ON                 1
  21. #define NGX_HTTP_AIO_SENDFILE           2


  22. #define NGX_HTTP_SATISFY_ALL            0
  23. #define NGX_HTTP_SATISFY_ANY            1


  24. #define NGX_HTTP_LINGERING_OFF          0
  25. #define NGX_HTTP_LINGERING_ON           1
  26. #define NGX_HTTP_LINGERING_ALWAYS       2


  27. #define NGX_HTTP_IMS_OFF                0
  28. #define NGX_HTTP_IMS_EXACT              1
  29. #define NGX_HTTP_IMS_BEFORE             2


  30. #define NGX_HTTP_KEEPALIVE_DISABLE_NONE    0x0002
  31. #define NGX_HTTP_KEEPALIVE_DISABLE_MSIE6   0x0004
  32. #define NGX_HTTP_KEEPALIVE_DISABLE_SAFARI  0x0008


  33. typedef struct ngx_http_location_tree_node_s  ngx_http_location_tree_node_t;
  34. typedef struct ngx_http_core_loc_conf_s  ngx_http_core_loc_conf_t;


  35. typedef struct {
  36.     union {
  37.         struct sockaddr        sockaddr;
  38.         struct sockaddr_in     sockaddr_in;
  39. #if (NGX_HAVE_INET6)
  40.         struct sockaddr_in6    sockaddr_in6;
  41. #endif
  42. #if (NGX_HAVE_UNIX_DOMAIN)
  43.         struct sockaddr_un     sockaddr_un;
  44. #endif
  45.         u_char                 sockaddr_data[NGX_SOCKADDRLEN];
  46.     } u;

  47.     socklen_t                  socklen;

  48.     unsigned                   set:1;
  49.     unsigned                   default_server:1;
  50.     unsigned                   bind:1;
  51.     unsigned                   wildcard:1;
  52. #if (NGX_HTTP_SSL)
  53.     unsigned                   ssl:1;
  54. #endif
  55. #if (NGX_HTTP_SPDY)
  56.     unsigned                   spdy:1;
  57. #endif
  58. #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
  59.     unsigned                   ipv6only:1;
  60. #endif
  61.     unsigned                   so_keepalive:2;
  62.     unsigned                   proxy_protocol:1;

  63.     int                        backlog;
  64.     int                        rcvbuf;
  65.     int                        sndbuf;
  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. #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
  81.     ngx_uint_t                 deferred_accept;
  82. #endif

  83.     u_char                     addr[NGX_SOCKADDR_STRLEN + 1];
  84. } ngx_http_listen_opt_t;


  85. typedef enum {
  86.     NGX_HTTP_POST_READ_PHASE = 0,

  87.     NGX_HTTP_SERVER_REWRITE_PHASE,

  88.     NGX_HTTP_FIND_CONFIG_PHASE,
  89.     NGX_HTTP_REWRITE_PHASE,
  90.     NGX_HTTP_POST_REWRITE_PHASE,

  91.     NGX_HTTP_PREACCESS_PHASE,

  92.     NGX_HTTP_ACCESS_PHASE,
  93.     NGX_HTTP_POST_ACCESS_PHASE,

  94.     NGX_HTTP_TRY_FILES_PHASE,
  95.     NGX_HTTP_CONTENT_PHASE,

  96.     NGX_HTTP_LOG_PHASE
  97. } ngx_http_phases;

  98. typedef struct ngx_http_phase_handler_s  ngx_http_phase_handler_t;

  99. typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
  100.     ngx_http_phase_handler_t *ph);

  101. struct ngx_http_phase_handler_s {
  102.     ngx_http_phase_handler_pt  checker;
  103.     ngx_http_handler_pt        handler;
  104.     ngx_uint_t                 next;
  105. };


  106. typedef struct {
  107.     ngx_http_phase_handler_t  *handlers;
  108.     ngx_uint_t                 server_rewrite_index;
  109.     ngx_uint_t                 location_rewrite_index;
  110. } ngx_http_phase_engine_t;


  111. typedef struct {
  112.     ngx_array_t                handlers;
  113. } ngx_http_phase_t;


  114. typedef struct {
  115.     ngx_array_t                servers;         /* ngx_http_core_srv_conf_t */

  116.     ngx_http_phase_engine_t    phase_engine;

  117.     ngx_hash_t                 headers_in_hash;

  118.     ngx_hash_t                 variables_hash;

  119.     ngx_array_t                variables;       /* ngx_http_variable_t */
  120.     ngx_uint_t                 ncaptures;

  121.     ngx_uint_t                 server_names_hash_max_size;
  122.     ngx_uint_t                 server_names_hash_bucket_size;

  123.     ngx_uint_t                 variables_hash_max_size;
  124.     ngx_uint_t                 variables_hash_bucket_size;

  125.     ngx_hash_keys_arrays_t    *variables_keys;

  126.     ngx_array_t               *ports;

  127.     ngx_uint_t                 try_files;       /* unsigned  try_files:1 */

  128.     ngx_http_phase_t           phases[NGX_HTTP_LOG_PHASE + 1];
  129. } ngx_http_core_main_conf_t;


  130. typedef struct {
  131.     /* array of the ngx_http_server_name_t, "server_name" directive */
  132.     ngx_array_t                 server_names;

  133.     /* server ctx */
  134.     ngx_http_conf_ctx_t        *ctx;

  135.     ngx_str_t                   server_name;

  136.     size_t                      connection_pool_size;
  137.     size_t                      request_pool_size;
  138.     size_t                      client_header_buffer_size;

  139.     ngx_bufs_t                  large_client_header_buffers;

  140.     ngx_msec_t                  client_header_timeout;

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

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

  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. #if (NGX_HTTP_SSL)
  168.     unsigned                   ssl:1;
  169. #endif
  170. #if (NGX_HTTP_SPDY)
  171.     unsigned                   spdy:1;
  172. #endif
  173.     unsigned                   proxy_protocol:1;
  174. };


  175. typedef struct {
  176.     in_addr_t                  addr;
  177.     ngx_http_addr_conf_t       conf;
  178. } ngx_http_in_addr_t;


  179. #if (NGX_HAVE_INET6)

  180. typedef struct {
  181.     struct in6_addr            addr6;
  182.     ngx_http_addr_conf_t       conf;
  183. } ngx_http_in6_addr_t;

  184. #endif


  185. typedef struct {
  186.     /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
  187.     void                      *addrs;
  188.     ngx_uint_t                 naddrs;
  189. } ngx_http_port_t;


  190. typedef struct {
  191.     ngx_int_t                  family;
  192.     in_port_t                  port;
  193.     ngx_array_t                addrs;     /* array of ngx_http_conf_addr_t */
  194. } ngx_http_conf_port_t;


  195. typedef struct {
  196.     ngx_http_listen_opt_t      opt;

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

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

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


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


  214. typedef struct {
  215.     ngx_array_t               *lengths;
  216.     ngx_array_t               *values;
  217.     ngx_str_t                  name;

  218.     unsigned                   code:10;
  219.     unsigned                   test_dir:1;
  220. } ngx_http_try_file_t;


  221. struct ngx_http_core_loc_conf_s {
  222.     ngx_str_t     name;          /* location name */

  223. #if (NGX_PCRE)
  224.     ngx_http_regex_t  *regex;
  225. #endif

  226.     unsigned      noname:1;   /* "if () {}" block or limit_except */
  227.     unsigned      lmt_excpt:1;
  228.     unsigned      named:1;

  229.     unsigned      exact_match:1;
  230.     unsigned      noregex:1;

  231.     unsigned      auto_redirect:1;
  232. #if (NGX_HTTP_GZIP)
  233.     unsigned      gzip_disable_msie6:2;
  234. #if (NGX_HTTP_DEGRADATION)
  235.     unsigned      gzip_disable_degradation:2;
  236. #endif
  237. #endif

  238.     ngx_http_location_tree_node_t   *static_locations;
  239. #if (NGX_PCRE)
  240.     ngx_http_core_loc_conf_t       **regex_locations;
  241. #endif

  242.     /* pointer to the modules' loc_conf */
  243.     void        **loc_conf;

  244.     uint32_t      limit_except;
  245.     void        **limit_except_loc_conf;

  246.     ngx_http_handler_pt  handler;

  247.     /* location name length for inclusive location with inherited alias */
  248.     size_t        alias;
  249.     ngx_str_t     root;                    /* root, alias */
  250.     ngx_str_t     post_action;

  251.     ngx_array_t  *root_lengths;
  252.     ngx_array_t  *root_values;

  253.     ngx_array_t  *types;
  254.     ngx_hash_t    types_hash;
  255.     ngx_str_t     default_type;

  256.     off_t         client_max_body_size;    /* client_max_body_size */
  257.     off_t         directio;                /* directio */
  258.     off_t         directio_alignment;      /* directio_alignment */

  259.     size_t        client_body_buffer_size; /* client_body_buffer_size */
  260.     size_t        send_lowat;              /* send_lowat */
  261.     size_t        postpone_output;         /* postpone_output */
  262.     size_t        limit_rate;              /* limit_rate */
  263.     size_t        limit_rate_after;        /* limit_rate_after */
  264.     size_t        sendfile_max_chunk;      /* sendfile_max_chunk */
  265.     size_t        read_ahead;              /* read_ahead */

  266.     ngx_msec_t    client_body_timeout;     /* client_body_timeout */
  267.     ngx_msec_t    send_timeout;            /* send_timeout */
  268.     ngx_msec_t    keepalive_timeout;       /* keepalive_timeout */
  269.     ngx_msec_t    lingering_time;          /* lingering_time */
  270.     ngx_msec_t    lingering_timeout;       /* lingering_timeout */
  271.     ngx_msec_t    resolver_timeout;        /* resolver_timeout */

  272.     ngx_resolver_t  *resolver;             /* resolver */

  273.     time_t        keepalive_header;        /* keepalive_timeout */

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

  281.     ngx_flag_t    client_body_in_single_buffer;
  282.                                            /* client_body_in_singe_buffer */
  283.     ngx_flag_t    internal;                /* internal */
  284.     ngx_flag_t    sendfile;                /* sendfile */
  285. #if (NGX_HAVE_FILE_AIO)
  286.     ngx_flag_t    aio;                     /* aio */
  287. #endif
  288.     ngx_flag_t    tcp_nopush;              /* tcp_nopush */
  289.     ngx_flag_t    tcp_nodelay;             /* tcp_nodelay */
  290.     ngx_flag_t    reset_timedout_connection; /* reset_timedout_connection */
  291.     ngx_flag_t    server_name_in_redirect; /* server_name_in_redirect */
  292.     ngx_flag_t    port_in_redirect;        /* port_in_redirect */
  293.     ngx_flag_t    msie_padding;            /* msie_padding */
  294.     ngx_flag_t    msie_refresh;            /* msie_refresh */
  295.     ngx_flag_t    log_not_found;           /* log_not_found */
  296.     ngx_flag_t    log_subrequest;          /* log_subrequest */
  297.     ngx_flag_t    recursive_error_pages;   /* recursive_error_pages */
  298.     ngx_flag_t    server_tokens;           /* server_tokens */
  299.     ngx_flag_t    chunked_transfer_encoding; /* chunked_transfer_encoding */
  300.     ngx_flag_t    etag;                    /* etag */

  301. #if (NGX_HTTP_GZIP)
  302.     ngx_flag_t    gzip_vary;               /* gzip_vary */

  303.     ngx_uint_t    gzip_http_version;       /* gzip_http_version */
  304.     ngx_uint_t    gzip_proxied;            /* gzip_proxied */

  305. #if (NGX_PCRE)
  306.     ngx_array_t  *gzip_disable;            /* gzip_disable */
  307. #endif
  308. #endif

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

  313.     ngx_array_t  *error_pages;             /* error_page */
  314.     ngx_http_try_file_t    *try_files;     /* try_files */

  315.     ngx_path_t   *client_body_temp_path;   /* client_body_temp_path */

  316.     ngx_open_file_cache_t  *open_file_cache;
  317.     time_t        open_file_cache_valid;
  318.     ngx_uint_t    open_file_cache_min_uses;
  319.     ngx_flag_t    open_file_cache_errors;
  320.     ngx_flag_t    open_file_cache_events;

  321.     ngx_log_t    *error_log;

  322.     ngx_uint_t    types_hash_max_size;
  323.     ngx_uint_t    types_hash_bucket_size;

  324.     ngx_queue_t  *locations;

  325. #if 0
  326.     ngx_http_core_loc_conf_t  *prev_location;
  327. #endif
  328. };


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


  338. struct ngx_http_location_tree_node_s {
  339.     ngx_http_location_tree_node_t   *left;
  340.     ngx_http_location_tree_node_t   *right;
  341.     ngx_http_location_tree_node_t   *tree;

  342.     ngx_http_core_loc_conf_t        *exact;
  343.     ngx_http_core_loc_conf_t        *inclusive;

  344.     u_char                           auto_redirect;
  345.     u_char                           len;
  346.     u_char                           name[1];
  347. };


  348. void ngx_http_core_run_phases(ngx_http_request_t *r);
  349. ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
  350.     ngx_http_phase_handler_t *ph);
  351. ngx_int_t ngx_http_core_rewrite_phase(ngx_http_request_t *r,
  352.     ngx_http_phase_handler_t *ph);
  353. ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
  354.     ngx_http_phase_handler_t *ph);
  355. ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
  356.     ngx_http_phase_handler_t *ph);
  357. ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
  358.     ngx_http_phase_handler_t *ph);
  359. ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
  360.     ngx_http_phase_handler_t *ph);
  361. ngx_int_t ngx_http_core_try_files_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 **sr,
  380.     ngx_http_post_subrequest_t *psr, 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. ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
  389. ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);


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

  392. ngx_int_t ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
  393.     ngx_array_t *headers, ngx_str_t *value, ngx_array_t *proxies,
  394.     int recursive);


  395. extern ngx_module_t  ngx_http_core_module;

  396. extern ngx_uint_t ngx_http_max_module;

  397. extern ngx_str_t  ngx_http_core_get_method;


  398. #define ngx_http_clear_content_length(r)                                      \
  399.                                                                               \
  400.     r->headers_out.content_length_n = -1;                                     \
  401.     if (r->headers_out.content_length) {                                      \
  402.         r->headers_out.content_length->hash = 0;                              \
  403.         r->headers_out.content_length = NULL;                                 \
  404.     }

  405. #define ngx_http_clear_accept_ranges(r)                                       \
  406.                                                                               \
  407.     r->allow_ranges = 0;                                                      \
  408.     if (r->headers_out.accept_ranges) {                                       \
  409.         r->headers_out.accept_ranges->hash = 0;                               \
  410.         r->headers_out.accept_ranges = NULL;                                  \
  411.     }

  412. #define ngx_http_clear_last_modified(r)                                       \
  413.                                                                               \
  414.     r->headers_out.last_modified_time = -1;                                   \
  415.     if (r->headers_out.last_modified) {                                       \
  416.         r->headers_out.last_modified->hash = 0;                               \
  417.         r->headers_out.last_modified = NULL;                                  \
  418.     }

  419. #define ngx_http_clear_location(r)                                            \
  420.                                                                               \
  421.     if (r->headers_out.location) {                                            \
  422.         r->headers_out.location->hash = 0;                                    \
  423.         r->headers_out.location = NULL;                                       \
  424.     }

  425. #define ngx_http_clear_etag(r)                                                \
  426.                                                                               \
  427.     if (r->headers_out.etag) {                                                \
  428.         r->headers_out.etag->hash = 0;                                        \
  429.         r->headers_out.etag = NULL;                                           \
  430.     }


  431. #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */