3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
9 #define _NGX_HTTP_REQUEST_H_INCLUDED_
12 #define NGX_HTTP_MAX_URI_CHANGES 10
13 #define NGX_HTTP_MAX_SUBREQUESTS 200
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_PATCH 0x4000
42 #define NGX_HTTP_TRACE 0x8000
44 #define NGX_HTTP_CONNECTION_CLOSE 1
45 #define NGX_HTTP_CONNECTION_KEEP_ALIVE 2
51 #define NGX_HTTP_PARSE_HEADER_DONE 1
53 #define NGX_HTTP_CLIENT_ERROR 10
54 #define NGX_HTTP_PARSE_INVALID_METHOD 10
55 #define NGX_HTTP_PARSE_INVALID_REQUEST 11
56 #define NGX_HTTP_PARSE_INVALID_09_METHOD 12
58 #define NGX_HTTP_PARSE_INVALID_HEADER 13
62 #define NGX_HTTP_SUBREQUEST_IN_MEMORY 2
63 #define NGX_HTTP_SUBREQUEST_WAITED 4
64 #define NGX_HTTP_LOG_UNSAFE 8
67 #define NGX_HTTP_CONTINUE 100
68 #define NGX_HTTP_SWITCHING_PROTOCOLS 101
69 #define NGX_HTTP_PROCESSING 102
71 #define NGX_HTTP_OK 200
72 #define NGX_HTTP_CREATED 201
73 #define NGX_HTTP_ACCEPTED 202
74 #define NGX_HTTP_NO_CONTENT 204
75 #define NGX_HTTP_PARTIAL_CONTENT 206
77 #define NGX_HTTP_SPECIAL_RESPONSE 300
78 #define NGX_HTTP_MOVED_PERMANENTLY 301
79 #define NGX_HTTP_MOVED_TEMPORARILY 302
80 #define NGX_HTTP_SEE_OTHER 303
81 #define NGX_HTTP_NOT_MODIFIED 304
82 #define NGX_HTTP_TEMPORARY_REDIRECT 307
84 #define NGX_HTTP_BAD_REQUEST 400
85 #define NGX_HTTP_UNAUTHORIZED 401
86 #define NGX_HTTP_FORBIDDEN 403
87 #define NGX_HTTP_NOT_FOUND 404
88 #define NGX_HTTP_NOT_ALLOWED 405
89 #define NGX_HTTP_REQUEST_TIME_OUT 408
90 #define NGX_HTTP_CONFLICT 409
91 #define NGX_HTTP_LENGTH_REQUIRED 411
92 #define NGX_HTTP_PRECONDITION_FAILED 412
93 #define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE 413
94 #define NGX_HTTP_REQUEST_URI_TOO_LARGE 414
95 #define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE 415
96 #define NGX_HTTP_RANGE_NOT_SATISFIABLE 416
99 /* Our own HTTP codes */
101 /* The special code to close connection without any response */
102 #define NGX_HTTP_CLOSE 444
104 #define NGX_HTTP_NGINX_CODES 494
106 #define NGX_HTTP_REQUEST_HEADER_TOO_LARGE 494
108 #define NGX_HTTPS_CERT_ERROR 495
109 #define NGX_HTTPS_NO_CERT 496
112 * We use the special code for the plain HTTP requests that are sent to
113 * HTTPS port to distinguish it from 4XX in an error page redirection
115 #define NGX_HTTP_TO_HTTPS 497
117 /* 498 is the canceled code for the requests with invalid host name */
120 * HTTP does not define the code for the case when a client closed
121 * the connection while we are processing its request so we introduce
122 * own code to log such situation when a client has closed the connection
123 * before we even try to send the HTTP header to it
125 #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
128 #define NGX_HTTP_INTERNAL_SERVER_ERROR 500
129 #define NGX_HTTP_NOT_IMPLEMENTED 501
130 #define NGX_HTTP_BAD_GATEWAY 502
131 #define NGX_HTTP_SERVICE_UNAVAILABLE 503
132 #define NGX_HTTP_GATEWAY_TIME_OUT 504
133 #define NGX_HTTP_INSUFFICIENT_STORAGE 507
136 #define NGX_HTTP_LOWLEVEL_BUFFERED 0xf0
137 #define NGX_HTTP_WRITE_BUFFERED 0x10
138 #define NGX_HTTP_GZIP_BUFFERED 0x20
139 #define NGX_HTTP_SSI_BUFFERED 0x01
140 #define NGX_HTTP_SUB_BUFFERED 0x02
141 #define NGX_HTTP_COPY_BUFFERED 0x04
145 NGX_HTTP_INITING_REQUEST_STATE
= 0,
146 NGX_HTTP_READING_REQUEST_STATE
,
147 NGX_HTTP_PROCESS_REQUEST_STATE
,
149 NGX_HTTP_CONNECT_UPSTREAM_STATE
,
150 NGX_HTTP_WRITING_UPSTREAM_STATE
,
151 NGX_HTTP_READING_UPSTREAM_STATE
,
153 NGX_HTTP_WRITING_REQUEST_STATE
,
154 NGX_HTTP_LINGERING_CLOSE_STATE
,
155 NGX_HTTP_KEEPALIVE_STATE
162 ngx_http_header_handler_pt handler
;
169 } ngx_http_header_out_t
;
175 ngx_table_elt_t
*host
;
176 ngx_table_elt_t
*connection
;
177 ngx_table_elt_t
*if_modified_since
;
178 ngx_table_elt_t
*if_unmodified_since
;
179 ngx_table_elt_t
*if_match
;
180 ngx_table_elt_t
*if_none_match
;
181 ngx_table_elt_t
*user_agent
;
182 ngx_table_elt_t
*referer
;
183 ngx_table_elt_t
*content_length
;
184 ngx_table_elt_t
*content_type
;
186 ngx_table_elt_t
*range
;
187 ngx_table_elt_t
*if_range
;
189 ngx_table_elt_t
*transfer_encoding
;
190 ngx_table_elt_t
*expect
;
191 ngx_table_elt_t
*upgrade
;
194 ngx_table_elt_t
*accept_encoding
;
195 ngx_table_elt_t
*via
;
198 ngx_table_elt_t
*authorization
;
200 ngx_table_elt_t
*keep_alive
;
202 #if (NGX_HTTP_X_FORWARDED_FOR)
203 ngx_array_t x_forwarded_for
;
206 #if (NGX_HTTP_REALIP)
207 ngx_table_elt_t
*x_real_ip
;
210 #if (NGX_HTTP_HEADERS)
211 ngx_table_elt_t
*accept
;
212 ngx_table_elt_t
*accept_language
;
216 ngx_table_elt_t
*depth
;
217 ngx_table_elt_t
*destination
;
218 ngx_table_elt_t
*overwrite
;
219 ngx_table_elt_t
*date
;
228 off_t content_length_n
;
231 unsigned connection_type
:2;
239 unsigned konqueror
:1;
240 } ngx_http_headers_in_t
;
247 ngx_str_t status_line
;
249 ngx_table_elt_t
*server
;
250 ngx_table_elt_t
*date
;
251 ngx_table_elt_t
*content_length
;
252 ngx_table_elt_t
*content_encoding
;
253 ngx_table_elt_t
*location
;
254 ngx_table_elt_t
*refresh
;
255 ngx_table_elt_t
*last_modified
;
256 ngx_table_elt_t
*content_range
;
257 ngx_table_elt_t
*accept_ranges
;
258 ngx_table_elt_t
*www_authenticate
;
259 ngx_table_elt_t
*expires
;
260 ngx_table_elt_t
*etag
;
262 ngx_str_t
*override_charset
;
264 size_t content_type_len
;
265 ngx_str_t content_type
;
267 u_char
*content_type_lowcase
;
268 ngx_uint_t content_type_hash
;
270 ngx_array_t cache_control
;
272 off_t content_length_n
;
274 time_t last_modified_time
;
275 } ngx_http_headers_out_t
;
278 typedef void (*ngx_http_client_body_handler_pt
)(ngx_http_request_t
*r
);
281 ngx_temp_file_t
*temp_file
;
287 ngx_http_chunked_t
*chunked
;
288 ngx_http_client_body_handler_pt post_handler
;
289 } ngx_http_request_body_t
;
292 typedef struct ngx_http_addr_conf_s ngx_http_addr_conf_t
;
295 ngx_http_addr_conf_t
*addr_conf
;
296 ngx_http_conf_ctx_t
*conf_ctx
;
298 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
299 ngx_str_t
*ssl_servername
;
301 ngx_http_regex_t
*ssl_servername_regex
;
312 ngx_uint_t ssl
; /* unsigned ssl:1; */
314 } ngx_http_connection_t
;
317 typedef void (*ngx_http_cleanup_pt
)(void *data
);
319 typedef struct ngx_http_cleanup_s ngx_http_cleanup_t
;
321 struct ngx_http_cleanup_s
{
322 ngx_http_cleanup_pt handler
;
324 ngx_http_cleanup_t
*next
;
328 typedef ngx_int_t (*ngx_http_post_subrequest_pt
)(ngx_http_request_t
*r
,
329 void *data
, ngx_int_t rc
);
332 ngx_http_post_subrequest_pt handler
;
334 } ngx_http_post_subrequest_t
;
337 typedef struct ngx_http_postponed_request_s ngx_http_postponed_request_t
;
339 struct ngx_http_postponed_request_s
{
340 ngx_http_request_t
*request
;
342 ngx_http_postponed_request_t
*next
;
346 typedef struct ngx_http_posted_request_s ngx_http_posted_request_t
;
348 struct ngx_http_posted_request_s
{
349 ngx_http_request_t
*request
;
350 ngx_http_posted_request_t
*next
;
354 typedef ngx_int_t (*ngx_http_handler_pt
)(ngx_http_request_t
*r
);
355 typedef void (*ngx_http_event_handler_pt
)(ngx_http_request_t
*r
);
358 struct ngx_http_request_s
{
359 uint32_t signature
; /* "HTTP" */
361 ngx_connection_t
*connection
;
368 ngx_http_event_handler_pt read_event_handler
;
369 ngx_http_event_handler_pt write_event_handler
;
372 ngx_http_cache_t
*cache
;
375 ngx_http_upstream_t
*upstream
;
376 ngx_array_t
*upstream_states
;
377 /* of ngx_http_upstream_state_t */
380 ngx_buf_t
*header_in
;
382 ngx_http_headers_in_t headers_in
;
383 ngx_http_headers_out_t headers_out
;
385 ngx_http_request_body_t
*request_body
;
387 time_t lingering_time
;
389 ngx_msec_t start_msec
;
392 ngx_uint_t http_version
;
394 ngx_str_t request_line
;
398 ngx_str_t unparsed_uri
;
400 ngx_str_t method_name
;
401 ngx_str_t http_protocol
;
404 ngx_http_request_t
*main
;
405 ngx_http_request_t
*parent
;
406 ngx_http_postponed_request_t
*postponed
;
407 ngx_http_post_subrequest_t
*post_subrequest
;
408 ngx_http_posted_request_t
*posted_requests
;
410 ngx_int_t phase_handler
;
411 ngx_http_handler_pt content_handler
;
412 ngx_uint_t access_code
;
414 ngx_http_variable_value_t
*variables
;
417 ngx_uint_t ncaptures
;
419 u_char
*captures_data
;
424 /* used to learn the Apache compatible response length without a header */
427 off_t request_length
;
429 ngx_uint_t err_status
;
431 ngx_http_connection_t
*http_connection
;
433 ngx_http_spdy_stream_t
*spdy_stream
;
436 ngx_http_log_handler_pt log_handler
;
438 ngx_http_cleanup_t
*cleanup
;
440 unsigned subrequests
:8;
446 unsigned http_state
:4;
448 /* URI with "/." and on Win32 with "//" */
449 unsigned complex_uri
:1;
452 unsigned quoted_uri
:1;
455 unsigned plus_in_uri
:1;
458 unsigned space_in_uri
:1;
460 unsigned invalid_header
:1;
462 unsigned add_uri_to_alias
:1;
463 unsigned valid_location
:1;
464 unsigned valid_unparsed_uri
:1;
465 unsigned uri_changed
:1;
466 unsigned uri_changes
:4;
468 unsigned request_body_in_single_buf
:1;
469 unsigned request_body_in_file_only
:1;
470 unsigned request_body_in_persistent_file
:1;
471 unsigned request_body_in_clean_file
:1;
472 unsigned request_body_file_group_access
:1;
473 unsigned request_body_file_log_level
:3;
475 unsigned subrequest_in_memory
:1;
483 unsigned gzip_tested
:1;
485 unsigned gzip_vary
:1;
489 unsigned bypass_cache
:1;
493 * instead of using the request context data in
494 * ngx_http_limit_conn_module and ngx_http_limit_req_module
495 * we use the single bits in the request structure
497 unsigned limit_conn_set
:1;
498 unsigned limit_req_set
:1;
501 unsigned cacheable
:1;
506 unsigned header_only
:1;
507 unsigned keepalive
:1;
508 unsigned lingering_close
:1;
509 unsigned discard_body
:1;
511 unsigned error_page
:1;
512 unsigned ignore_content_encoding
:1;
513 unsigned filter_finalize
:1;
514 unsigned post_action
:1;
515 unsigned request_complete
:1;
516 unsigned request_output
:1;
517 unsigned header_sent
:1;
518 unsigned expect_tested
:1;
519 unsigned root_tested
:1;
525 unsigned main_filter_need_in_memory
:1;
526 unsigned filter_need_in_memory
:1;
527 unsigned filter_need_temporary
:1;
528 unsigned allow_ranges
:1;
531 unsigned stat_reading
:1;
532 unsigned stat_writing
:1;
535 /* used to parse HTTP headers */
539 ngx_uint_t header_hash
;
540 ngx_uint_t lowcase_index
;
541 u_char lowcase_header
[NGX_HTTP_LC_HEADER_LEN
];
543 u_char
*header_name_start
;
544 u_char
*header_name_end
;
545 u_char
*header_start
;
549 * a memory that can be reused after parsing a request line
550 * via ngx_http_ephemeral_t
557 u_char
*request_start
;
560 u_char
*schema_start
;
567 unsigned http_minor
:16;
568 unsigned http_major
:16;
573 ngx_http_posted_request_t terminal_posted_request
;
574 #if (NGX_HAVE_AIO_SENDFILE)
577 } ngx_http_ephemeral_t
;
580 extern ngx_http_header_t ngx_http_headers_in
[];
581 extern ngx_http_header_out_t ngx_http_headers_out
[];
584 #define ngx_http_set_connection_log(c, l) \
586 c->log->file = l->file; \
587 if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { \
588 c->log->log_level = l->log_level; \
592 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */