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_TRACE 0x4000
41
42 #define NGX_HTTP_CONNECTION_CLOSE 1
43 #define NGX_HTTP_CONNECTION_KEEP_ALIVE 2
44
45
46 #define NGX_NONE 1
47
48
49 #define NGX_HTTP_PARSE_HEADER_DONE 1
50
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
55
56 #define NGX_HTTP_PARSE_INVALID_HEADER 13
57
58
59 #define NGX_HTTP_ZERO_IN_URI 1
60 #define NGX_HTTP_SUBREQUEST_IN_MEMORY 2
61
62
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
67
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
72
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
86
87
88 /* Our own HTTP codes */
89
90 /* The special code to close connection without any response */
91 #define NGX_HTTP_CLOSE 444
92
93 #define NGX_HTTP_OWN_CODES 495
94
95 #define NGX_HTTPS_CERT_ERROR 495
96 #define NGX_HTTPS_NO_CERT 496
97
98 /*
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
101 */
102 #define NGX_HTTP_TO_HTTPS 497
103
104 /* 498 is the canceled code for the requests with invalid host name */
105
106 /*
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
111 */
112 #define NGX_HTTP_CLIENT_CLOSED_REQUEST 499
113
114
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
121
122
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
129
130
131 typedef enum {
132 NGX_HTTP_INITING_REQUEST_STATE = 0,
133 NGX_HTTP_READING_REQUEST_STATE,
134 NGX_HTTP_PROCESS_REQUEST_STATE,
135
136 NGX_HTTP_CONNECT_UPSTREAM_STATE,
137 NGX_HTTP_WRITING_UPSTREAM_STATE,
138 NGX_HTTP_READING_UPSTREAM_STATE,
139
140 NGX_HTTP_WRITING_REQUEST_STATE,
141 NGX_HTTP_LINGERING_CLOSE_STATE,
142 NGX_HTTP_KEEPALIVE_STATE
143 } ngx_http_state_e;
144
145
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;
151
152
153 typedef struct {
154 ngx_str_t name;
155 ngx_uint_t offset;
156 } ngx_http_header_out_t;
157
158
159 typedef struct {
160 ngx_list_t headers;
161
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;
169
170 ngx_table_elt_t *range;
171 ngx_table_elt_t *if_range;
172
173 ngx_table_elt_t *transfer_encoding;
174
175 #if (NGX_HTTP_GZIP)
176 ngx_table_elt_t *accept_encoding;
177 ngx_table_elt_t *via;
178 #endif
179
180 ngx_table_elt_t *authorization;
181
182 ngx_table_elt_t *keep_alive;
183
184 #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP)
185 ngx_table_elt_t *x_forwarded_for;
186 #endif
187
188 #if (NGX_HTTP_REALIP)
189 ngx_table_elt_t *x_real_ip;
190 #endif
191
192 #if (NGX_HTTP_HEADERS)
193 ngx_table_elt_t *accept;
194 ngx_table_elt_t *accept_language;
195 #endif
196
197 #if (NGX_HTTP_DAV)
198 ngx_table_elt_t *depth;
199 ngx_table_elt_t *destination;
200 ngx_table_elt_t *overwrite;
201 ngx_table_elt_t *date;
202 #endif
203
204 ngx_str_t user;
205 ngx_str_t passwd;
206
207 ngx_array_t cookies;
208
209 size_t host_name_len;
210 off_t content_length_n;
211 time_t keep_alive_n;
212
213 unsigned connection_type:2;
214 unsigned msie:1;
215 unsigned msie4:1;
216 unsigned opera:1;
217 unsigned gecko:1;
218 unsigned konqueror:1;
219 } ngx_http_headers_in_t;
220
221
222 typedef struct {
223 ngx_list_t headers;
224
225 ngx_uint_t status;
226 ngx_str_t status_line;
227
228 ngx_table_elt_t *server;
229 ngx_table_elt_t *date;
230 ngx_table_elt_t *content_length;
231 ngx_table_elt_t *content_encoding;
232 ngx_table_elt_t *location;
233 ngx_table_elt_t *refresh;
234 ngx_table_elt_t *last_modified;
235 ngx_table_elt_t *content_range;
236 ngx_table_elt_t *accept_ranges;
237 ngx_table_elt_t *www_authenticate;
238 ngx_table_elt_t *expires;
239 ngx_table_elt_t *etag;
240
241 ngx_str_t *override_charset;
242
243 size_t content_type_len;
244 ngx_str_t content_type;
245 ngx_str_t charset;
246
247 ngx_array_t cache_control;
248
249 off_t content_length_n;
250 time_t date_time;
251 time_t last_modified_time;
252 } ngx_http_headers_out_t;
253
254
255 typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);
256
257 typedef struct {
258 ngx_temp_file_t *temp_file;
259 ngx_chain_t *bufs;
260 ngx_buf_t *buf;
261 off_t rest;
262 ngx_chain_t *to_write;
263 ngx_http_client_body_handler_pt post_handler;
264 } ngx_http_request_body_t;
265
266
267 typedef struct {
268 ngx_http_request_t *request;
269
270 ngx_buf_t **busy;
271 ngx_int_t nbusy;
272
273 ngx_buf_t **free;
274 ngx_int_t nfree;
275
276 ngx_uint_t pipeline; /* unsigned pipeline:1; */
277 } ngx_http_connection_t;
278
279
280 typedef struct ngx_http_server_name_s ngx_http_server_name_t;
281
282
283 typedef struct {
284 ngx_hash_combined_t names;
285
286 ngx_uint_t nregex;
287 ngx_http_server_name_t *regex;
288 } ngx_http_virtual_names_t;
289
290
291 typedef void (*ngx_http_cleanup_pt)(void *data);
292
293 typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
294
295 struct ngx_http_cleanup_s {
296 ngx_http_cleanup_pt handler;
297 void *data;
298 ngx_http_cleanup_t *next;
299 };
300
301
302 typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
303 void *data, ngx_int_t rc);
304
305 typedef struct {
306 ngx_http_post_subrequest_pt handler;
307 void *data;
308 } ngx_http_post_subrequest_t;
309
310
311 typedef struct ngx_http_postponed_request_s ngx_http_postponed_request_t;
312
313 struct ngx_http_postponed_request_s {
314 ngx_http_request_t *request;
315 ngx_chain_t *out;
316 ngx_http_postponed_request_t *next;
317 };
318
319
320 typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
321 typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r);
322
323
324 struct ngx_http_request_s {
325 uint32_t signature; /* "HTTP" */
326
327 ngx_connection_t *connection;
328
329 void **ctx;
330 void **main_conf;
331 void **srv_conf;
332 void **loc_conf;
333
334 ngx_http_event_handler_pt read_event_handler;
335 ngx_http_event_handler_pt write_event_handler;
336
337 ngx_http_cache_t *cache;
338
339 ngx_http_upstream_t *upstream;
340 ngx_array_t *upstream_states;
341 /* of ngx_http_upstream_state_t */
342
343 ngx_pool_t *pool;
344 ngx_buf_t *header_in;
345
346 ngx_http_headers_in_t headers_in;
347 ngx_http_headers_out_t headers_out;
348
349 ngx_http_request_body_t *request_body;
350
351 time_t lingering_time;
352 time_t start_sec;
353 ngx_msec_t start_msec;
354
355 ngx_uint_t method;
356 ngx_uint_t http_version;
357
358 ngx_str_t request_line;
359 ngx_str_t uri;
360 ngx_str_t args;
361 ngx_str_t exten;
362 ngx_str_t unparsed_uri;
363
364 ngx_str_t method_name;
365 ngx_str_t http_protocol;
366
367 ngx_chain_t *out;
368 ngx_http_request_t *main;
369 ngx_http_request_t *parent;
370 ngx_http_postponed_request_t *postponed;
371 ngx_http_post_subrequest_t *post_subrequest;
372
373 uint32_t in_addr;
374 ngx_uint_t port;
375 ngx_str_t *port_text; /* ":80" */
376 ngx_http_virtual_names_t *virtual_names;
377
378 ngx_int_t phase_handler;
379 ngx_http_handler_pt content_handler;
380 ngx_uint_t access_code;
381
382 ngx_http_variable_value_t *variables;
383
384 size_t limit_rate;
385
386 /* used to learn the Apache compatible response length without a header */
387 size_t header_size;
388
389 off_t request_length;
390
391 ngx_uint_t err_status;
392
393 ngx_http_connection_t *http_connection;
394
395 ngx_http_log_handler_pt log_handler;
396
397 ngx_http_cleanup_t *cleanup;
398
399 unsigned http_state:4;
400
401 /* URI with "/." and on Win32 with "//" */
402 unsigned complex_uri:1;
403
404 /* URI with "%" */
405 unsigned quoted_uri:1;
406
407 /* URI with "+" */
408 unsigned plus_in_uri:1;
409
410 /* URI with "\0" or "%00" */
411 unsigned zero_in_uri:1;
412
413 unsigned invalid_header:1;
414
415 unsigned valid_location:1;
416 unsigned valid_unparsed_uri:1;
417 unsigned uri_changed:1;
418 unsigned uri_changes:4;
419
420 unsigned request_body_in_single_buf:1;
421 unsigned request_body_in_file_only:1;
422 unsigned request_body_in_persistent_file:1;
423 unsigned request_body_in_clean_file:1;
424 unsigned request_body_file_group_access:1;
425 unsigned request_body_file_log_level:3;
426
427 unsigned fast_subrequest:1;
428 unsigned subrequest_in_memory:1;
429
430 unsigned gzip:2;
431
432 unsigned proxy:1;
433 unsigned bypass_cache:1;
434 unsigned no_cache:1;
435
436 #if (NGX_HTTP_REALIP)
437
438 /*
439 * instead of using the request context data in ngx_http_realip_module
440 * we use the single bit in the request structure
441 */
442 unsigned realip_set:1;
443
444 #endif
445
446 /*
447 * instead of using the request context data in ngx_http_limit_zone_module
448 * we use the single bit in the request structure
449 */
450 unsigned limit_zone_set:1;
451
452 #if 0
453 unsigned cacheable:1;
454 #endif
455
456 unsigned pipeline:1;
457 unsigned plain_http:1;
458 unsigned chunked:1;
459 unsigned header_only:1;
460 unsigned zero_body:1;
461 unsigned keepalive:1;
462 unsigned lingering_close:1;
463 unsigned discard_body:1;
464 unsigned internal:1;
465 unsigned error_page:1;
466 unsigned post_action:1;
467 unsigned request_complete:1;
468 unsigned request_output:1;
469 unsigned header_sent:1;
470 unsigned done:1;
471 unsigned utf8:1;
472
473 unsigned buffered:4;
474
475 unsigned main_filter_need_in_memory:1;
476 unsigned filter_need_in_memory:1;
477 unsigned filter_need_temporary:1;
478 unsigned allow_ranges:1;
479
480 #if (NGX_STAT_STUB)
481 unsigned stat_reading:1;
482 unsigned stat_writing:1;
483 #endif
484
485 unsigned subrequests:8;
486
487 /* used to parse HTTP headers */
488
489 ngx_uint_t state;
490 u_char *uri_start;
491 u_char *uri_end;
492 u_char *uri_ext;
493 u_char *args_start;
494 u_char *request_start;
495 u_char *request_end;
496 u_char *method_end;
497 u_char *schema_start;
498 u_char *schema_end;
499 u_char *host_start;
500 u_char *host_end;
501 u_char *port_start;
502 u_char *port_end;
503 u_char *header_name_start;
504 u_char *header_name_end;
505 u_char *header_start;
506 u_char *header_end;
507
508 unsigned http_minor:16;
509 unsigned http_major:16;
510
511 ngx_uint_t header_hash;
512 ngx_uint_t lowcase_index;
513 u_char lowcase_header[NGX_HTTP_LC_HEADER_LEN];
514 };
515
516
517 extern ngx_http_header_t ngx_http_headers_in[];
518 extern ngx_http_header_out_t ngx_http_headers_out[];
519
520
521 #endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */
522
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.