Ticket #7: ngx_http_request.h

File ngx_http_request.h, 18.5 KB (added by Marc VERRIERE, 15 years ago)

nginx request source (for multi status)

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