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_UPSTREAM_H_INCLUDED_
0009 #define _NGX_HTTP_UPSTREAM_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 #include <ngx_event.h>
0015 #include <ngx_event_connect.h>
0016 #include <ngx_event_pipe.h>
0017 #include <ngx_http.h>
0018 
0019 
0020 #define NGX_HTTP_UPSTREAM_FT_ERROR           0x00000002
0021 #define NGX_HTTP_UPSTREAM_FT_TIMEOUT         0x00000004
0022 #define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER  0x00000008
0023 #define NGX_HTTP_UPSTREAM_FT_HTTP_500        0x00000010
0024 #define NGX_HTTP_UPSTREAM_FT_HTTP_502        0x00000020
0025 #define NGX_HTTP_UPSTREAM_FT_HTTP_503        0x00000040
0026 #define NGX_HTTP_UPSTREAM_FT_HTTP_504        0x00000080
0027 #define NGX_HTTP_UPSTREAM_FT_HTTP_403        0x00000100
0028 #define NGX_HTTP_UPSTREAM_FT_HTTP_404        0x00000200
0029 #define NGX_HTTP_UPSTREAM_FT_HTTP_429        0x00000400
0030 #define NGX_HTTP_UPSTREAM_FT_UPDATING        0x00000800
0031 #define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x00001000
0032 #define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x00002000
0033 #define NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT  0x00004000
0034 #define NGX_HTTP_UPSTREAM_FT_NOLIVE          0x40000000
0035 #define NGX_HTTP_UPSTREAM_FT_OFF             0x80000000
0036 
0037 #define NGX_HTTP_UPSTREAM_FT_STATUS          (NGX_HTTP_UPSTREAM_FT_HTTP_500  \
0038                                              |NGX_HTTP_UPSTREAM_FT_HTTP_502  \
0039                                              |NGX_HTTP_UPSTREAM_FT_HTTP_503  \
0040                                              |NGX_HTTP_UPSTREAM_FT_HTTP_504  \
0041                                              |NGX_HTTP_UPSTREAM_FT_HTTP_403  \
0042                                              |NGX_HTTP_UPSTREAM_FT_HTTP_404  \
0043                                              |NGX_HTTP_UPSTREAM_FT_HTTP_429)
0044 
0045 #define NGX_HTTP_UPSTREAM_INVALID_HEADER     40
0046 
0047 
0048 #define NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT    0x00000002
0049 #define NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES     0x00000004
0050 #define NGX_HTTP_UPSTREAM_IGN_EXPIRES        0x00000008
0051 #define NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL  0x00000010
0052 #define NGX_HTTP_UPSTREAM_IGN_SET_COOKIE     0x00000020
0053 #define NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE  0x00000040
0054 #define NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING   0x00000080
0055 #define NGX_HTTP_UPSTREAM_IGN_XA_CHARSET     0x00000100
0056 #define NGX_HTTP_UPSTREAM_IGN_VARY           0x00000200
0057 
0058 
0059 typedef struct {
0060     ngx_uint_t                       status;
0061     ngx_msec_t                       response_time;
0062     ngx_msec_t                       connect_time;
0063     ngx_msec_t                       header_time;
0064     off_t                            response_length;
0065     off_t                            bytes_received;
0066 
0067     ngx_str_t                       *peer;
0068 } ngx_http_upstream_state_t;
0069 
0070 
0071 typedef struct {
0072     ngx_hash_t                       headers_in_hash;
0073     ngx_array_t                      upstreams;
0074                                              /* ngx_http_upstream_srv_conf_t */
0075 } ngx_http_upstream_main_conf_t;
0076 
0077 typedef struct ngx_http_upstream_srv_conf_s  ngx_http_upstream_srv_conf_t;
0078 
0079 typedef ngx_int_t (*ngx_http_upstream_init_pt)(ngx_conf_t *cf,
0080     ngx_http_upstream_srv_conf_t *us);
0081 typedef ngx_int_t (*ngx_http_upstream_init_peer_pt)(ngx_http_request_t *r,
0082     ngx_http_upstream_srv_conf_t *us);
0083 
0084 
0085 typedef struct {
0086     ngx_http_upstream_init_pt        init_upstream;
0087     ngx_http_upstream_init_peer_pt   init;
0088     void                            *data;
0089 } ngx_http_upstream_peer_t;
0090 
0091 
0092 typedef struct {
0093     ngx_str_t                        name;
0094     ngx_addr_t                      *addrs;
0095     ngx_uint_t                       naddrs;
0096     ngx_uint_t                       weight;
0097     ngx_uint_t                       max_conns;
0098     ngx_uint_t                       max_fails;
0099     time_t                           fail_timeout;
0100     ngx_msec_t                       slow_start;
0101 
0102     unsigned                         down:1;
0103     unsigned                         backup:1;
0104 
0105     NGX_COMPAT_BEGIN(6)
0106     NGX_COMPAT_END
0107 } ngx_http_upstream_server_t;
0108 
0109 
0110 #define NGX_HTTP_UPSTREAM_CREATE        0x0001
0111 #define NGX_HTTP_UPSTREAM_WEIGHT        0x0002
0112 #define NGX_HTTP_UPSTREAM_MAX_FAILS     0x0004
0113 #define NGX_HTTP_UPSTREAM_FAIL_TIMEOUT  0x0008
0114 #define NGX_HTTP_UPSTREAM_DOWN          0x0010
0115 #define NGX_HTTP_UPSTREAM_BACKUP        0x0020
0116 #define NGX_HTTP_UPSTREAM_MAX_CONNS     0x0100
0117 
0118 
0119 struct ngx_http_upstream_srv_conf_s {
0120     ngx_http_upstream_peer_t         peer;
0121     void                           **srv_conf;
0122 
0123     ngx_array_t                     *servers;  /* ngx_http_upstream_server_t */
0124 
0125     ngx_uint_t                       flags;
0126     ngx_str_t                        host;
0127     u_char                          *file_name;
0128     ngx_uint_t                       line;
0129     in_port_t                        port;
0130     ngx_uint_t                       no_port;  /* unsigned no_port:1 */
0131 
0132 #if (NGX_HTTP_UPSTREAM_ZONE)
0133     ngx_shm_zone_t                  *shm_zone;
0134 #endif
0135 };
0136 
0137 
0138 typedef struct {
0139     ngx_addr_t                      *addr;
0140     ngx_http_complex_value_t        *value;
0141 #if (NGX_HAVE_TRANSPARENT_PROXY)
0142     ngx_uint_t                       transparent; /* unsigned  transparent:1; */
0143 #endif
0144 } ngx_http_upstream_local_t;
0145 
0146 
0147 typedef struct {
0148     ngx_http_upstream_srv_conf_t    *upstream;
0149 
0150     ngx_msec_t                       connect_timeout;
0151     ngx_msec_t                       send_timeout;
0152     ngx_msec_t                       read_timeout;
0153     ngx_msec_t                       next_upstream_timeout;
0154 
0155     size_t                           send_lowat;
0156     size_t                           buffer_size;
0157     size_t                           limit_rate;
0158 
0159     size_t                           busy_buffers_size;
0160     size_t                           max_temp_file_size;
0161     size_t                           temp_file_write_size;
0162 
0163     size_t                           busy_buffers_size_conf;
0164     size_t                           max_temp_file_size_conf;
0165     size_t                           temp_file_write_size_conf;
0166 
0167     ngx_bufs_t                       bufs;
0168 
0169     ngx_uint_t                       ignore_headers;
0170     ngx_uint_t                       next_upstream;
0171     ngx_uint_t                       store_access;
0172     ngx_uint_t                       next_upstream_tries;
0173     ngx_flag_t                       buffering;
0174     ngx_flag_t                       request_buffering;
0175     ngx_flag_t                       pass_request_headers;
0176     ngx_flag_t                       pass_request_body;
0177 
0178     ngx_flag_t                       ignore_client_abort;
0179     ngx_flag_t                       intercept_errors;
0180     ngx_flag_t                       cyclic_temp_file;
0181     ngx_flag_t                       force_ranges;
0182 
0183     ngx_path_t                      *temp_path;
0184 
0185     ngx_hash_t                       hide_headers_hash;
0186     ngx_array_t                     *hide_headers;
0187     ngx_array_t                     *pass_headers;
0188 
0189     ngx_http_upstream_local_t       *local;
0190 
0191 #if (NGX_HTTP_CACHE)
0192     ngx_shm_zone_t                  *cache_zone;
0193     ngx_http_complex_value_t        *cache_value;
0194 
0195     ngx_uint_t                       cache_min_uses;
0196     ngx_uint_t                       cache_use_stale;
0197     ngx_uint_t                       cache_methods;
0198 
0199     off_t                            cache_max_range_offset;
0200 
0201     ngx_flag_t                       cache_lock;
0202     ngx_msec_t                       cache_lock_timeout;
0203     ngx_msec_t                       cache_lock_age;
0204 
0205     ngx_flag_t                       cache_revalidate;
0206     ngx_flag_t                       cache_convert_head;
0207     ngx_flag_t                       cache_background_update;
0208 
0209     ngx_array_t                     *cache_valid;
0210     ngx_array_t                     *cache_bypass;
0211     ngx_array_t                     *cache_purge;
0212     ngx_array_t                     *no_cache;
0213 #endif
0214 
0215     ngx_array_t                     *store_lengths;
0216     ngx_array_t                     *store_values;
0217 
0218 #if (NGX_HTTP_CACHE)
0219     signed                           cache:2;
0220 #endif
0221     signed                           store:2;
0222     unsigned                         intercept_404:1;
0223     unsigned                         change_buffering:1;
0224 
0225 #if (NGX_HTTP_SSL || NGX_COMPAT)
0226     ngx_ssl_t                       *ssl;
0227     ngx_flag_t                       ssl_session_reuse;
0228 
0229     ngx_http_complex_value_t        *ssl_name;
0230     ngx_flag_t                       ssl_server_name;
0231     ngx_flag_t                       ssl_verify;
0232 #endif
0233 
0234     ngx_str_t                        module;
0235 
0236     NGX_COMPAT_BEGIN(2)
0237     NGX_COMPAT_END
0238 } ngx_http_upstream_conf_t;
0239 
0240 
0241 typedef struct {
0242     ngx_str_t                        name;
0243     ngx_http_header_handler_pt       handler;
0244     ngx_uint_t                       offset;
0245     ngx_http_header_handler_pt       copy_handler;
0246     ngx_uint_t                       conf;
0247     ngx_uint_t                       redirect;  /* unsigned   redirect:1; */
0248 } ngx_http_upstream_header_t;
0249 
0250 
0251 typedef struct {
0252     ngx_list_t                       headers;
0253 
0254     ngx_uint_t                       status_n;
0255     ngx_str_t                        status_line;
0256 
0257     ngx_table_elt_t                 *status;
0258     ngx_table_elt_t                 *date;
0259     ngx_table_elt_t                 *server;
0260     ngx_table_elt_t                 *connection;
0261 
0262     ngx_table_elt_t                 *expires;
0263     ngx_table_elt_t                 *etag;
0264     ngx_table_elt_t                 *x_accel_expires;
0265     ngx_table_elt_t                 *x_accel_redirect;
0266     ngx_table_elt_t                 *x_accel_limit_rate;
0267 
0268     ngx_table_elt_t                 *content_type;
0269     ngx_table_elt_t                 *content_length;
0270 
0271     ngx_table_elt_t                 *last_modified;
0272     ngx_table_elt_t                 *location;
0273     ngx_table_elt_t                 *accept_ranges;
0274     ngx_table_elt_t                 *www_authenticate;
0275     ngx_table_elt_t                 *transfer_encoding;
0276     ngx_table_elt_t                 *vary;
0277 
0278 #if (NGX_HTTP_GZIP)
0279     ngx_table_elt_t                 *content_encoding;
0280 #endif
0281 
0282     ngx_array_t                      cache_control;
0283     ngx_array_t                      cookies;
0284 
0285     off_t                            content_length_n;
0286     time_t                           last_modified_time;
0287 
0288     unsigned                         connection_close:1;
0289     unsigned                         chunked:1;
0290 } ngx_http_upstream_headers_in_t;
0291 
0292 
0293 typedef struct {
0294     ngx_str_t                        host;
0295     in_port_t                        port;
0296     ngx_uint_t                       no_port; /* unsigned no_port:1 */
0297 
0298     ngx_uint_t                       naddrs;
0299     ngx_resolver_addr_t             *addrs;
0300 
0301     struct sockaddr                 *sockaddr;
0302     socklen_t                        socklen;
0303     ngx_str_t                        name;
0304 
0305     ngx_resolver_ctx_t              *ctx;
0306 } ngx_http_upstream_resolved_t;
0307 
0308 
0309 typedef void (*ngx_http_upstream_handler_pt)(ngx_http_request_t *r,
0310     ngx_http_upstream_t *u);
0311 
0312 
0313 struct ngx_http_upstream_s {
0314     ngx_http_upstream_handler_pt     read_event_handler;
0315     ngx_http_upstream_handler_pt     write_event_handler;
0316 
0317     ngx_peer_connection_t            peer;
0318 
0319     ngx_event_pipe_t                *pipe;
0320 
0321     ngx_chain_t                     *request_bufs;
0322 
0323     ngx_output_chain_ctx_t           output;
0324     ngx_chain_writer_ctx_t           writer;
0325 
0326     ngx_http_upstream_conf_t        *conf;
0327     ngx_http_upstream_srv_conf_t    *upstream;
0328 #if (NGX_HTTP_CACHE)
0329     ngx_array_t                     *caches;
0330 #endif
0331 
0332     ngx_http_upstream_headers_in_t   headers_in;
0333 
0334     ngx_http_upstream_resolved_t    *resolved;
0335 
0336     ngx_buf_t                        from_client;
0337 
0338     ngx_buf_t                        buffer;
0339     off_t                            length;
0340 
0341     ngx_chain_t                     *out_bufs;
0342     ngx_chain_t                     *busy_bufs;
0343     ngx_chain_t                     *free_bufs;
0344 
0345     ngx_int_t                      (*input_filter_init)(void *data);
0346     ngx_int_t                      (*input_filter)(void *data, ssize_t bytes);
0347     void                            *input_filter_ctx;
0348 
0349 #if (NGX_HTTP_CACHE)
0350     ngx_int_t                      (*create_key)(ngx_http_request_t *r);
0351 #endif
0352     ngx_int_t                      (*create_request)(ngx_http_request_t *r);
0353     ngx_int_t                      (*reinit_request)(ngx_http_request_t *r);
0354     ngx_int_t                      (*process_header)(ngx_http_request_t *r);
0355     void                           (*abort_request)(ngx_http_request_t *r);
0356     void                           (*finalize_request)(ngx_http_request_t *r,
0357                                          ngx_int_t rc);
0358     ngx_int_t                      (*rewrite_redirect)(ngx_http_request_t *r,
0359                                          ngx_table_elt_t *h, size_t prefix);
0360     ngx_int_t                      (*rewrite_cookie)(ngx_http_request_t *r,
0361                                          ngx_table_elt_t *h);
0362 
0363     ngx_msec_t                       timeout;
0364 
0365     ngx_http_upstream_state_t       *state;
0366 
0367     ngx_str_t                        method;
0368     ngx_str_t                        schema;
0369     ngx_str_t                        uri;
0370 
0371 #if (NGX_HTTP_SSL || NGX_COMPAT)
0372     ngx_str_t                        ssl_name;
0373 #endif
0374 
0375     ngx_http_cleanup_pt             *cleanup;
0376 
0377     unsigned                         store:1;
0378     unsigned                         cacheable:1;
0379     unsigned                         accel:1;
0380     unsigned                         ssl:1;
0381 #if (NGX_HTTP_CACHE)
0382     unsigned                         cache_status:3;
0383 #endif
0384 
0385     unsigned                         buffering:1;
0386     unsigned                         keepalive:1;
0387     unsigned                         upgrade:1;
0388 
0389     unsigned                         request_sent:1;
0390     unsigned                         request_body_sent:1;
0391     unsigned                         header_sent:1;
0392 };
0393 
0394 
0395 typedef struct {
0396     ngx_uint_t                      status;
0397     ngx_uint_t                      mask;
0398 } ngx_http_upstream_next_t;
0399 
0400 
0401 typedef struct {
0402     ngx_str_t   key;
0403     ngx_str_t   value;
0404     ngx_uint_t  skip_empty;
0405 } ngx_http_upstream_param_t;
0406 
0407 
0408 ngx_int_t ngx_http_upstream_create(ngx_http_request_t *r);
0409 void ngx_http_upstream_init(ngx_http_request_t *r);
0410 ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
0411     ngx_url_t *u, ngx_uint_t flags);
0412 char *ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
0413     void *conf);
0414 char *ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
0415     void *conf);
0416 ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
0417     ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
0418     ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
0419 
0420 
0421 #define ngx_http_conf_upstream_srv_conf(uscf, module)                         \
0422     uscf->srv_conf[module.ctx_index]
0423 
0424 
0425 extern ngx_module_t        ngx_http_upstream_module;
0426 extern ngx_conf_bitmask_t  ngx_http_upstream_cache_method_mask[];
0427 extern ngx_conf_bitmask_t  ngx_http_upstream_ignore_headers_masks[];
0428 
0429 
0430 #endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */