Mercurial > hg > nginx-quic
comparison src/http/ngx_http_event.c @ 19:d7908993fdeb
nginx-0.0.1-2002-12-02-19:09:40 import; resume after 2 months stall
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 02 Dec 2002 16:09:40 +0000 |
parents | 72ad26c77d2d |
children | a649c0a0adb3 |
comparison
equal
deleted
inserted
replaced
18:72ad26c77d2d | 19:d7908993fdeb |
---|---|
7 #include <ngx_core.h> | 7 #include <ngx_core.h> |
8 #include <ngx_string.h> | 8 #include <ngx_string.h> |
9 #include <ngx_files.h> | 9 #include <ngx_files.h> |
10 #include <ngx_log.h> | 10 #include <ngx_log.h> |
11 #include <ngx_alloc.h> | 11 #include <ngx_alloc.h> |
12 #include <ngx_array.h> | |
13 #include <ngx_table.h> | |
12 #include <ngx_hunk.h> | 14 #include <ngx_hunk.h> |
13 #include <ngx_connection.h> | 15 #include <ngx_connection.h> |
14 #include <ngx_http.h> | 16 #include <ngx_http.h> |
15 #include <ngx_http_config.h> | 17 #include <ngx_http_config.h> |
16 #include <ngx_http_core.h> | 18 #include <ngx_http_core.h> |
17 | 19 |
18 /* STUB */ | 20 /* STUB */ |
19 #include <ngx_http_output_filter.h> | 21 #include <ngx_http_output_filter.h> |
20 int ngx_http_static_handler(ngx_http_request_t *r); | 22 int ngx_http_static_handler(ngx_http_request_t *r); |
21 int ngx_http_index_handler(ngx_http_request_t *r); | 23 int ngx_http_index_handler(ngx_http_request_t *r); |
24 int ngx_http_proxy_handler(ngx_http_request_t *r); | |
22 /* */ | 25 /* */ |
23 | 26 |
24 int ngx_http_init_connection(ngx_connection_t *c); | 27 int ngx_http_init_connection(ngx_connection_t *c); |
25 | 28 |
26 static int ngx_http_init_request(ngx_event_t *ev); | 29 static int ngx_http_init_request(ngx_event_t *ev); |
57 "client %s sent invalid request", | 60 "client %s sent invalid request", |
58 "client %s sent too long URI", | 61 "client %s sent too long URI", |
59 "client %s sent HEAD method in HTTP/0.9 request" | 62 "client %s sent HEAD method in HTTP/0.9 request" |
60 }; | 63 }; |
61 | 64 |
65 | |
66 static ngx_http_header_t headers_in[] = { | |
67 { 4, "Host", offsetof(ngx_http_headers_in_t, host) }, | |
68 { 10, "Connection", offsetof(ngx_http_headers_in_t, connection) }, | |
69 | |
70 { 10, "User-Agent", offsetof(ngx_http_headers_in_t, user_agent) }, | |
71 | |
72 { 0, NULL, 0 } | |
73 }; | |
62 | 74 |
63 | 75 |
64 int ngx_http_init_connection(ngx_connection_t *c) | 76 int ngx_http_init_connection(ngx_connection_t *c) |
65 { | 77 { |
66 ngx_event_t *ev; | 78 ngx_event_t *ev; |
290 if (r->http_version == 9) | 302 if (r->http_version == 9) |
291 return ngx_http_event_handler(r); | 303 return ngx_http_event_handler(r); |
292 | 304 |
293 /* TODO: check too long URI - no space for header, compact buffer */ | 305 /* TODO: check too long URI - no space for header, compact buffer */ |
294 | 306 |
307 r->headers_in.headers = ngx_create_table(r->pool, 10); | |
308 | |
295 r->state_handler = ngx_http_process_request_header; | 309 r->state_handler = ngx_http_process_request_header; |
296 ctx = r->connection->log->data; | 310 ctx = r->connection->log->data; |
297 ctx->action = "reading client request headers"; | 311 ctx->action = "reading client request headers"; |
298 | 312 |
299 return NGX_OK; | 313 return NGX_OK; |
353 } | 367 } |
354 | 368 |
355 | 369 |
356 static int ngx_http_process_request_header_line(ngx_http_request_t *r) | 370 static int ngx_http_process_request_header_line(ngx_http_request_t *r) |
357 { | 371 { |
358 /* STUB */ | 372 int i; |
359 *r->header_name_end = '\0'; | 373 ngx_table_elt_t *h; |
360 *r->header_end = '\0'; | 374 |
375 ngx_test_null(h, ngx_push_array(r->headers_in.headers), NGX_ERROR); | |
376 | |
377 h->key.len = r->header_name_end - r->header_name_start; | |
378 ngx_test_null(h->key.data, ngx_palloc(r->pool, h->key.len + 1), NGX_ERROR); | |
379 ngx_cpystrn(h->key.data, r->header_name_start, h->key.len + 1); | |
380 | |
381 h->value.len = r->header_end - r->header_start; | |
382 ngx_test_null(h->value.data, ngx_palloc(r->pool, h->value.len + 1), | |
383 NGX_ERROR); | |
384 ngx_cpystrn(h->value.data, r->header_start, h->value.len + 1); | |
385 | |
386 for (i = 0; headers_in[i].len != 0; i++) { | |
387 if (headers_in[i].len == h->key.len) { | |
388 if (strcasecmp(headers_in[i].data, h->key.data) == 0) { | |
389 *((ngx_table_elt_t **) | |
390 ((char *) &r->headers_in + headers_in[i].offset)) = h; | |
391 } | |
392 } | |
393 } | |
394 | |
361 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ | 395 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ |
362 r->header_name_start _ r->header_start); | 396 h->key.data _ h->value.data); |
363 | 397 |
364 return NGX_OK; | 398 return NGX_OK; |
365 } | 399 } |
366 | 400 |
367 | 401 |
443 | 477 |
444 static int ngx_http_event_handler(ngx_http_request_t *r) | 478 static int ngx_http_event_handler(ngx_http_request_t *r) |
445 { | 479 { |
446 int rc; | 480 int rc; |
447 ngx_msec_t timeout; | 481 ngx_msec_t timeout; |
482 | |
483 ngx_log_debug(r->connection->log, "UA: '%s: %s'" _ | |
484 r->headers_in.user_agent->key.data _ | |
485 r->headers_in.user_agent->value.data); | |
448 | 486 |
449 rc = ngx_http_handler(r); | 487 rc = ngx_http_handler(r); |
450 | 488 |
451 /* transfer not completed */ | 489 /* transfer not completed */ |
452 if (rc == NGX_AGAIN) { | 490 if (rc == NGX_AGAIN) { |
543 static int ngx_http_set_default_handler(ngx_http_request_t *r) | 581 static int ngx_http_set_default_handler(ngx_http_request_t *r) |
544 { | 582 { |
545 int err, rc; | 583 int err, rc; |
546 char *name, *loc, *file; | 584 char *name, *loc, *file; |
547 | 585 |
586 #if 0 | |
587 /* STUB */ | |
588 r->handler = ngx_http_proxy_handler; | |
589 return NGX_OK; | |
590 #endif | |
591 | |
592 /* NO NEEDED | |
548 ngx_test_null(r->headers_out, | 593 ngx_test_null(r->headers_out, |
549 ngx_pcalloc(r->pool, sizeof(ngx_http_headers_out_t)), | 594 ngx_pcalloc(r->pool, sizeof(ngx_http_headers_out_t)), |
550 NGX_HTTP_INTERNAL_SERVER_ERROR); | 595 NGX_HTTP_INTERNAL_SERVER_ERROR); |
596 */ | |
551 | 597 |
552 if (*(r->uri_end - 1) == '/') { | 598 if (*(r->uri_end - 1) == '/') { |
553 r->handler = ngx_http_index_handler; | 599 r->handler = ngx_http_index_handler; |
554 return NGX_OK; | 600 return NGX_OK; |
555 } | 601 } |
581 | 627 |
582 if (ngx_is_dir(r->fileinfo)) { | 628 if (ngx_is_dir(r->fileinfo)) { |
583 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->filename); | 629 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->filename); |
584 *file++ = '/'; | 630 *file++ = '/'; |
585 *file = '\0'; | 631 *file = '\0'; |
586 r->headers_out->location = r->location; | 632 r->headers_out.location = r->location; |
587 return NGX_HTTP_MOVED_PERMANENTLY; | 633 return NGX_HTTP_MOVED_PERMANENTLY; |
588 } | 634 } |
589 | 635 |
590 r->handler = ngx_http_static_handler; | 636 r->handler = ngx_http_static_handler; |
591 | 637 |
603 | 649 |
604 | 650 |
605 static int ngx_http_writer(ngx_event_t *ev) | 651 static int ngx_http_writer(ngx_event_t *ev) |
606 { | 652 { |
607 int rc; | 653 int rc; |
608 ngx_msec_t timeout; | 654 ngx_msec_t timeout; |
609 ngx_connection_t *c; | 655 ngx_connection_t *c; |
610 ngx_http_request_t *r; | 656 ngx_http_request_t *r; |
611 ngx_http_core_conf_t *conf; | 657 ngx_http_core_loc_conf_t *conf; |
612 | 658 |
613 c = (ngx_connection_t *) ev->data; | 659 c = (ngx_connection_t *) ev->data; |
614 r = (ngx_http_request_t *) c->data; | 660 r = (ngx_http_request_t *) c->data; |
615 | 661 |
616 c->sent = 0; | 662 c->sent = 0; |
620 ngx_log_debug(ev->log, "output filter in writer: %d" _ rc); | 666 ngx_log_debug(ev->log, "output filter in writer: %d" _ rc); |
621 | 667 |
622 if (rc == NGX_AGAIN) { | 668 if (rc == NGX_AGAIN) { |
623 | 669 |
624 if (c->sent > 0) { | 670 if (c->sent > 0) { |
625 conf = (ngx_http_core_conf_t *) | 671 conf = (ngx_http_core_loc_conf_t *) |
626 ngx_get_module_loc_conf(r->main ? r->main : r, | 672 ngx_get_module_loc_conf(r->main ? r->main : r, |
627 ngx_http_core_module); | 673 ngx_http_core_module); |
628 | 674 |
629 timeout = (ngx_msec_t) (c->sent * conf->send_timeout); | 675 timeout = (ngx_msec_t) (c->sent * conf->send_timeout); |
630 | 676 |