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