comparison src/http/ngx_http_event.c @ 95:b48066122884

nginx-0.0.1-2003-05-23-15:53:01 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 23 May 2003 11:53:01 +0000
parents 8220378432a8
children a23d010f356d
comparison
equal deleted inserted replaced
94:8220378432a8 95:b48066122884
56 56
57 57
58 static ngx_http_header_t headers_in[] = { 58 static ngx_http_header_t headers_in[] = {
59 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) }, 59 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) },
60 { ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) }, 60 { ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) },
61 { ngx_string("If-Modified-Since"), 61 { ngx_string("If-Modified-Since"),
62 offsetof(ngx_http_headers_in_t, if_modified_since) }, 62 offsetof(ngx_http_headers_in_t, if_modified_since) },
63 { ngx_string("Content-Length"), 63 { ngx_string("Content-Length"),
64 offsetof(ngx_http_headers_in_t, content_length) }, 64 offsetof(ngx_http_headers_in_t, content_length) },
65 65
66 #if 0 66 #if 0
67 67
68 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) }, 68 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
73 }; 73 };
74 74
75 75
76 void ngx_http_init_connection(ngx_connection_t *c) 76 void ngx_http_init_connection(ngx_connection_t *c)
77 { 77 {
78 int event; 78 int event;
79 ngx_event_t *rev; 79 ngx_event_t *rev;
80 ngx_http_log_ctx_t *lcx; 80 ngx_http_log_ctx_t *lcx;
81 ngx_http_conf_ctx_t *ctx;
81 82
82 c->addr_text.data = ngx_palloc(c->pool, c->addr_text_max_len); 83 c->addr_text.data = ngx_palloc(c->pool, c->addr_text_max_len);
83 if (c->addr_text.data == NULL) { 84 if (c->addr_text.data == NULL) {
84 ngx_http_close_connection(c); 85 ngx_http_close_connection(c);
85 return; 86 return;
136 } 137 }
137 138
138 139
139 static void ngx_http_init_request(ngx_event_t *rev) 140 static void ngx_http_init_request(ngx_event_t *rev)
140 { 141 {
141 ngx_connection_t *c; 142 ngx_connection_t *c;
142 ngx_http_request_t *r; 143 ngx_http_request_t *r;
143 ngx_http_conf_ctx_t *ctx; 144 ngx_http_conf_ctx_t *ctx;
144 ngx_http_core_main_conf_t *cmcf; 145 ngx_http_core_srv_conf_t *cscf;
145 146
146 c = rev->data; 147 c = rev->data;
147 ctx = c->ctx; 148 ctx = c->ctx;
148 149
149 cmcf = ngx_http_get_module_main_conf(ctx, ngx_http_core_module_ctx); 150 cscf = ngx_http_get_module_srv_conf(ctx, ngx_http_core_module_ctx);
151 cscf = ngx_http_get_module_srv_conf(cscf->ctx, ngx_http_core_module_ctx);
150 152
151 if (c->buffer == NULL) { 153 if (c->buffer == NULL) {
152 c->buffer = ngx_create_temp_hunk(c->pool, 154 c->buffer = ngx_create_temp_hunk(c->pool,
153 cmcf->client_header_buffer_size, 155 cscf->client_header_buffer_size,
154 0, 0); 156 0, 0);
155 if (c->buffer == NULL) { 157 if (c->buffer == NULL) {
156 ngx_http_close_connection(c); 158 ngx_http_close_connection(c);
157 return; 159 return;
158 } 160 }
162 if (r == NULL) { 164 if (r == NULL) {
163 ngx_http_close_connection(c); 165 ngx_http_close_connection(c);
164 return; 166 return;
165 } 167 }
166 168
167 r->pool = ngx_create_pool(cmcf->request_pool_size, c->log); 169 r->pool = ngx_create_pool(cscf->request_pool_size, c->log);
168 if (r->pool == NULL) { 170 if (r->pool == NULL) {
169 ngx_http_close_connection(c); 171 ngx_http_close_connection(c);
170 return; 172 return;
171 } 173 }
172 174
205 } 207 }
206 208
207 209
208 static void ngx_http_process_request_line(ngx_event_t *rev) 210 static void ngx_http_process_request_line(ngx_event_t *rev)
209 { 211 {
210 int rc, offset; 212 int rc, offset;
211 ssize_t n; 213 ssize_t n;
212 ngx_connection_t *c; 214 ngx_connection_t *c;
213 ngx_http_request_t *r; 215 ngx_http_request_t *r;
214 ngx_http_log_ctx_t *lcx; 216 ngx_http_log_ctx_t *lcx;
215 ngx_http_core_main_conf_t *cmcf; 217 ngx_http_core_srv_conf_t *cscf;
216 218
217 c = rev->data; 219 c = rev->data;
218 r = c->data; 220 r = c->data;
219 221
220 ngx_log_debug(rev->log, "http process request line"); 222 ngx_log_debug(rev->log, "http process request line");
235 237
236 if (rc == NGX_OK) { 238 if (rc == NGX_OK) {
237 239
238 /* the request line has been parsed successfully */ 240 /* the request line has been parsed successfully */
239 241
240 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx); 242 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
241 243
242 if (r->http_version >= NGX_HTTP_VERSION_10 244 if (r->http_version >= NGX_HTTP_VERSION_10
243 && cmcf->large_client_header == 0 245 && cscf->large_client_header == 0
244 && r->header_in->pos == r->header_in->end) 246 && r->header_in->pos == r->header_in->end)
245 { 247 {
246 /* no space for "\r\n" at the end of the header */ 248 /* no space for "\r\n" at the end of the header */
247 249
248 ngx_http_header_parse_error(r, NGX_HTTP_PARSE_TOO_LONG_URI); 250 ngx_http_header_parse_error(r, NGX_HTTP_PARSE_TOO_LONG_URI);
287 r->request_line.len = r->request_end - r->request_start; 289 r->request_line.len = r->request_end - r->request_start;
288 290
289 /* if the large client headers are enabled then 291 /* if the large client headers are enabled then
290 we need to copy a request line */ 292 we need to copy a request line */
291 293
292 if (cmcf->large_client_header) { 294 if (cscf->large_client_header) {
293 295
294 r->request_line.data = ngx_palloc(r->pool, r->request_line.len + 1); 296 r->request_line.data = ngx_palloc(r->pool, r->request_line.len + 1);
295 if (r->request_line.data == NULL) { 297 if (r->request_line.data == NULL) {
296 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 298 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
297 ngx_http_close_connection(c); 299 ngx_http_close_connection(c);
365 lcx = c->log->data; 367 lcx = c->log->data;
366 lcx->action = "reading client request headers"; 368 lcx->action = "reading client request headers";
367 lcx->url = r->unparsed_uri.data; 369 lcx->url = r->unparsed_uri.data;
368 r->headers_in.headers = ngx_create_table(r->pool, 10); 370 r->headers_in.headers = ngx_create_table(r->pool, 10);
369 371
370 if (cmcf->large_client_header 372 if (cscf->large_client_header
371 && r->header_in->pos == r->header_in->last) 373 && r->header_in->pos == r->header_in->last)
372 { 374 {
373 r->header_in->pos = r->header_in->last = r->header_in->start; 375 r->header_in->pos = r->header_in->last = r->header_in->start;
374 } 376 }
375 377
396 then we need to copy it to the start of the r->header_in hunk. 398 then we need to copy it to the start of the r->header_in hunk.
397 We need to copy it here only if the large client headers 399 We need to copy it here only if the large client headers
398 are enabled otherwise a request line had been already copied 400 are enabled otherwise a request line had been already copied
399 to the start of the r->header_in hunk in ngx_http_set_keepalive() */ 401 to the start of the r->header_in hunk in ngx_http_set_keepalive() */
400 402
401 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx); 403 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
402 404
403 if (cmcf->large_client_header) { 405 if (cscf->large_client_header) {
404 offset = r->request_start - r->header_in->start; 406 offset = r->request_start - r->header_in->start;
405 407
406 if (offset == 0) { 408 if (offset == 0) {
407 ngx_http_header_parse_error(r, NGX_HTTP_PARSE_TOO_LONG_URI); 409 ngx_http_header_parse_error(r, NGX_HTTP_PARSE_TOO_LONG_URI);
408 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_URI_TOO_LARGE); 410 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_URI_TOO_LARGE);
436 } 438 }
437 439
438 440
439 static void ngx_http_process_request_headers(ngx_event_t *rev) 441 static void ngx_http_process_request_headers(ngx_event_t *rev)
440 { 442 {
441 int rc, i, offset; 443 int rc, i, offset;
442 size_t len; 444 size_t len;
443 ssize_t n; 445 ssize_t n;
444 ngx_table_elt_t *h; 446 ngx_table_elt_t *h;
445 ngx_connection_t *c; 447 ngx_connection_t *c;
446 ngx_http_request_t *r; 448 ngx_http_request_t *r;
447 ngx_http_log_ctx_t *ctx; 449 ngx_http_log_ctx_t *ctx;
448 ngx_http_core_main_conf_t *cmcf; 450 ngx_http_core_srv_conf_t *cscf;
449 451
450 c = rev->data; 452 c = rev->data;
451 r = c->data; 453 r = c->data;
452 454
453 ngx_log_debug(rev->log, "http process request header line"); 455 ngx_log_debug(rev->log, "http process request header line");
486 h->value.len = r->header_end - r->header_start; 488 h->value.len = r->header_end - r->header_start;
487 489
488 /* if the large client headers are enabled then 490 /* if the large client headers are enabled then
489 we need to copy the header name and value */ 491 we need to copy the header name and value */
490 492
491 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx); 493 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
492 494
493 if (cmcf->large_client_header) { 495 if (cscf->large_client_header) {
494 h->key.data = ngx_palloc(r->pool, 496 h->key.data = ngx_palloc(r->pool,
495 h->key.len + 1 + h->value.len + 1); 497 h->key.len + 1 + h->value.len + 1);
496 if (h->key.data == NULL) { 498 if (h->key.data == NULL) {
497 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 499 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
498 ngx_http_close_connection(c); 500 ngx_http_close_connection(c);
522 } 524 }
523 525
524 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ 526 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _
525 h->key.data _ h->value.data); 527 h->key.data _ h->value.data);
526 528
527 if (cmcf->large_client_header 529 if (cscf->large_client_header
528 && r->header_in->pos == r->header_in->last) 530 && r->header_in->pos == r->header_in->last)
529 { 531 {
530 r->header_in->pos = r->header_in->last = r->header_in->start; 532 r->header_in->pos = r->header_in->last = r->header_in->start;
531 } 533 }
532 534
591 if (r->header_in->last == r->header_in->end) { 593 if (r->header_in->last == r->header_in->end) {
592 594
593 /* if the large client headers are enabled then 595 /* if the large client headers are enabled then
594 we need to compact r->header_in hunk */ 596 we need to compact r->header_in hunk */
595 597
596 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx); 598 cscf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx);
597 599
598 if (cmcf->large_client_header) { 600 if (cscf->large_client_header) {
599 offset = r->header_name_start - r->header_in->start; 601 offset = r->header_name_start - r->header_in->start;
600 602
601 if (offset == 0) { 603 if (offset == 0) {
602 ngx_http_header_parse_error(r, 604 ngx_http_header_parse_error(r,
603 NGX_HTTP_PARSE_TOO_LONG_HEADER); 605 NGX_HTTP_PARSE_TOO_LONG_HEADER);
625 } 627 }
626 628
627 629
628 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r) 630 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
629 { 631 {
630 int event; 632 int event;
631 ssize_t n; 633 ssize_t n;
632 ngx_event_t *rev; 634 ngx_event_t *rev;
633 ngx_http_core_main_conf_t *cmcf; 635 ngx_http_core_srv_conf_t *cscf;
634 636
635 n = r->header_in->last - r->header_in->pos; 637 n = r->header_in->last - r->header_in->pos;
636 638
637 if (n > 0) { 639 if (n > 0) {
638 return n; 640 return n;
649 ngx_del_timer(rev); 651 ngx_del_timer(rev);
650 } else { 652 } else {
651 rev->timer_set = 1; 653 rev->timer_set = 1;
652 } 654 }
653 655
654 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx); 656 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
655 657
656 ngx_add_timer(rev, cmcf->client_header_timeout); 658 ngx_add_timer(rev, cscf->client_header_timeout);
657 r->header_timeout_set = 1; 659 r->header_timeout_set = 1;
658 } 660 }
659 661
660 if (!rev->active) { 662 if (!rev->active) {
661 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { 663 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) {
911 r->header_in->pos += r->headers_in.content_length_n; 913 r->header_in->pos += r->headers_in.content_length_n;
912 r->headers_in.content_length_n = 0; 914 r->headers_in.content_length_n = 0;
913 return NGX_OK; 915 return NGX_OK;
914 } 916 }
915 } 917 }
916 918
917 rev->event_handler = ngx_http_read_discarded_body_event; 919 rev->event_handler = ngx_http_read_discarded_body_event;
918 920
919 if (rev->blocked) { 921 if (rev->blocked) {
920 if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { 922 if (ngx_event_flags & NGX_USE_LEVEL_EVENT) {
921 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT) 923 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT)
989 } 991 }
990 992
991 993
992 static void ngx_http_set_keepalive(ngx_http_request_t *r) 994 static void ngx_http_set_keepalive(ngx_http_request_t *r)
993 { 995 {
994 int len, blocked; 996 int len, blocked;
995 ngx_hunk_t *h; 997 ngx_hunk_t *h;
996 ngx_event_t *rev, *wev; 998 ngx_event_t *rev, *wev;
997 ngx_connection_t *c; 999 ngx_connection_t *c;
998 ngx_http_log_ctx_t *ctx; 1000 ngx_http_log_ctx_t *ctx;
999 ngx_http_core_main_conf_t *cmcf; 1001 ngx_http_core_srv_conf_t *cscf;
1000 ngx_http_core_loc_conf_t *clcf; 1002 ngx_http_core_loc_conf_t *clcf;
1001 1003
1002 c = (ngx_connection_t *) r->connection; 1004 c = (ngx_connection_t *) r->connection;
1003 rev = c->read; 1005 rev = c->read;
1004 1006
1005 ngx_log_debug(c->log, "set http keepalive handler"); 1007 ngx_log_debug(c->log, "set http keepalive handler");
1041 so if the large client headers are not enabled 1043 so if the large client headers are not enabled
1042 we need to copy the data to the start of c->buffer. 1044 we need to copy the data to the start of c->buffer.
1043 This copy should be rare because clients that support 1045 This copy should be rare because clients that support
1044 pipelined requests (Mozilla 1.x, Opera 6.x) are still rare */ 1046 pipelined requests (Mozilla 1.x, Opera 6.x) are still rare */
1045 1047
1046 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module_ctx); 1048 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
1047 1049
1048 if (!cmcf->large_client_header) { 1050 if (!cscf->large_client_header) {
1049 len = h->last - h->pos; 1051 len = h->last - h->pos;
1050 ngx_memcpy(h->start, h->pos, len); 1052 ngx_memcpy(h->start, h->pos, len);
1051 h->pos = h->start; 1053 h->pos = h->start;
1052 h->last = h->start + len; 1054 h->last = h->start + len;
1053 } 1055 }
1054 1056