Mercurial > hg > nginx-quic
comparison src/http/ngx_http_request.c @ 210:00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 14 Dec 2003 20:10:27 +0000 |
parents | e1c815be05ae |
children | 679f60139863 |
comparison
equal
deleted
inserted
replaced
209:e1c815be05ae | 210:00cafae0bdf1 |
---|---|
40 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", | 40 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", |
41 "client %s sent invalid \"Content-Length\" header, URL: %s" | 41 "client %s sent invalid \"Content-Length\" header, URL: %s" |
42 }; | 42 }; |
43 | 43 |
44 | 44 |
45 #if 0 | |
45 static void ngx_http_dummy(ngx_event_t *wev) | 46 static void ngx_http_dummy(ngx_event_t *wev) |
46 { | 47 { |
47 return; | 48 return; |
48 } | 49 } |
50 #endif | |
49 | 51 |
50 | 52 |
51 void ngx_http_init_connection(ngx_connection_t *c) | 53 void ngx_http_init_connection(ngx_connection_t *c) |
52 { | 54 { |
53 ngx_event_t *rev; | 55 ngx_event_t *rev; |
108 } | 110 } |
109 | 111 |
110 | 112 |
111 static void ngx_http_init_request(ngx_event_t *rev) | 113 static void ngx_http_init_request(ngx_event_t *rev) |
112 { | 114 { |
113 int i; | 115 ngx_int_t i; |
114 socklen_t len; | 116 socklen_t len; |
115 struct sockaddr_in addr_in; | 117 struct sockaddr_in addr_in; |
116 ngx_connection_t *c; | 118 ngx_connection_t *c; |
117 ngx_http_request_t *r; | 119 ngx_http_request_t *r; |
118 ngx_http_in_port_t *in_port; | 120 ngx_http_in_port_t *in_port; |
145 /* AF_INET only */ | 147 /* AF_INET only */ |
146 | 148 |
147 in_port = c->servers; | 149 in_port = c->servers; |
148 in_addr = in_port->addrs.elts; | 150 in_addr = in_port->addrs.elts; |
149 | 151 |
150 ngx_log_debug(rev->log, "IN: %08x" _ in_port); | |
151 | |
152 r->port = in_port->port; | 152 r->port = in_port->port; |
153 r->port_name = &in_port->port_name; | 153 r->port_name = &in_port->port_name; |
154 | 154 |
155 i = 0; | 155 i = 0; |
156 | 156 |
272 } | 272 } |
273 | 273 |
274 | 274 |
275 static void ngx_http_process_request_line(ngx_event_t *rev) | 275 static void ngx_http_process_request_line(ngx_event_t *rev) |
276 { | 276 { |
277 int rc, offset; | |
278 ssize_t n; | 277 ssize_t n; |
278 ngx_int_t rc, offset; | |
279 ngx_connection_t *c; | 279 ngx_connection_t *c; |
280 ngx_http_request_t *r; | 280 ngx_http_request_t *r; |
281 ngx_http_log_ctx_t *ctx; | 281 ngx_http_log_ctx_t *ctx; |
282 ngx_http_core_srv_conf_t *cscf; | 282 ngx_http_core_srv_conf_t *cscf; |
283 | 283 |
437 } | 437 } |
438 | 438 |
439 ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1); | 439 ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1); |
440 } | 440 } |
441 | 441 |
442 #if 1 /* DEBUG */ | 442 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
443 if (r->exten.data == NULL) { r->exten.data = ""; } | 443 "http request line: \"%s\"", r->request_line.data); |
444 if (r->args.data == NULL) { r->args.data = ""; } | 444 |
445 ngx_log_debug(c->log, "HTTP: %d, %d, '%s', '%s', '%s'" _ | 445 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
446 r->method _ r->http_version _ | 446 "http uri: \"%s\"", r->uri.data); |
447 r->uri.data _ r->exten.data _ r->args.data); | 447 |
448 if (r->exten.data[0] == '\0') { r->exten.data = NULL; } | 448 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
449 if (r->args.data[0] == '\0') { r->args.data = NULL; } | 449 "http args: \"%s\"", r->args.data ? r->args.data : ""); |
450 #endif | 450 |
451 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
452 "http exten: \"%s\"", | |
453 r->exten.data ? r->exten.data : ""); | |
451 | 454 |
452 if (r->http_version < NGX_HTTP_VERSION_10) { | 455 if (r->http_version < NGX_HTTP_VERSION_10) { |
453 rev->event_handler = ngx_http_block_read; | 456 rev->event_handler = ngx_http_block_read; |
454 ngx_http_handler(r); | 457 ngx_http_handler(r); |
455 return; | 458 return; |
530 } | 533 } |
531 | 534 |
532 | 535 |
533 static void ngx_http_process_request_headers(ngx_event_t *rev) | 536 static void ngx_http_process_request_headers(ngx_event_t *rev) |
534 { | 537 { |
535 int rc, i, offset; | |
536 ssize_t n; | 538 ssize_t n; |
539 ngx_int_t rc, i, offset; | |
537 ngx_table_elt_t *h; | 540 ngx_table_elt_t *h; |
538 ngx_connection_t *c; | 541 ngx_connection_t *c; |
539 ngx_http_request_t *r; | 542 ngx_http_request_t *r; |
540 ngx_http_core_srv_conf_t *cscf; | 543 ngx_http_core_srv_conf_t *cscf; |
541 | 544 |
614 + ngx_http_headers_in[i].offset)) = h; | 617 + ngx_http_headers_in[i].offset)) = h; |
615 break; | 618 break; |
616 } | 619 } |
617 } | 620 } |
618 | 621 |
619 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ | 622 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
620 h->key.data _ h->value.data); | 623 "http header: \"%s: %s\"'", |
624 h->key.data, h->value.data); | |
621 | 625 |
622 if (cscf->large_client_header | 626 if (cscf->large_client_header |
623 && r->header_in->pos == r->header_in->last) | 627 && r->header_in->pos == r->header_in->last) |
624 { | 628 { |
625 r->header_in->pos = r->header_in->last = r->header_in->start; | 629 r->header_in->pos = r->header_in->last = r->header_in->start; |
629 | 633 |
630 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { | 634 } else if (rc == NGX_HTTP_PARSE_HEADER_DONE) { |
631 | 635 |
632 /* a whole header has been parsed successfully */ | 636 /* a whole header has been parsed successfully */ |
633 | 637 |
634 ngx_log_debug(r->connection->log, "HTTP header done"); | 638 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
639 "http header done"); | |
635 | 640 |
636 rc = ngx_http_process_request_header(r); | 641 rc = ngx_http_process_request_header(r); |
637 | 642 |
638 if (rc != NGX_OK) { | 643 if (rc != NGX_OK) { |
639 ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); | 644 ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); |
744 | 749 |
745 return n; | 750 return n; |
746 } | 751 } |
747 | 752 |
748 | 753 |
749 static int ngx_http_process_request_header(ngx_http_request_t *r) | 754 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r) |
750 { | 755 { |
751 int i; | |
752 size_t len; | 756 size_t len; |
757 ngx_int_t i; | |
753 ngx_http_server_name_t *name; | 758 ngx_http_server_name_t *name; |
754 ngx_http_core_loc_conf_t *clcf; | 759 ngx_http_core_loc_conf_t *clcf; |
755 | 760 |
756 if (r->headers_in.host) { | 761 if (r->headers_in.host) { |
757 for (len = 0; len < r->headers_in.host->value.len; len++) { | 762 for (len = 0; len < r->headers_in.host->value.len; len++) { |
826 } | 831 } |
827 | 832 |
828 | 833 |
829 void ngx_http_finalize_request(ngx_http_request_t *r, int rc) | 834 void ngx_http_finalize_request(ngx_http_request_t *r, int rc) |
830 { | 835 { |
836 ngx_http_core_loc_conf_t *clcf; | |
837 | |
831 /* r can be already destroyed when rc == NGX_DONE */ | 838 /* r can be already destroyed when rc == NGX_DONE */ |
832 | 839 |
833 if (rc == NGX_DONE || r->main) { | 840 if (rc == NGX_DONE || r->main) { |
834 return; | 841 return; |
835 } | 842 } |
836 | 843 |
837 ngx_log_debug(r->connection->log, "finalize http request"); | 844 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
845 "http finalize request"); | |
838 | 846 |
839 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | 847 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
840 | 848 |
841 if (r->connection->read->timer_set) { | 849 if (r->connection->read->timer_set) { |
842 ngx_del_timer(r->connection->read); | 850 ngx_del_timer(r->connection->read); |
866 | 874 |
867 if (r->connection->write->timer_set) { | 875 if (r->connection->write->timer_set) { |
868 ngx_del_timer(r->connection->write); | 876 ngx_del_timer(r->connection->write); |
869 } | 877 } |
870 | 878 |
871 if (r->keepalive != 0) { | 879 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
880 | |
881 if (r->keepalive != 0 && clcf->keepalive_timeout > 0) { | |
872 ngx_http_set_keepalive(r); | 882 ngx_http_set_keepalive(r); |
873 | 883 |
874 } else if (r->lingering_close) { | 884 } else if (r->lingering_close && clcf->lingering_timeout > 0) { |
875 ngx_http_set_lingering_close(r); | 885 ngx_http_set_lingering_close(r); |
876 | 886 |
877 } else { | 887 } else { |
878 ngx_http_close_request(r, 0); | 888 ngx_http_close_request(r, 0); |
879 ngx_http_close_connection(r->connection); | 889 ngx_http_close_connection(r->connection); |
914 int rc; | 924 int rc; |
915 ngx_connection_t *c; | 925 ngx_connection_t *c; |
916 ngx_http_request_t *r; | 926 ngx_http_request_t *r; |
917 ngx_http_core_loc_conf_t *clcf; | 927 ngx_http_core_loc_conf_t *clcf; |
918 | 928 |
919 ngx_log_debug(wev->log, "http writer handler"); | 929 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http writer handler"); |
920 | 930 |
921 c = wev->data; | 931 c = wev->data; |
922 r = c->data; | 932 r = c->data; |
923 | 933 |
924 #if 0 /* TODO: THINK */ | 934 #if 0 /* TODO: THINK */ |
932 return; | 942 return; |
933 } | 943 } |
934 | 944 |
935 rc = ngx_http_output_filter(r, NULL); | 945 rc = ngx_http_output_filter(r, NULL); |
936 | 946 |
937 ngx_log_debug(c->log, "writer output filter: %d" _ rc); | 947 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
948 "http writer output filter: %d", rc); | |
938 | 949 |
939 if (rc == NGX_AGAIN) { | 950 if (rc == NGX_AGAIN) { |
940 if (!wev->ready) { | 951 if (!wev->ready) { |
941 clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, | 952 clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, |
942 ngx_http_core_module); | 953 ngx_http_core_module); |
949 } | 960 } |
950 | 961 |
951 return; | 962 return; |
952 } | 963 } |
953 | 964 |
954 ngx_log_debug(c->log, "http writer done"); | 965 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http writer done"); |
955 | 966 |
956 ngx_http_finalize_request(r, rc); | 967 ngx_http_finalize_request(r, rc); |
957 } | 968 } |
958 | 969 |
959 | 970 |
960 static void ngx_http_block_read(ngx_event_t *rev) | 971 static void ngx_http_block_read(ngx_event_t *rev) |
961 { | 972 { |
962 ngx_connection_t *c; | 973 ngx_connection_t *c; |
963 ngx_http_request_t *r; | 974 ngx_http_request_t *r; |
964 | 975 |
965 ngx_log_debug(rev->log, "http read blocked"); | 976 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http read blocked"); |
966 | 977 |
967 /* aio does not call this handler */ | 978 /* aio does not call this handler */ |
968 | 979 |
969 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) { | 980 if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) { |
970 if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { | 981 if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { |
984 ssize_t size; | 995 ssize_t size; |
985 ngx_event_t *rev; | 996 ngx_event_t *rev; |
986 | 997 |
987 rev = r->connection->read; | 998 rev = r->connection->read; |
988 | 999 |
989 ngx_log_debug(rev->log, "set discard body"); | 1000 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); |
990 | 1001 |
991 if (rev->timer_set) { | 1002 if (rev->timer_set) { |
992 ngx_del_timer(rev); | 1003 ngx_del_timer(rev); |
993 } | 1004 } |
994 | 1005 |