3 * Copyright (C) Igor Sysoev
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
13 #define NGX_HTTP_MAX_CAPTURES 9
16 #define NGX_HTTP_LC_HEADER_LEN 32
19 #define NGX_HTTP_DISCARD_BUFFER_SIZE 4096
20 #define NGX_HTTP_LINGERING_BUFFER_SIZE 4096
23 #define NGX_HTTP_VERSION_9 9
24 #define NGX_HTTP_VERSION_10 1000
25 #define NGX_HTTP_VERSION_11 1001
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
43 #define NGX_HTTP_CONNECTION_CLOSE 1
44 #define NGX_HTTP_CONNECTION_KEEP_ALIVE 2
50 #define NGX_HTTP_PARSE_HEADER_DONE 1
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
57 #define NGX_HTTP_PARSE_INVALID_HEADER 13
60 #define NGX_HTTP_ZERO_IN_URI 1
61 #define NGX_HTTP_SUBREQUEST_IN_MEMORY 2
62 #define NGX_HTTP_SUBREQUEST_WAITED 4
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
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
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
90 /* Our own HTTP codes */
92 /* The special code to close connection without any response */
93 #define NGX_HTTP_CLOSE 444
95 #define NGX_HTTP_OWN_CODES 495
97 #define NGX_HTTPS_CERT_ERROR 495
98 #define NGX_HTTPS_NO_CERT 496
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
104 #define NGX_HTTP_TO_HTTPS 497
106 /* 498 is the canceled code for the requests with invalid host name */
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
114 #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
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
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
134 NGX_HTTP_INITING_REQUEST_STATE = 0,
135 NGX_HTTP_READING_REQUEST_STATE,
136 NGX_HTTP_PROCESS_REQUEST_STATE,
138 NGX_HTTP_CONNECT_UPSTREAM_STATE,
139 NGX_HTTP_WRITING_UPSTREAM_STATE,
140 NGX_HTTP_READING_UPSTREAM_STATE,
142 NGX_HTTP_WRITING_REQUEST_STATE,
143 NGX_HTTP_LINGERING_CLOSE_STATE,
144 NGX_HTTP_KEEPALIVE_STATE
151 ngx_http_header_handler_pt handler;
158 } ngx_http_header_out_t;
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;
172 ngx_table_elt_t *range;
173 ngx_table_elt_t *if_range;
175 ngx_table_elt_t *transfer_encoding;
176 ngx_table_elt_t *expect;
179 ngx_table_elt_t *accept_encoding;
180 ngx_table_elt_t *via;
183 ngx_table_elt_t *authorization;
185 ngx_table_elt_t *keep_alive;
187 #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP)
188 ngx_table_elt_t *x_forwarded_for;
191 #if (NGX_HTTP_REALIP)
192 ngx_table_elt_t *x_real_ip;
195 #if (NGX_HTTP_HEADERS)
196 ngx_table_elt_t *accept;
197 ngx_table_elt_t *accept_language;
201 ngx_table_elt_t *depth;
202 ngx_table_elt_t *destination;
203 ngx_table_elt_t *overwrite;
204 ngx_table_elt_t *date;
213 off_t content_length_n;
216 unsigned connection_type:2;
222 unsigned konqueror:1;
223 } ngx_http_headers_in_t;
230 ngx_str_t status_line;
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;
245 ngx_str_t *override_charset;
247 size_t content_type_len;
248 ngx_str_t content_type;
250 u_char *content_type_lowcase;
251 ngx_uint_t content_type_hash;
253 ngx_array_t cache_control;
255 off_t content_length_n;
257 time_t last_modified_time;
258 } ngx_http_headers_out_t;
261 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
264 ngx_temp_file_t *temp_file;
268 ngx_chain_t *to_write;
269 ngx_http_client_body_handler_pt post_handler;
270 } ngx_http_request_body_t;
274 ngx_http_request_t *request;
282 ngx_uint_t pipeline; /* unsigned pipeline:1; */
283 } ngx_http_connection_t;
286 typedef struct ngx_http_server_name_s ngx_http_server_name_t;
290 ngx_hash_combined_t names;
293 ngx_http_server_name_t *regex;
294 } ngx_http_virtual_names_t;
297 typedef void (*ngx_http_cleanup_pt)(void *data);
299 typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
301 struct ngx_http_cleanup_s {
302 ngx_http_cleanup_pt handler;
304 ngx_http_cleanup_t *next;
308 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
309 void *data, ngx_int_t rc);
312 ngx_http_post_subrequest_pt handler;
314 } ngx_http_post_subrequest_t;
317 typedef struct ngx_http_postponed_request_s ngx_http_postponed_request_t;
319 struct ngx_http_postponed_request_s {
320 ngx_http_request_t *request;
322 ngx_http_postponed_request_t *next;
326 typedef struct ngx_http_posted_request_s ngx_http_posted_request_t;
328 struct ngx_http_posted_request_s {
329 ngx_http_request_t *request;
330 ngx_http_posted_request_t *next;
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);
338 struct ngx_http_request_s {
339 uint32_t signature; /* "HTTP" */
341 ngx_connection_t *connection;
348 ngx_http_event_handler_pt read_event_handler;
349 ngx_http_event_handler_pt write_event_handler;
351 ngx_http_cache_t *cache;
353 ngx_http_upstream_t *upstream;
354 ngx_array_t *upstream_states;
355 /* of ngx_http_upstream_state_t */
358 ngx_buf_t *header_in;
360 ngx_http_headers_in_t headers_in;
361 ngx_http_headers_out_t headers_out;
363 ngx_http_request_body_t *request_body;
365 time_t lingering_time;
367 ngx_msec_t start_msec;
370 ngx_uint_t http_version;
372 ngx_str_t request_line;
376 ngx_str_t unparsed_uri;
378 ngx_str_t method_name;
379 ngx_str_t http_protocol;
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;
388 ngx_int_t phase_handler;
389 ngx_http_handler_pt content_handler;
390 ngx_uint_t access_code;
392 ngx_http_variable_value_t *variables;
395 ngx_uint_t ncaptures;
397 u_char *captures_data;
402 /* used to learn the Apache compatible response length without a header */
405 off_t request_length;
407 ngx_uint_t err_status;
409 ngx_http_connection_t *http_connection;
411 ngx_http_log_handler_pt log_handler;
413 ngx_http_cleanup_t *cleanup;
415 unsigned http_state:4;
417 /* URI with "/." and on Win32 with "//" */
418 unsigned complex_uri:1;
421 unsigned quoted_uri:1;
424 unsigned plus_in_uri:1;
426 /* URI with "\0" or "%00" */
427 unsigned zero_in_uri:1;
429 unsigned invalid_header:1;
431 unsigned valid_location:1;
432 unsigned valid_unparsed_uri:1;
433 unsigned uri_changed:1;
434 unsigned uri_changes:4;
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;
443 unsigned subrequest_in_memory:1;
449 unsigned bypass_cache:1;
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
457 unsigned limit_zone_set:1;
458 unsigned limit_req_set:1;
461 unsigned cacheable:1;
465 unsigned plain_http: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;
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;
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;
492 unsigned stat_reading:1;
493 unsigned stat_writing:1;
496 unsigned subrequests:8;
498 /* used to parse HTTP headers */
505 u_char *request_start;
508 u_char *schema_start;
514 u_char *header_name_start;
515 u_char *header_name_end;
516 u_char *header_start;
519 unsigned http_minor:16;
520 unsigned http_major:16;
522 ngx_uint_t header_hash;
523 ngx_uint_t lowcase_index;
524 u_char lowcase_header[NGX_HTTP_LC_HEADER_LEN];
528 extern ngx_http_header_t ngx_http_headers_in[];
529 extern ngx_http_header_out_t ngx_http_headers_out[];
532 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */