upstream nginx-0.7.40
[nginx.git] / nginx / src / http / ngx_http_request.h
1
2 /*
3  * Copyright (C) Igor Sysoev
4  */
5
6
7 #ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
8 #define _NGX_HTTP_REQUEST_H_INCLUDED_
9
10
11 #define NGX_HTTP_MAX_URI_CHANGES           10
12 #define NGX_HTTP_MAX_SUBREQUESTS           50
13 #define NGX_HTTP_MAX_CAPTURES              9
14
15 /* must be 2^n */
16 #define NGX_HTTP_LC_HEADER_LEN             32
17
18
19 #define NGX_HTTP_DISCARD_BUFFER_SIZE       4096
20 #define NGX_HTTP_LINGERING_BUFFER_SIZE     4096
21
22
23 #define NGX_HTTP_VERSION_9                 9
24 #define NGX_HTTP_VERSION_10                1000
25 #define NGX_HTTP_VERSION_11                1001
26
27 #define NGX_HTTP_UNKNOWN                   0x0001
28 #define NGX_HTTP_GET                       0x0002
29 #define NGX_HTTP_HEAD                      0x0004
30 #define NGX_HTTP_POST                      0x0008
31 #define NGX_HTTP_PUT                       0x0010
32 #define NGX_HTTP_DELETE                    0x0020
33 #define NGX_HTTP_MKCOL                     0x0040
34 #define NGX_HTTP_COPY                      0x0080
35 #define NGX_HTTP_MOVE                      0x0100
36 #define NGX_HTTP_OPTIONS                   0x0200
37 #define NGX_HTTP_PROPFIND                  0x0400
38 #define NGX_HTTP_PROPPATCH                 0x0800
39 #define NGX_HTTP_LOCK                      0x1000
40 #define NGX_HTTP_UNLOCK                    0x2000
41 #define NGX_HTTP_TRACE                     0x4000
42
43 #define NGX_HTTP_CONNECTION_CLOSE          1
44 #define NGX_HTTP_CONNECTION_KEEP_ALIVE     2
45
46
47 #define NGX_NONE                           1
48
49
50 #define NGX_HTTP_PARSE_HEADER_DONE         1
51
52 #define NGX_HTTP_CLIENT_ERROR              10
53 #define NGX_HTTP_PARSE_INVALID_METHOD      10
54 #define NGX_HTTP_PARSE_INVALID_REQUEST     11
55 #define NGX_HTTP_PARSE_INVALID_09_METHOD   12
56
57 #define NGX_HTTP_PARSE_INVALID_HEADER      13
58
59
60 #define NGX_HTTP_ZERO_IN_URI               1
61 #define NGX_HTTP_SUBREQUEST_IN_MEMORY      2
62 #define NGX_HTTP_SUBREQUEST_WAITED         4
63
64
65 #define NGX_HTTP_OK                        200
66 #define NGX_HTTP_CREATED                   201
67 #define NGX_HTTP_NO_CONTENT                204
68 #define NGX_HTTP_PARTIAL_CONTENT           206
69
70 #define NGX_HTTP_SPECIAL_RESPONSE          300
71 #define NGX_HTTP_MOVED_PERMANENTLY         301
72 #define NGX_HTTP_MOVED_TEMPORARILY         302
73 #define NGX_HTTP_NOT_MODIFIED              304
74
75 #define NGX_HTTP_BAD_REQUEST               400
76 #define NGX_HTTP_UNAUTHORIZED              401
77 #define NGX_HTTP_FORBIDDEN                 403
78 #define NGX_HTTP_NOT_FOUND                 404
79 #define NGX_HTTP_NOT_ALLOWED               405
80 #define NGX_HTTP_REQUEST_TIME_OUT          408
81 #define NGX_HTTP_CONFLICT                  409
82 #define NGX_HTTP_LENGTH_REQUIRED           411
83 #define NGX_HTTP_PRECONDITION_FAILED       412
84 #define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE  413
85 #define NGX_HTTP_REQUEST_URI_TOO_LARGE     414
86 #define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE    415
87 #define NGX_HTTP_RANGE_NOT_SATISFIABLE     416
88
89
90 /* Our own HTTP codes */
91
92 /* The special code to close connection without any response */
93 #define NGX_HTTP_CLOSE                     444
94
95 #define NGX_HTTP_OWN_CODES                 495
96
97 #define NGX_HTTPS_CERT_ERROR               495
98 #define NGX_HTTPS_NO_CERT                  496
99
100 /*
101  * We use the special code for the plain HTTP requests that are sent to
102  * HTTPS port to distinguish it from 4XX in an error page redirection
103  */
104 #define NGX_HTTP_TO_HTTPS                  497
105
106 /* 498 is the canceled code for the requests with invalid host name */
107
108 /*
109  * HTTP does not define the code for the case when a client closed
110  * the connection while we are processing its request so we introduce
111  * own code to log such situation when a client has closed the connection
112  * before we even try to send the HTTP header to it
113  */
114 #define NGX_HTTP_CLIENT_CLOSED_REQUEST     499
115
116
117 #define NGX_HTTP_INTERNAL_SERVER_ERROR     500
118 #define NGX_HTTP_NOT_IMPLEMENTED           501
119 #define NGX_HTTP_BAD_GATEWAY               502
120 #define NGX_HTTP_SERVICE_UNAVAILABLE       503
121 #define NGX_HTTP_GATEWAY_TIME_OUT          504
122 #define NGX_HTTP_INSUFFICIENT_STORAGE      507
123
124
125 #define NGX_HTTP_LOWLEVEL_BUFFERED         0xf0
126 #define NGX_HTTP_WRITE_BUFFERED            0x10
127 #define NGX_HTTP_GZIP_BUFFERED             0x20
128 #define NGX_HTTP_SSI_BUFFERED              0x01
129 #define NGX_HTTP_SUB_BUFFERED              0x02
130 #define NGX_HTTP_COPY_BUFFERED             0x04
131
132
133 typedef enum {
134     NGX_HTTP_INITING_REQUEST_STATE = 0,
135     NGX_HTTP_READING_REQUEST_STATE,
136     NGX_HTTP_PROCESS_REQUEST_STATE,
137
138     NGX_HTTP_CONNECT_UPSTREAM_STATE,
139     NGX_HTTP_WRITING_UPSTREAM_STATE,
140     NGX_HTTP_READING_UPSTREAM_STATE,
141
142     NGX_HTTP_WRITING_REQUEST_STATE,
143     NGX_HTTP_LINGERING_CLOSE_STATE,
144     NGX_HTTP_KEEPALIVE_STATE
145 } ngx_http_state_e;
146
147
148 typedef struct {
149     ngx_str_t                         name;
150     ngx_uint_t                        offset;
151     ngx_http_header_handler_pt        handler;
152 } ngx_http_header_t;
153
154
155 typedef struct {
156     ngx_str_t                         name;
157     ngx_uint_t                        offset;
158 } ngx_http_header_out_t;
159
160
161 typedef struct {
162     ngx_list_t                        headers;
163
164     ngx_table_elt_t                  *host;
165     ngx_table_elt_t                  *connection;
166     ngx_table_elt_t                  *if_modified_since;
167     ngx_table_elt_t                  *user_agent;
168     ngx_table_elt_t                  *referer;
169     ngx_table_elt_t                  *content_length;
170     ngx_table_elt_t                  *content_type;
171
172     ngx_table_elt_t                  *range;
173     ngx_table_elt_t                  *if_range;
174
175     ngx_table_elt_t                  *transfer_encoding;
176     ngx_table_elt_t                  *expect;
177
178 #if (NGX_HTTP_GZIP)
179     ngx_table_elt_t                  *accept_encoding;
180     ngx_table_elt_t                  *via;
181 #endif
182
183     ngx_table_elt_t                  *authorization;
184
185     ngx_table_elt_t                  *keep_alive;
186
187 #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP)
188     ngx_table_elt_t                  *x_forwarded_for;
189 #endif
190
191 #if (NGX_HTTP_REALIP)
192     ngx_table_elt_t                  *x_real_ip;
193 #endif
194
195 #if (NGX_HTTP_HEADERS)
196     ngx_table_elt_t                  *accept;
197     ngx_table_elt_t                  *accept_language;
198 #endif
199
200 #if (NGX_HTTP_DAV)
201     ngx_table_elt_t                  *depth;
202     ngx_table_elt_t                  *destination;
203     ngx_table_elt_t                  *overwrite;
204     ngx_table_elt_t                  *date;
205 #endif
206
207     ngx_str_t                         user;
208     ngx_str_t                         passwd;
209
210     ngx_array_t                       cookies;
211
212     ngx_str_t                         server;
213     off_t                             content_length_n;
214     time_t                            keep_alive_n;
215
216     unsigned                          connection_type:2;
217     unsigned                          msie:1;
218     unsigned                          msie4:1;
219     unsigned                          msie6:1;
220     unsigned                          opera:1;
221     unsigned                          gecko:1;
222     unsigned                          konqueror:1;
223 } ngx_http_headers_in_t;
224
225
226 typedef struct {
227     ngx_list_t                        headers;
228
229     ngx_uint_t                        status;
230     ngx_str_t                         status_line;
231
232     ngx_table_elt_t                  *server;
233     ngx_table_elt_t                  *date;
234     ngx_table_elt_t                  *content_length;
235     ngx_table_elt_t                  *content_encoding;
236     ngx_table_elt_t                  *location;
237     ngx_table_elt_t                  *refresh;
238     ngx_table_elt_t                  *last_modified;
239     ngx_table_elt_t                  *content_range;
240     ngx_table_elt_t                  *accept_ranges;
241     ngx_table_elt_t                  *www_authenticate;
242     ngx_table_elt_t                  *expires;
243     ngx_table_elt_t                  *etag;
244
245     ngx_str_t                        *override_charset;
246
247     size_t                            content_type_len;
248     ngx_str_t                         content_type;
249     ngx_str_t                         charset;
250     u_char                           *content_type_lowcase;
251     ngx_uint_t                        content_type_hash;
252
253     ngx_array_t                       cache_control;
254
255     off_t                             content_length_n;
256     time_t                            date_time;
257     time_t                            last_modified_time;
258 } ngx_http_headers_out_t;
259
260
261 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
262
263 typedef struct {
264     ngx_temp_file_t                  *temp_file;
265     ngx_chain_t                      *bufs;
266     ngx_buf_t                        *buf;
267     off_t                             rest;
268     ngx_chain_t                      *to_write;
269     ngx_http_client_body_handler_pt   post_handler;
270 } ngx_http_request_body_t;
271
272
273 typedef struct {
274     ngx_http_request_t               *request;
275
276     ngx_buf_t                       **busy;
277     ngx_int_t                         nbusy;
278
279     ngx_buf_t                       **free;
280     ngx_int_t                         nfree;
281
282     ngx_uint_t                        pipeline;    /* unsigned  pipeline:1; */
283 } ngx_http_connection_t;
284
285
286 typedef struct ngx_http_server_name_s  ngx_http_server_name_t;
287
288
289 typedef struct {
290      ngx_hash_combined_t              names;
291
292      ngx_uint_t                       nregex;
293      ngx_http_server_name_t          *regex;
294 } ngx_http_virtual_names_t;
295
296
297 typedef void (*ngx_http_cleanup_pt)(void *data);
298
299 typedef struct ngx_http_cleanup_s  ngx_http_cleanup_t;
300
301 struct ngx_http_cleanup_s {
302     ngx_http_cleanup_pt               handler;
303     void                             *data;
304     ngx_http_cleanup_t               *next;
305 };
306
307
308 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
309     void *data, ngx_int_t rc);
310
311 typedef struct {
312     ngx_http_post_subrequest_pt       handler;
313     void                             *data;
314 } ngx_http_post_subrequest_t;
315
316
317 typedef struct ngx_http_postponed_request_s  ngx_http_postponed_request_t;
318
319 struct ngx_http_postponed_request_s {
320     ngx_http_request_t               *request;
321     ngx_chain_t                      *out;
322     ngx_http_postponed_request_t     *next;
323 };
324
325
326 typedef struct ngx_http_posted_request_s  ngx_http_posted_request_t;
327
328 struct ngx_http_posted_request_s {
329     ngx_http_request_t               *request;
330     ngx_http_posted_request_t        *next;
331 };
332
333
334 typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
335 typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r);
336
337
338 struct ngx_http_request_s {
339     uint32_t                          signature;         /* "HTTP" */
340
341     ngx_connection_t                 *connection;
342
343     void                            **ctx;
344     void                            **main_conf;
345     void                            **srv_conf;
346     void                            **loc_conf;
347
348     ngx_http_event_handler_pt         read_event_handler;
349     ngx_http_event_handler_pt         write_event_handler;
350
351     ngx_http_cache_t                 *cache;
352
353     ngx_http_upstream_t              *upstream;
354     ngx_array_t                      *upstream_states;
355                                          /* of ngx_http_upstream_state_t */
356
357     ngx_pool_t                       *pool;
358     ngx_buf_t                        *header_in;
359
360     ngx_http_headers_in_t             headers_in;
361     ngx_http_headers_out_t            headers_out;
362
363     ngx_http_request_body_t          *request_body;
364
365     time_t                            lingering_time;
366     time_t                            start_sec;
367     ngx_msec_t                        start_msec;
368
369     ngx_uint_t                        method;
370     ngx_uint_t                        http_version;
371
372     ngx_str_t                         request_line;
373     ngx_str_t                         uri;
374     ngx_str_t                         args;
375     ngx_str_t                         exten;
376     ngx_str_t                         unparsed_uri;
377
378     ngx_str_t                         method_name;
379     ngx_str_t                         http_protocol;
380
381     ngx_chain_t                      *out;
382     ngx_http_request_t               *main;
383     ngx_http_request_t               *parent;
384     ngx_http_postponed_request_t     *postponed;
385     ngx_http_post_subrequest_t       *post_subrequest;
386     ngx_http_posted_request_t        *posted_requests;
387
388     ngx_int_t                         phase_handler;
389     ngx_http_handler_pt               content_handler;
390     ngx_uint_t                        access_code;
391
392     ngx_http_variable_value_t        *variables;
393
394 #if (NGX_PCRE)
395     ngx_uint_t                        ncaptures;
396     int                              *captures;
397     u_char                           *captures_data;
398 #endif
399
400     size_t                            limit_rate;
401
402     /* used to learn the Apache compatible response length without a header */
403     size_t                            header_size;
404
405     off_t                             request_length;
406
407     ngx_uint_t                        err_status;
408
409     ngx_http_connection_t            *http_connection;
410
411     ngx_http_log_handler_pt           log_handler;
412
413     ngx_http_cleanup_t               *cleanup;
414
415     unsigned                          http_state:4;
416
417     /* URI with "/." and on Win32 with "//" */
418     unsigned                          complex_uri:1;
419
420     /* URI with "%" */
421     unsigned                          quoted_uri:1;
422
423     /* URI with "+" */
424     unsigned                          plus_in_uri:1;
425
426     /* URI with "\0" or "%00" */
427     unsigned                          zero_in_uri:1;
428
429     unsigned                          invalid_header:1;
430
431     unsigned                          valid_location:1;
432     unsigned                          valid_unparsed_uri:1;
433     unsigned                          uri_changed:1;
434     unsigned                          uri_changes:4;
435
436     unsigned                          request_body_in_single_buf:1;
437     unsigned                          request_body_in_file_only:1;
438     unsigned                          request_body_in_persistent_file:1;
439     unsigned                          request_body_in_clean_file:1;
440     unsigned                          request_body_file_group_access:1;
441     unsigned                          request_body_file_log_level:3;
442
443     unsigned                          subrequest_in_memory:1;
444     unsigned                          waited:1;
445
446     unsigned                          gzip:2;
447
448     unsigned                          proxy:1;
449     unsigned                          bypass_cache:1;
450     unsigned                          no_cache:1;
451
452     /*
453      * instead of using the request context data in
454      * ngx_http_limit_zone_module and ngx_http_limit_req_module
455      * we use the single bits in the request structure
456      */
457     unsigned                          limit_zone_set:1;
458     unsigned                          limit_req_set:1;
459
460 #if 0
461     unsigned                          cacheable:1;
462 #endif
463
464     unsigned                          pipeline:1;
465     unsigned                          plain_http:1;
466     unsigned                          chunked:1;
467     unsigned                          header_only:1;
468     unsigned                          zero_body:1;
469     unsigned                          keepalive:1;
470     unsigned                          lingering_close:1;
471     unsigned                          discard_body:1;
472     unsigned                          internal:1;
473     unsigned                          error_page:1;
474     unsigned                          post_action:1;
475     unsigned                          request_complete:1;
476     unsigned                          request_output:1;
477     unsigned                          header_sent:1;
478     unsigned                          expect_tested:1;
479     unsigned                          root_tested:1;
480     unsigned                          done:1;
481     unsigned                          logged:1;
482     unsigned                          utf8:1;
483
484     unsigned                          buffered:4;
485
486     unsigned                          main_filter_need_in_memory:1;
487     unsigned                          filter_need_in_memory:1;
488     unsigned                          filter_need_temporary:1;
489     unsigned                          allow_ranges:1;
490
491 #if (NGX_STAT_STUB)
492     unsigned                          stat_reading:1;
493     unsigned                          stat_writing:1;
494 #endif
495
496     unsigned                          subrequests:8;
497
498     /* used to parse HTTP headers */
499
500     ngx_uint_t                        state;
501     u_char                           *uri_start;
502     u_char                           *uri_end;
503     u_char                           *uri_ext;
504     u_char                           *args_start;
505     u_char                           *request_start;
506     u_char                           *request_end;
507     u_char                           *method_end;
508     u_char                           *schema_start;
509     u_char                           *schema_end;
510     u_char                           *host_start;
511     u_char                           *host_end;
512     u_char                           *port_start;
513     u_char                           *port_end;
514     u_char                           *header_name_start;
515     u_char                           *header_name_end;
516     u_char                           *header_start;
517     u_char                           *header_end;
518
519     unsigned                          http_minor:16;
520     unsigned                          http_major:16;
521
522     ngx_uint_t                        header_hash;
523     ngx_uint_t                        lowcase_index;
524     u_char                            lowcase_header[NGX_HTTP_LC_HEADER_LEN];
525 };
526
527
528 extern ngx_http_header_t       ngx_http_headers_in[];
529 extern ngx_http_header_out_t   ngx_http_headers_out[];
530
531
532 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */