~ubuntu-branches/ubuntu/trusty/nginx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/http/ngx_http_upstream.h

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-04-25 12:51:45 UTC
  • mfrom: (1.3.28)
  • mto: (1.3.29) (15.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20130425125145-ugl0wor6bq0u5eae
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
3
 * Copyright (C) Igor Sysoev
 
4
 * Copyright (C) Nginx, Inc.
4
5
 */
5
6
 
6
7
 
20
21
#define NGX_HTTP_UPSTREAM_FT_TIMEOUT         0x00000004
21
22
#define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER  0x00000008
22
23
#define NGX_HTTP_UPSTREAM_FT_HTTP_500        0x00000010
23
 
#define NGX_HTTP_UPSTREAM_FT_HTTP_503        0x00000020
24
 
#define NGX_HTTP_UPSTREAM_FT_HTTP_404        0x00000040
25
 
#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x00000080
26
 
#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x00000100
 
24
#define NGX_HTTP_UPSTREAM_FT_HTTP_502        0x00000020
 
25
#define NGX_HTTP_UPSTREAM_FT_HTTP_503        0x00000040
 
26
#define NGX_HTTP_UPSTREAM_FT_HTTP_504        0x00000080
 
27
#define NGX_HTTP_UPSTREAM_FT_HTTP_404        0x00000100
 
28
#define NGX_HTTP_UPSTREAM_FT_UPDATING        0x00000200
 
29
#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x00000400
 
30
#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x00000800
27
31
#define NGX_HTTP_UPSTREAM_FT_NOLIVE          0x40000000
28
32
#define NGX_HTTP_UPSTREAM_FT_OFF             0x80000000
29
33
 
 
34
#define NGX_HTTP_UPSTREAM_FT_STATUS          (NGX_HTTP_UPSTREAM_FT_HTTP_500  \
 
35
                                             |NGX_HTTP_UPSTREAM_FT_HTTP_502  \
 
36
                                             |NGX_HTTP_UPSTREAM_FT_HTTP_503  \
 
37
                                             |NGX_HTTP_UPSTREAM_FT_HTTP_504  \
 
38
                                             |NGX_HTTP_UPSTREAM_FT_HTTP_404)
30
39
 
31
40
#define NGX_HTTP_UPSTREAM_INVALID_HEADER     40
32
41
 
33
42
 
 
43
#define NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT    0x00000002
 
44
#define NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES     0x00000004
 
45
#define NGX_HTTP_UPSTREAM_IGN_EXPIRES        0x00000008
 
46
#define NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL  0x00000010
 
47
#define NGX_HTTP_UPSTREAM_IGN_SET_COOKIE     0x00000020
 
48
#define NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE  0x00000040
 
49
#define NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING   0x00000080
 
50
#define NGX_HTTP_UPSTREAM_IGN_XA_CHARSET     0x00000100
 
51
 
 
52
 
34
53
typedef struct {
35
 
    ngx_msec_t                      bl_time;
36
 
    ngx_uint_t                      bl_state;
37
 
 
38
 
    ngx_uint_t                      status;
39
 
    time_t                          response_sec;
40
 
    ngx_uint_t                      response_msec;
41
 
 
42
 
    ngx_str_t                      *peer;
 
54
    ngx_msec_t                       bl_time;
 
55
    ngx_uint_t                       bl_state;
 
56
 
 
57
    ngx_uint_t                       status;
 
58
    time_t                           response_sec;
 
59
    ngx_uint_t                       response_msec;
 
60
    off_t                            response_length;
 
61
 
 
62
    ngx_str_t                       *peer;
43
63
} ngx_http_upstream_state_t;
44
64
 
45
65
 
46
66
typedef struct {
47
 
    ngx_hash_t                      headers_in_hash;
48
 
    ngx_array_t                     upstreams;
 
67
    ngx_hash_t                       headers_in_hash;
 
68
    ngx_array_t                      upstreams;
49
69
                                             /* ngx_http_upstream_srv_conf_t */
50
70
} ngx_http_upstream_main_conf_t;
51
71
 
58
78
 
59
79
 
60
80
typedef struct {
61
 
    ngx_http_upstream_init_pt       init_upstream;
62
 
    ngx_http_upstream_init_peer_pt  init;
63
 
    void                           *data;
 
81
    ngx_http_upstream_init_pt        init_upstream;
 
82
    ngx_http_upstream_init_peer_pt   init;
 
83
    void                            *data;
64
84
} ngx_http_upstream_peer_t;
65
85
 
66
86
 
67
87
typedef struct {
68
 
    ngx_peer_addr_t                *addrs;
69
 
    ngx_uint_t                      naddrs;
70
 
    ngx_uint_t                      weight;
71
 
    ngx_uint_t                      max_fails;
72
 
    time_t                          fail_timeout;
 
88
    ngx_addr_t                      *addrs;
 
89
    ngx_uint_t                       naddrs;
 
90
    ngx_uint_t                       weight;
 
91
    ngx_uint_t                       max_fails;
 
92
    time_t                           fail_timeout;
73
93
 
74
 
    unsigned                        down:1;
75
 
    unsigned                        backup:1;
 
94
    unsigned                         down:1;
 
95
    unsigned                         backup:1;
76
96
} ngx_http_upstream_server_t;
77
97
 
78
98
 
85
105
 
86
106
 
87
107
struct ngx_http_upstream_srv_conf_s {
88
 
    ngx_http_upstream_peer_t        peer;
89
 
    void                          **srv_conf;
90
 
 
91
 
    ngx_array_t                    *servers;   /* ngx_http_upstream_server_t */
92
 
 
93
 
    ngx_uint_t                      flags;
94
 
    ngx_str_t                       host;
95
 
    u_char                         *file_name;
96
 
    ngx_uint_t                      line;
97
 
    in_port_t                       port;
98
 
    in_port_t                       default_port;
 
108
    ngx_http_upstream_peer_t         peer;
 
109
    void                           **srv_conf;
 
110
 
 
111
    ngx_array_t                     *servers;  /* ngx_http_upstream_server_t */
 
112
 
 
113
    ngx_uint_t                       flags;
 
114
    ngx_str_t                        host;
 
115
    u_char                          *file_name;
 
116
    ngx_uint_t                       line;
 
117
    in_port_t                        port;
 
118
    in_port_t                        default_port;
 
119
    ngx_uint_t                       no_port;  /* unsigned no_port:1 */
99
120
};
100
121
 
101
122
 
102
123
typedef struct {
103
 
    ngx_http_upstream_srv_conf_t   *upstream;
104
 
 
105
 
    ngx_msec_t                      connect_timeout;
106
 
    ngx_msec_t                      send_timeout;
107
 
    ngx_msec_t                      read_timeout;
108
 
    ngx_msec_t                      timeout;
109
 
 
110
 
    size_t                          send_lowat;
111
 
    size_t                          buffer_size;
112
 
 
113
 
    size_t                          busy_buffers_size;
114
 
    size_t                          max_temp_file_size;
115
 
    size_t                          temp_file_write_size;
116
 
 
117
 
    size_t                          busy_buffers_size_conf;
118
 
    size_t                          max_temp_file_size_conf;
119
 
    size_t                          temp_file_write_size_conf;
120
 
 
121
 
    ngx_uint_t                      next_upstream;
122
 
    ngx_uint_t                      store_access;
123
 
 
124
 
    ngx_bufs_t                      bufs;
125
 
 
126
 
    ngx_flag_t                      buffering;
127
 
    ngx_flag_t                      pass_request_headers;
128
 
    ngx_flag_t                      pass_request_body;
129
 
 
130
 
    ngx_flag_t                      ignore_client_abort;
131
 
    ngx_flag_t                      intercept_errors;
132
 
    ngx_flag_t                      cyclic_temp_file;
133
 
 
134
 
    ngx_path_t                     *temp_path;
135
 
 
136
 
    ngx_hash_t                      hide_headers_hash;
137
 
    ngx_array_t                    *hide_headers;
138
 
    ngx_array_t                    *pass_headers;
139
 
 
140
 
    ngx_str_t                       schema;
141
 
 
142
 
    ngx_array_t                    *store_lengths;
143
 
    ngx_array_t                    *store_values;
144
 
 
145
 
    signed                          store:2;
146
 
    unsigned                        intercept_404:1;
147
 
    unsigned                        change_buffering:1;
 
124
    ngx_addr_t                      *addr;
 
125
    ngx_http_complex_value_t        *value;
 
126
} ngx_http_upstream_local_t;
 
127
 
 
128
 
 
129
typedef struct {
 
130
    ngx_http_upstream_srv_conf_t    *upstream;
 
131
 
 
132
    ngx_msec_t                       connect_timeout;
 
133
    ngx_msec_t                       send_timeout;
 
134
    ngx_msec_t                       read_timeout;
 
135
    ngx_msec_t                       timeout;
 
136
 
 
137
    size_t                           send_lowat;
 
138
    size_t                           buffer_size;
 
139
 
 
140
    size_t                           busy_buffers_size;
 
141
    size_t                           max_temp_file_size;
 
142
    size_t                           temp_file_write_size;
 
143
 
 
144
    size_t                           busy_buffers_size_conf;
 
145
    size_t                           max_temp_file_size_conf;
 
146
    size_t                           temp_file_write_size_conf;
 
147
 
 
148
    ngx_bufs_t                       bufs;
 
149
 
 
150
    ngx_uint_t                       ignore_headers;
 
151
    ngx_uint_t                       next_upstream;
 
152
    ngx_uint_t                       store_access;
 
153
    ngx_flag_t                       buffering;
 
154
    ngx_flag_t                       pass_request_headers;
 
155
    ngx_flag_t                       pass_request_body;
 
156
 
 
157
    ngx_flag_t                       ignore_client_abort;
 
158
    ngx_flag_t                       intercept_errors;
 
159
    ngx_flag_t                       cyclic_temp_file;
 
160
 
 
161
    ngx_path_t                      *temp_path;
 
162
 
 
163
    ngx_hash_t                       hide_headers_hash;
 
164
    ngx_array_t                     *hide_headers;
 
165
    ngx_array_t                     *pass_headers;
 
166
 
 
167
    ngx_http_upstream_local_t       *local;
 
168
 
 
169
#if (NGX_HTTP_CACHE)
 
170
    ngx_shm_zone_t                  *cache;
 
171
 
 
172
    ngx_uint_t                       cache_min_uses;
 
173
    ngx_uint_t                       cache_use_stale;
 
174
    ngx_uint_t                       cache_methods;
 
175
 
 
176
    ngx_flag_t                       cache_lock;
 
177
    ngx_msec_t                       cache_lock_timeout;
 
178
 
 
179
    ngx_array_t                     *cache_valid;
 
180
    ngx_array_t                     *cache_bypass;
 
181
    ngx_array_t                     *no_cache;
 
182
#endif
 
183
 
 
184
    ngx_array_t                     *store_lengths;
 
185
    ngx_array_t                     *store_values;
 
186
 
 
187
    signed                           store:2;
 
188
    unsigned                         intercept_404:1;
 
189
    unsigned                         change_buffering:1;
148
190
 
149
191
#if (NGX_HTTP_SSL)
150
 
    ngx_ssl_t                      *ssl;
 
192
    ngx_ssl_t                       *ssl;
 
193
    ngx_flag_t                       ssl_session_reuse;
151
194
#endif
152
195
 
 
196
    ngx_str_t                        module;
153
197
} ngx_http_upstream_conf_t;
154
198
 
155
199
 
156
200
typedef struct {
157
 
    ngx_str_t                       name;
158
 
    ngx_http_header_handler_pt      handler;
159
 
    ngx_uint_t                      offset;
160
 
    ngx_http_header_handler_pt      copy_handler;
161
 
    ngx_uint_t                      conf;
162
 
    ngx_uint_t                      redirect;  /* unsigned   redirect:1; */
 
201
    ngx_str_t                        name;
 
202
    ngx_http_header_handler_pt       handler;
 
203
    ngx_uint_t                       offset;
 
204
    ngx_http_header_handler_pt       copy_handler;
 
205
    ngx_uint_t                       conf;
 
206
    ngx_uint_t                       redirect;  /* unsigned   redirect:1; */
163
207
} ngx_http_upstream_header_t;
164
208
 
165
209
 
166
210
typedef struct {
167
 
    ngx_list_t                      headers;
168
 
 
169
 
    ngx_uint_t                      status_n;
170
 
    ngx_str_t                       status_line;
171
 
 
172
 
    ngx_table_elt_t                *status;
173
 
    ngx_table_elt_t                *date;
174
 
    ngx_table_elt_t                *server;
175
 
    ngx_table_elt_t                *connection;
176
 
 
177
 
    ngx_table_elt_t                *expires;
178
 
    ngx_table_elt_t                *etag;
179
 
    ngx_table_elt_t                *x_accel_expires;
180
 
    ngx_table_elt_t                *x_accel_redirect;
181
 
    ngx_table_elt_t                *x_accel_limit_rate;
182
 
 
183
 
    ngx_table_elt_t                *content_type;
184
 
    ngx_table_elt_t                *content_length;
185
 
 
186
 
    ngx_table_elt_t                *last_modified;
187
 
    ngx_table_elt_t                *location;
188
 
    ngx_table_elt_t                *accept_ranges;
189
 
    ngx_table_elt_t                *www_authenticate;
 
211
    ngx_list_t                       headers;
 
212
 
 
213
    ngx_uint_t                       status_n;
 
214
    ngx_str_t                        status_line;
 
215
 
 
216
    ngx_table_elt_t                 *status;
 
217
    ngx_table_elt_t                 *date;
 
218
    ngx_table_elt_t                 *server;
 
219
    ngx_table_elt_t                 *connection;
 
220
 
 
221
    ngx_table_elt_t                 *expires;
 
222
    ngx_table_elt_t                 *etag;
 
223
    ngx_table_elt_t                 *x_accel_expires;
 
224
    ngx_table_elt_t                 *x_accel_redirect;
 
225
    ngx_table_elt_t                 *x_accel_limit_rate;
 
226
 
 
227
    ngx_table_elt_t                 *content_type;
 
228
    ngx_table_elt_t                 *content_length;
 
229
 
 
230
    ngx_table_elt_t                 *last_modified;
 
231
    ngx_table_elt_t                 *location;
 
232
    ngx_table_elt_t                 *accept_ranges;
 
233
    ngx_table_elt_t                 *www_authenticate;
 
234
    ngx_table_elt_t                 *transfer_encoding;
190
235
 
191
236
#if (NGX_HTTP_GZIP)
192
 
    ngx_table_elt_t                *content_encoding;
 
237
    ngx_table_elt_t                 *content_encoding;
193
238
#endif
194
239
 
195
 
    off_t                           content_length_n;
196
 
 
197
 
    ngx_array_t                     cache_control;
 
240
    off_t                            content_length_n;
 
241
 
 
242
    ngx_array_t                      cache_control;
 
243
 
 
244
    unsigned                         connection_close:1;
 
245
    unsigned                         chunked:1;
198
246
} ngx_http_upstream_headers_in_t;
199
247
 
200
248
 
201
249
typedef struct {
202
 
    ngx_str_t                       host;
203
 
    in_port_t                       port;
204
 
    ngx_uint_t                      default_port; /* unsigned  default_port:1 */
205
 
    ngx_uint_t                      naddrs;
206
 
    in_addr_t                      *addrs;
207
 
    ngx_resolver_ctx_t             *ctx;
 
250
    ngx_str_t                        host;
 
251
    in_port_t                        port;
 
252
    ngx_uint_t                       no_port; /* unsigned no_port:1 */
 
253
 
 
254
    ngx_uint_t                       naddrs;
 
255
    in_addr_t                       *addrs;
 
256
 
 
257
    struct sockaddr                 *sockaddr;
 
258
    socklen_t                        socklen;
 
259
 
 
260
    ngx_resolver_ctx_t              *ctx;
208
261
} ngx_http_upstream_resolved_t;
209
262
 
210
263
 
 
264
typedef void (*ngx_http_upstream_handler_pt)(ngx_http_request_t *r,
 
265
    ngx_http_upstream_t *u);
 
266
 
 
267
 
211
268
struct ngx_http_upstream_s {
212
 
    ngx_peer_connection_t           peer;
213
 
 
214
 
    ngx_event_pipe_t               *pipe;
215
 
 
216
 
    ngx_chain_t                    *request_bufs;
217
 
 
218
 
    ngx_output_chain_ctx_t          output;
219
 
    ngx_chain_writer_ctx_t          writer;
220
 
 
221
 
    ngx_http_upstream_conf_t       *conf;
222
 
 
223
 
    ngx_http_upstream_headers_in_t  headers_in;
224
 
 
225
 
    ngx_http_upstream_resolved_t   *resolved;
226
 
 
227
 
    ngx_buf_t                       buffer;
228
 
    size_t                          length;
229
 
 
230
 
    ngx_chain_t                    *out_bufs;
231
 
    ngx_chain_t                    *busy_bufs;
232
 
    ngx_chain_t                    *free_bufs;
233
 
 
234
 
    ngx_int_t                     (*input_filter_init)(void *data);
235
 
    ngx_int_t                     (*input_filter)(void *data, ssize_t bytes);
236
 
    void                           *input_filter_ctx;
237
 
 
238
 
    ngx_int_t                     (*create_request)(ngx_http_request_t *r);
239
 
    ngx_int_t                     (*reinit_request)(ngx_http_request_t *r);
240
 
    ngx_int_t                     (*process_header)(ngx_http_request_t *r);
241
 
    void                          (*abort_request)(ngx_http_request_t *r);
242
 
    void                          (*finalize_request)(ngx_http_request_t *r,
243
 
                                        ngx_int_t rc);
244
 
    ngx_int_t                     (*rewrite_redirect)(ngx_http_request_t *r,
245
 
                                        ngx_table_elt_t *h, size_t prefix);
246
 
 
247
 
    ngx_msec_t                      timeout;
248
 
 
249
 
    ngx_http_upstream_state_t      *state;
250
 
 
251
 
    ngx_str_t                       method;
252
 
    ngx_str_t                       schema;
253
 
    ngx_str_t                       uri;
254
 
 
255
 
    ngx_http_cleanup_pt            *cleanup;
256
 
 
257
 
    unsigned                        store:1;
258
 
    unsigned                        cacheable:1;
259
 
    unsigned                        accel:1;
260
 
    unsigned                        ssl:1;
261
 
 
262
 
    unsigned                        buffering:1;
263
 
 
264
 
    unsigned                        request_sent:1;
265
 
    unsigned                        header_sent:1;
 
269
    ngx_http_upstream_handler_pt     read_event_handler;
 
270
    ngx_http_upstream_handler_pt     write_event_handler;
 
271
 
 
272
    ngx_peer_connection_t            peer;
 
273
 
 
274
    ngx_event_pipe_t                *pipe;
 
275
 
 
276
    ngx_chain_t                     *request_bufs;
 
277
 
 
278
    ngx_output_chain_ctx_t           output;
 
279
    ngx_chain_writer_ctx_t           writer;
 
280
 
 
281
    ngx_http_upstream_conf_t        *conf;
 
282
 
 
283
    ngx_http_upstream_headers_in_t   headers_in;
 
284
 
 
285
    ngx_http_upstream_resolved_t    *resolved;
 
286
 
 
287
    ngx_buf_t                        from_client;
 
288
 
 
289
    ngx_buf_t                        buffer;
 
290
    off_t                            length;
 
291
 
 
292
    ngx_chain_t                     *out_bufs;
 
293
    ngx_chain_t                     *busy_bufs;
 
294
    ngx_chain_t                     *free_bufs;
 
295
 
 
296
    ngx_int_t                      (*input_filter_init)(void *data);
 
297
    ngx_int_t                      (*input_filter)(void *data, ssize_t bytes);
 
298
    void                            *input_filter_ctx;
 
299
 
 
300
#if (NGX_HTTP_CACHE)
 
301
    ngx_int_t                      (*create_key)(ngx_http_request_t *r);
 
302
#endif
 
303
    ngx_int_t                      (*create_request)(ngx_http_request_t *r);
 
304
    ngx_int_t                      (*reinit_request)(ngx_http_request_t *r);
 
305
    ngx_int_t                      (*process_header)(ngx_http_request_t *r);
 
306
    void                           (*abort_request)(ngx_http_request_t *r);
 
307
    void                           (*finalize_request)(ngx_http_request_t *r,
 
308
                                         ngx_int_t rc);
 
309
    ngx_int_t                      (*rewrite_redirect)(ngx_http_request_t *r,
 
310
                                         ngx_table_elt_t *h, size_t prefix);
 
311
    ngx_int_t                      (*rewrite_cookie)(ngx_http_request_t *r,
 
312
                                         ngx_table_elt_t *h);
 
313
 
 
314
    ngx_msec_t                       timeout;
 
315
 
 
316
    ngx_http_upstream_state_t       *state;
 
317
 
 
318
    ngx_str_t                        method;
 
319
    ngx_str_t                        schema;
 
320
    ngx_str_t                        uri;
 
321
 
 
322
    ngx_http_cleanup_pt             *cleanup;
 
323
 
 
324
    unsigned                         store:1;
 
325
    unsigned                         cacheable:1;
 
326
    unsigned                         accel:1;
 
327
    unsigned                         ssl:1;
 
328
#if (NGX_HTTP_CACHE)
 
329
    unsigned                         cache_status:3;
 
330
#endif
 
331
 
 
332
    unsigned                         buffering:1;
 
333
    unsigned                         keepalive:1;
 
334
    unsigned                         upgrade:1;
 
335
 
 
336
    unsigned                         request_sent:1;
 
337
    unsigned                         header_sent:1;
266
338
};
267
339
 
268
340
 
 
341
typedef struct {
 
342
    ngx_uint_t                      status;
 
343
    ngx_uint_t                      mask;
 
344
} ngx_http_upstream_next_t;
 
345
 
 
346
 
 
347
typedef struct {
 
348
    ngx_str_t   key;
 
349
    ngx_str_t   value;
 
350
    ngx_uint_t  skip_empty;
 
351
} ngx_http_upstream_param_t;
 
352
 
 
353
 
269
354
ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
270
355
    ngx_http_variable_value_t *v, uintptr_t data);
271
356
 
 
357
ngx_int_t ngx_http_upstream_create(ngx_http_request_t *r);
272
358
void ngx_http_upstream_init(ngx_http_request_t *r);
273
359
ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
274
360
    ngx_url_t *u, ngx_uint_t flags);
 
361
char *ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
 
362
    void *conf);
 
363
char *ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
 
364
    void *conf);
275
365
ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
276
366
    ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
277
367
    ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
281
371
    uscf->srv_conf[module.ctx_index]
282
372
 
283
373
 
284
 
extern ngx_module_t  ngx_http_upstream_module;
 
374
extern ngx_module_t        ngx_http_upstream_module;
 
375
extern ngx_conf_bitmask_t  ngx_http_upstream_cache_method_mask[];
 
376
extern ngx_conf_bitmask_t  ngx_http_upstream_ignore_headers_masks[];
285
377
 
286
378
 
287
379
#endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */