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
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
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
61 #define NGX_HTTP_SUBREQUEST_WAITED 4
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
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
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
89 /* Our own HTTP codes */
91 /* The special code to close connection without any response */
92 #define NGX_HTTP_CLOSE 444
94 #define NGX_HTTP_OWN_CODES 495
96 #define NGX_HTTPS_CERT_ERROR 495
97 #define NGX_HTTPS_NO_CERT 496
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
103 #define NGX_HTTP_TO_HTTPS 497
105 /* 498 is the canceled code for the requests with invalid host name */
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
113 #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
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
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
133 NGX_HTTP_INITING_REQUEST_STATE = 0,
134 NGX_HTTP_READING_REQUEST_STATE,
135 NGX_HTTP_PROCESS_REQUEST_STATE,
137 NGX_HTTP_CONNECT_UPSTREAM_STATE,
138 NGX_HTTP_WRITING_UPSTREAM_STATE,
139 NGX_HTTP_READING_UPSTREAM_STATE,
141 NGX_HTTP_WRITING_REQUEST_STATE,
142 NGX_HTTP_LINGERING_CLOSE_STATE,
143 NGX_HTTP_KEEPALIVE_STATE
150 ngx_http_header_handler_pt handler;
157 } ngx_http_header_out_t;
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;
171 ngx_table_elt_t *range;
172 ngx_table_elt_t *if_range;
174 ngx_table_elt_t *transfer_encoding;
175 ngx_table_elt_t *expect;
178 ngx_table_elt_t *accept_encoding;
179 ngx_table_elt_t *via;
182 ngx_table_elt_t *authorization;
184 ngx_table_elt_t *keep_alive;
186 #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP)
187 ngx_table_elt_t *x_forwarded_for;
190 #if (NGX_HTTP_REALIP)
191 ngx_table_elt_t *x_real_ip;
194 #if (NGX_HTTP_HEADERS)
195 ngx_table_elt_t *accept;
196 ngx_table_elt_t *accept_language;
200 ngx_table_elt_t *depth;
201 ngx_table_elt_t *destination;
202 ngx_table_elt_t *overwrite;
203 ngx_table_elt_t *date;
212 off_t content_length_n;
215 unsigned connection_type:2;
221 unsigned konqueror:1;
222 } ngx_http_headers_in_t;
229 ngx_str_t status_line;
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;
244 ngx_str_t *override_charset;
246 size_t content_type_len;
247 ngx_str_t content_type;
249 u_char *content_type_lowcase;
250 ngx_uint_t content_type_hash;
252 ngx_array_t cache_control;
254 off_t content_length_n;
256 time_t last_modified_time;
257 } ngx_http_headers_out_t;
260 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
263 ngx_temp_file_t *temp_file;
267 ngx_chain_t *to_write;
268 ngx_http_client_body_handler_pt post_handler;
269 } ngx_http_request_body_t;
273 ngx_http_request_t *request;
281 ngx_uint_t pipeline; /* unsigned pipeline:1; */
282 } ngx_http_connection_t;
285 typedef struct ngx_http_server_name_s ngx_http_server_name_t;
289 ngx_hash_combined_t names;
292 ngx_http_server_name_t *regex;
293 } ngx_http_virtual_names_t;
296 typedef void (*ngx_http_cleanup_pt)(void *data);
298 typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
300 struct ngx_http_cleanup_s {
301 ngx_http_cleanup_pt handler;
303 ngx_http_cleanup_t *next;
307 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
308 void *data, ngx_int_t rc);
311 ngx_http_post_subrequest_pt handler;
313 } ngx_http_post_subrequest_t;
316 typedef struct ngx_http_postponed_request_s ngx_http_postponed_request_t;
318 struct ngx_http_postponed_request_s {
319 ngx_http_request_t *request;
321 ngx_http_postponed_request_t *next;
325 typedef struct ngx_http_posted_request_s ngx_http_posted_request_t;
327 struct ngx_http_posted_request_s {
328 ngx_http_request_t *request;
329 ngx_http_posted_request_t *next;
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);
337 struct ngx_http_request_s {
338 uint32_t signature; /* "HTTP" */
340 ngx_connection_t *connection;
347 ngx_http_event_handler_pt read_event_handler;
348 ngx_http_event_handler_pt write_event_handler;
350 ngx_http_cache_t *cache;
352 ngx_http_upstream_t *upstream;
353 ngx_array_t *upstream_states;
354 /* of ngx_http_upstream_state_t */
357 ngx_buf_t *header_in;
359 ngx_http_headers_in_t headers_in;
360 ngx_http_headers_out_t headers_out;
362 ngx_http_request_body_t *request_body;
364 time_t lingering_time;
366 ngx_msec_t start_msec;
369 ngx_uint_t http_version;
371 ngx_str_t request_line;
375 ngx_str_t unparsed_uri;
377 ngx_str_t method_name;
378 ngx_str_t http_protocol;
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;
389 ngx_str_t *port_text; /* ":80" */
390 ngx_http_virtual_names_t *virtual_names;
392 ngx_int_t phase_handler;
393 ngx_http_handler_pt content_handler;
394 ngx_uint_t access_code;
396 ngx_http_variable_value_t *variables;
400 /* used to learn the Apache compatible response length without a header */
403 off_t request_length;
405 ngx_uint_t err_status;
407 ngx_http_connection_t *http_connection;
409 ngx_http_log_handler_pt log_handler;
411 ngx_http_cleanup_t *cleanup;
413 unsigned http_state:4;
415 /* URI with "/." and on Win32 with "//" */
416 unsigned complex_uri:1;
419 unsigned quoted_uri:1;
422 unsigned plus_in_uri:1;
424 /* URI with "\0" or "%00" */
425 unsigned zero_in_uri:1;
427 unsigned invalid_header:1;
429 unsigned valid_location:1;
430 unsigned valid_unparsed_uri:1;
431 unsigned uri_changed:1;
432 unsigned uri_changes:4;
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;
441 unsigned subrequest_in_memory:1;
447 unsigned bypass_cache:1;
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
455 unsigned limit_zone_set:1;
456 unsigned limit_req_set:1;
459 unsigned cacheable:1;
463 unsigned plain_http: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;
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;
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;
490 unsigned stat_reading:1;
491 unsigned stat_writing:1;
494 unsigned subrequests:8;
496 /* used to parse HTTP headers */
503 u_char *request_start;
506 u_char *schema_start;
512 u_char *header_name_start;
513 u_char *header_name_end;
514 u_char *header_start;
517 unsigned http_minor:16;
518 unsigned http_major:16;
520 ngx_uint_t header_hash;
521 ngx_uint_t lowcase_index;
522 u_char lowcase_header[NGX_HTTP_LC_HEADER_LEN];
526 extern ngx_http_header_t ngx_http_headers_in[];
527 extern ngx_http_header_out_t ngx_http_headers_out[];
530 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */