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