Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

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