nginx 0.7.8
[nginx-catap.git] / src / http / ngx_http_request.h
blob9a6223963861dc3168a5e4ad02f18e37c39fe6f0
2 /*
3 * Copyright (C) Igor Sysoev
4 */
7 #ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
8 #define _NGX_HTTP_REQUEST_H_INCLUDED_
11 #define NGX_HTTP_MAX_URI_CHANGES 10
12 #define NGX_HTTP_MAX_SUBREQUESTS 50
14 /* must be 2^n */
15 #define NGX_HTTP_LC_HEADER_LEN 32
18 #define NGX_HTTP_DISCARD_BUFFER_SIZE 4096
19 #define NGX_HTTP_LINGERING_BUFFER_SIZE 4096
22 #define NGX_HTTP_VERSION_9 9
23 #define NGX_HTTP_VERSION_10 1000
24 #define NGX_HTTP_VERSION_11 1001
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
42 #define NGX_HTTP_CONNECTION_CLOSE 1
43 #define NGX_HTTP_CONNECTION_KEEP_ALIVE 2
46 #define NGX_NONE 1
49 #define NGX_HTTP_PARSE_HEADER_DONE 1
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
56 #define NGX_HTTP_PARSE_INVALID_HEADER 13
59 #define NGX_HTTP_ZERO_IN_URI 1
60 #define NGX_HTTP_SUBREQUEST_IN_MEMORY 2
63 #define NGX_HTTP_OK 200
64 #define NGX_HTTP_CREATED 201
65 #define NGX_HTTP_NO_CONTENT 204
66 #define NGX_HTTP_PARTIAL_CONTENT 206
68 #define NGX_HTTP_SPECIAL_RESPONSE 300
69 #define NGX_HTTP_MOVED_PERMANENTLY 301
70 #define NGX_HTTP_MOVED_TEMPORARILY 302
71 #define NGX_HTTP_NOT_MODIFIED 304
73 #define NGX_HTTP_BAD_REQUEST 400
74 #define NGX_HTTP_UNAUTHORIZED 401
75 #define NGX_HTTP_FORBIDDEN 403
76 #define NGX_HTTP_NOT_FOUND 404
77 #define NGX_HTTP_NOT_ALLOWED 405
78 #define NGX_HTTP_REQUEST_TIME_OUT 408
79 #define NGX_HTTP_CONFLICT 409
80 #define NGX_HTTP_LENGTH_REQUIRED 411
81 #define NGX_HTTP_PRECONDITION_FAILED 412
82 #define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE 413
83 #define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
84 #define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE 415
85 #define NGX_HTTP_RANGE_NOT_SATISFIABLE 416
88 /* Our own HTTP codes */
90 /* The special code to close connection without any response */
91 #define NGX_HTTP_CLOSE 444
93 #define NGX_HTTP_OWN_CODES 495
95 #define NGX_HTTPS_CERT_ERROR 495
96 #define NGX_HTTPS_NO_CERT 496
99 * We use the special code for the plain HTTP requests that are sent to
100 * HTTPS port to distinguish it from 4XX in an error page redirection
102 #define NGX_HTTP_TO_HTTPS 497
104 /* 498 is the canceled code for the requests with invalid host name */
107 * HTTP does not define the code for the case when a client closed
108 * the connection while we are processing its request so we introduce
109 * own code to log such situation when a client has closed the connection
110 * before we even try to send the HTTP header to it
112 #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
115 #define NGX_HTTP_INTERNAL_SERVER_ERROR 500
116 #define NGX_HTTP_NOT_IMPLEMENTED 501
117 #define NGX_HTTP_BAD_GATEWAY 502
118 #define NGX_HTTP_SERVICE_UNAVAILABLE 503
119 #define NGX_HTTP_GATEWAY_TIME_OUT 504
120 #define NGX_HTTP_INSUFFICIENT_STORAGE 507
123 #define NGX_HTTP_LOWLEVEL_BUFFERED 0xf0
124 #define NGX_HTTP_WRITE_BUFFERED 0x10
125 #define NGX_HTTP_GZIP_BUFFERED 0x20
126 #define NGX_HTTP_SSI_BUFFERED 0x01
127 #define NGX_HTTP_SUB_BUFFERED 0x02
128 #define NGX_HTTP_COPY_BUFFERED 0x04
131 typedef enum {
132 NGX_HTTP_INITING_REQUEST_STATE = 0,
133 NGX_HTTP_READING_REQUEST_STATE,
134 NGX_HTTP_PROCESS_REQUEST_STATE,
136 NGX_HTTP_CONNECT_UPSTREAM_STATE,
137 NGX_HTTP_WRITING_UPSTREAM_STATE,
138 NGX_HTTP_READING_UPSTREAM_STATE,
140 NGX_HTTP_WRITING_REQUEST_STATE,
141 NGX_HTTP_LINGERING_CLOSE_STATE,
142 NGX_HTTP_KEEPALIVE_STATE
143 } ngx_http_state_e;
146 typedef struct {
147 ngx_str_t name;
148 ngx_uint_t offset;
149 ngx_http_header_handler_pt handler;
150 } ngx_http_header_t;
153 typedef struct {
154 ngx_str_t name;
155 ngx_uint_t offset;
156 } ngx_http_header_out_t;
159 typedef struct {
160 ngx_list_t headers;
162 ngx_table_elt_t *host;
163 ngx_table_elt_t *connection;
164 ngx_table_elt_t *if_modified_since;
165 ngx_table_elt_t *user_agent;
166 ngx_table_elt_t *referer;
167 ngx_table_elt_t *content_length;
168 ngx_table_elt_t *content_type;
170 ngx_table_elt_t *range;
171 ngx_table_elt_t *if_range;
173 ngx_table_elt_t *transfer_encoding;
174 ngx_table_elt_t *expect;
176 #if (NGX_HTTP_GZIP)
177 ngx_table_elt_t *accept_encoding;
178 ngx_table_elt_t *via;
179 #endif
181 ngx_table_elt_t *authorization;
183 ngx_table_elt_t *keep_alive;
185 #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP)
186 ngx_table_elt_t *x_forwarded_for;
187 #endif
189 #if (NGX_HTTP_REALIP)
190 ngx_table_elt_t *x_real_ip;
191 #endif
193 #if (NGX_HTTP_HEADERS)
194 ngx_table_elt_t *accept;
195 ngx_table_elt_t *accept_language;
196 #endif
198 #if (NGX_HTTP_DAV)
199 ngx_table_elt_t *depth;
200 ngx_table_elt_t *destination;
201 ngx_table_elt_t *overwrite;
202 ngx_table_elt_t *date;
203 #endif
205 ngx_str_t user;
206 ngx_str_t passwd;
208 ngx_array_t cookies;
210 ngx_str_t server;
211 off_t content_length_n;
212 time_t keep_alive_n;
214 unsigned connection_type:2;
215 unsigned msie:1;
216 unsigned msie4:1;
217 unsigned opera:1;
218 unsigned gecko:1;
219 unsigned konqueror:1;
220 } ngx_http_headers_in_t;
223 typedef struct {
224 ngx_list_t headers;
226 ngx_uint_t status;
227 ngx_str_t status_line;
229 ngx_table_elt_t *server;
230 ngx_table_elt_t *date;
231 ngx_table_elt_t *content_length;
232 ngx_table_elt_t *content_encoding;
233 ngx_table_elt_t *location;
234 ngx_table_elt_t *refresh;
235 ngx_table_elt_t *last_modified;
236 ngx_table_elt_t *content_range;
237 ngx_table_elt_t *accept_ranges;
238 ngx_table_elt_t *www_authenticate;
239 ngx_table_elt_t *expires;
240 ngx_table_elt_t *etag;
242 ngx_str_t *override_charset;
244 size_t content_type_len;
245 ngx_str_t content_type;
246 ngx_str_t charset;
247 u_char *content_type_lowcase;
248 ngx_uint_t content_type_hash;
250 ngx_array_t cache_control;
252 off_t content_length_n;
253 time_t date_time;
254 time_t last_modified_time;
255 } ngx_http_headers_out_t;
258 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
260 typedef struct {
261 ngx_temp_file_t *temp_file;
262 ngx_chain_t *bufs;
263 ngx_buf_t *buf;
264 off_t rest;
265 ngx_chain_t *to_write;
266 ngx_http_client_body_handler_pt post_handler;
267 } ngx_http_request_body_t;
270 typedef struct {
271 ngx_http_request_t *request;
273 ngx_buf_t **busy;
274 ngx_int_t nbusy;
276 ngx_buf_t **free;
277 ngx_int_t nfree;
279 ngx_uint_t pipeline; /* unsigned pipeline:1; */
280 } ngx_http_connection_t;
283 typedef struct ngx_http_server_name_s ngx_http_server_name_t;
286 typedef struct {
287 ngx_hash_combined_t names;
289 ngx_uint_t nregex;
290 ngx_http_server_name_t *regex;
291 } ngx_http_virtual_names_t;
294 typedef void (*ngx_http_cleanup_pt)(void *data);
296 typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
298 struct ngx_http_cleanup_s {
299 ngx_http_cleanup_pt handler;
300 void *data;
301 ngx_http_cleanup_t *next;
305 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
306 void *data, ngx_int_t rc);
308 typedef struct {
309 ngx_http_post_subrequest_pt handler;
310 void *data;
311 } ngx_http_post_subrequest_t;
314 typedef struct ngx_http_postponed_request_s ngx_http_postponed_request_t;
316 struct ngx_http_postponed_request_s {
317 ngx_http_request_t *request;
318 ngx_chain_t *out;
319 ngx_http_postponed_request_t *next;
323 typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
324 typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r);
327 struct ngx_http_request_s {
328 uint32_t signature; /* "HTTP" */
330 ngx_connection_t *connection;
332 void **ctx;
333 void **main_conf;
334 void **srv_conf;
335 void **loc_conf;
337 ngx_http_event_handler_pt read_event_handler;
338 ngx_http_event_handler_pt write_event_handler;
340 ngx_http_cache_t *cache;
342 ngx_http_upstream_t *upstream;
343 ngx_array_t *upstream_states;
344 /* of ngx_http_upstream_state_t */
346 ngx_pool_t *pool;
347 ngx_buf_t *header_in;
349 ngx_http_headers_in_t headers_in;
350 ngx_http_headers_out_t headers_out;
352 ngx_http_request_body_t *request_body;
354 time_t lingering_time;
355 time_t start_sec;
356 ngx_msec_t start_msec;
358 ngx_uint_t method;
359 ngx_uint_t http_version;
361 ngx_str_t request_line;
362 ngx_str_t uri;
363 ngx_str_t args;
364 ngx_str_t exten;
365 ngx_str_t unparsed_uri;
367 ngx_str_t method_name;
368 ngx_str_t http_protocol;
370 ngx_chain_t *out;
371 ngx_http_request_t *main;
372 ngx_http_request_t *parent;
373 ngx_http_postponed_request_t *postponed;
374 ngx_http_post_subrequest_t *post_subrequest;
376 uint32_t in_addr;
377 ngx_uint_t port;
378 ngx_str_t *port_text; /* ":80" */
379 ngx_http_virtual_names_t *virtual_names;
381 ngx_int_t phase_handler;
382 ngx_http_handler_pt content_handler;
383 ngx_uint_t access_code;
385 ngx_http_variable_value_t *variables;
387 size_t limit_rate;
389 /* used to learn the Apache compatible response length without a header */
390 size_t header_size;
392 off_t request_length;
394 ngx_uint_t err_status;
396 ngx_http_connection_t *http_connection;
398 ngx_http_log_handler_pt log_handler;
400 ngx_http_cleanup_t *cleanup;
402 unsigned http_state:4;
404 /* URI with "/." and on Win32 with "//" */
405 unsigned complex_uri:1;
407 /* URI with "%" */
408 unsigned quoted_uri:1;
410 /* URI with "+" */
411 unsigned plus_in_uri:1;
413 /* URI with "\0" or "%00" */
414 unsigned zero_in_uri:1;
416 unsigned invalid_header:1;
418 unsigned valid_location:1;
419 unsigned valid_unparsed_uri:1;
420 unsigned uri_changed:1;
421 unsigned uri_changes:4;
423 unsigned request_body_in_single_buf:1;
424 unsigned request_body_in_file_only:1;
425 unsigned request_body_in_persistent_file:1;
426 unsigned request_body_in_clean_file:1;
427 unsigned request_body_file_group_access:1;
428 unsigned request_body_file_log_level:3;
430 unsigned fast_subrequest:1;
431 unsigned subrequest_in_memory:1;
433 unsigned gzip:2;
435 unsigned proxy:1;
436 unsigned bypass_cache:1;
437 unsigned no_cache:1;
439 #if (NGX_HTTP_REALIP)
442 * instead of using the request context data in ngx_http_realip_module
443 * we use the single bit in the request structure
445 unsigned realip_set:1;
447 #endif
450 * instead of using the request context data in ngx_http_limit_zone_module
451 * we use the single bit in the request structure
453 unsigned limit_zone_set:1;
455 #if 0
456 unsigned cacheable:1;
457 #endif
459 unsigned pipeline:1;
460 unsigned plain_http:1;
461 unsigned chunked:1;
462 unsigned header_only:1;
463 unsigned zero_body:1;
464 unsigned keepalive:1;
465 unsigned lingering_close:1;
466 unsigned discard_body:1;
467 unsigned internal:1;
468 unsigned error_page:1;
469 unsigned post_action:1;
470 unsigned request_complete:1;
471 unsigned request_output:1;
472 unsigned header_sent:1;
473 unsigned expect_tested:1;
474 unsigned root_tested:1;
475 unsigned done:1;
476 unsigned utf8:1;
478 unsigned buffered:4;
480 unsigned main_filter_need_in_memory:1;
481 unsigned filter_need_in_memory:1;
482 unsigned filter_need_temporary:1;
483 unsigned allow_ranges:1;
485 #if (NGX_STAT_STUB)
486 unsigned stat_reading:1;
487 unsigned stat_writing:1;
488 #endif
490 unsigned subrequests:8;
492 /* used to parse HTTP headers */
494 ngx_uint_t state;
495 u_char *uri_start;
496 u_char *uri_end;
497 u_char *uri_ext;
498 u_char *args_start;
499 u_char *request_start;
500 u_char *request_end;
501 u_char *method_end;
502 u_char *schema_start;
503 u_char *schema_end;
504 u_char *host_start;
505 u_char *host_end;
506 u_char *port_start;
507 u_char *port_end;
508 u_char *header_name_start;
509 u_char *header_name_end;
510 u_char *header_start;
511 u_char *header_end;
513 unsigned http_minor:16;
514 unsigned http_major:16;
516 ngx_uint_t header_hash;
517 ngx_uint_t lowcase_index;
518 u_char lowcase_header[NGX_HTTP_LC_HEADER_LEN];
522 extern ngx_http_header_t ngx_http_headers_in[];
523 extern ngx_http_header_out_t ngx_http_headers_out[];
526 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */