Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 153:c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 21 Oct 2003 16:49:56 +0000 |
parents | fb48bf4fea1c |
children | 46eb23d9471d |
comparison
equal
deleted
inserted
replaced
152:fb48bf4fea1c | 153:c71aeb75c071 |
---|---|
7 | 7 |
8 static void ngx_http_init_request(ngx_event_t *ev); | 8 static void ngx_http_init_request(ngx_event_t *ev); |
9 static void ngx_http_process_request_line(ngx_event_t *rev); | 9 static void ngx_http_process_request_line(ngx_event_t *rev); |
10 static void ngx_http_process_request_headers(ngx_event_t *rev); | 10 static void ngx_http_process_request_headers(ngx_event_t *rev); |
11 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); | 11 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); |
12 static int ngx_http_process_request_header(ngx_http_request_t *r); | |
12 | 13 |
13 static void ngx_http_set_write_handler(ngx_http_request_t *r); | 14 static void ngx_http_set_write_handler(ngx_http_request_t *r); |
14 | 15 |
15 static void ngx_http_block_read(ngx_event_t *ev); | 16 static void ngx_http_block_read(ngx_event_t *ev); |
16 static void ngx_http_read_discarded_body_event(ngx_event_t *rev); | 17 static void ngx_http_read_discarded_body_event(ngx_event_t *rev); |
254 r->header_in = c->buffer; | 255 r->header_in = c->buffer; |
255 | 256 |
256 r->file.fd = NGX_INVALID_FILE; | 257 r->file.fd = NGX_INVALID_FILE; |
257 | 258 |
258 r->headers_in.content_length_n = -1; | 259 r->headers_in.content_length_n = -1; |
259 r->headers_out.content_length = -1; | 260 r->headers_in.keep_alive_n = -1; |
261 r->headers_out.content_length_n = -1; | |
260 r->headers_out.last_modified_time = -1; | 262 r->headers_out.last_modified_time = -1; |
261 | 263 |
262 rev->event_handler = ngx_http_process_request_line; | 264 rev->event_handler = ngx_http_process_request_line; |
263 ngx_http_process_request_line(rev); | 265 ngx_http_process_request_line(rev); |
264 } | 266 } |
501 | 503 |
502 | 504 |
503 static void ngx_http_process_request_headers(ngx_event_t *rev) | 505 static void ngx_http_process_request_headers(ngx_event_t *rev) |
504 { | 506 { |
505 int rc, i, offset; | 507 int rc, i, offset; |
506 size_t len; | |
507 ssize_t n; | 508 ssize_t n; |
508 ngx_table_elt_t *h; | 509 ngx_table_elt_t *h; |
509 ngx_connection_t *c; | 510 ngx_connection_t *c; |
510 ngx_http_request_t *r; | 511 ngx_http_request_t *r; |
511 ngx_http_server_name_t *name; | |
512 ngx_http_core_srv_conf_t *cscf; | 512 ngx_http_core_srv_conf_t *cscf; |
513 ngx_http_core_loc_conf_t *clcf; | |
514 | 513 |
515 c = rev->data; | 514 c = rev->data; |
516 r = c->data; | 515 r = c->data; |
517 | 516 |
518 ngx_log_debug(rev->log, "http process request header line"); | 517 ngx_log_debug(rev->log, "http process request header line"); |
602 | 601 |
603 /* a whole header has been parsed successfully */ | 602 /* a whole header has been parsed successfully */ |
604 | 603 |
605 ngx_log_debug(r->connection->log, "HTTP header done"); | 604 ngx_log_debug(r->connection->log, "HTTP header done"); |
606 | 605 |
607 if (r->headers_in.host) { | 606 rc = ngx_http_process_request_header(r); |
608 for (len = 0; len < r->headers_in.host->value.len; len++) { | 607 |
609 if (r->headers_in.host->value.data[len] == ':') { | 608 if (rc != NGX_OK) { |
610 break; | 609 ngx_http_header_parse_error(r, rc, NGX_HTTP_BAD_REQUEST); |
611 } | 610 return; |
612 } | |
613 r->headers_in.host_name_len = len; | |
614 | |
615 /* find the name based server configuration */ | |
616 | |
617 name = r->virtual_names->elts; | |
618 for (i = 0; i < r->virtual_names->nelts; i++) { | |
619 if (r->headers_in.host_name_len != name[i].name.len) { | |
620 continue; | |
621 } | |
622 | |
623 if (ngx_strncasecmp(r->headers_in.host->value.data, | |
624 name[i].name.data, | |
625 r->headers_in.host_name_len) == 0) | |
626 { | |
627 r->srv_conf = name[i].core_srv_conf->ctx->srv_conf; | |
628 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; | |
629 | |
630 clcf = ngx_http_get_module_loc_conf(r, | |
631 ngx_http_core_module); | |
632 c->log->file = clcf->err_log->file; | |
633 c->log->log_level = clcf->err_log->log_level; | |
634 | |
635 break; | |
636 } | |
637 } | |
638 | |
639 } else { | |
640 if (r->http_version > NGX_HTTP_VERSION_10) { | |
641 ngx_http_header_parse_error(r, | |
642 NGX_HTTP_PARSE_NO_HOST_HEADER, | |
643 NGX_HTTP_BAD_REQUEST); | |
644 return; | |
645 } | |
646 r->headers_in.host_name_len = 0; | |
647 } | |
648 | |
649 if (r->headers_in.content_length) { | |
650 r->headers_in.content_length_n = | |
651 ngx_atoi(r->headers_in.content_length->value.data, | |
652 r->headers_in.content_length->value.len); | |
653 | |
654 if (r->headers_in.content_length_n == NGX_ERROR) { | |
655 ngx_http_header_parse_error(r, | |
656 NGX_HTTP_PARSE_INVALID_CL_HEADER, | |
657 NGX_HTTP_BAD_REQUEST); | |
658 return; | |
659 } | |
660 } | 611 } |
661 | 612 |
662 if (r->header_timeout_set) { | 613 if (r->header_timeout_set) { |
663 ngx_del_timer(rev); | 614 ngx_del_timer(rev); |
664 } | 615 } |
761 } | 712 } |
762 | 713 |
763 r->header_in->last += n; | 714 r->header_in->last += n; |
764 | 715 |
765 return n; | 716 return n; |
717 } | |
718 | |
719 | |
720 static int ngx_http_process_request_header(ngx_http_request_t *r) | |
721 { | |
722 int i; | |
723 size_t len; | |
724 ngx_http_server_name_t *name; | |
725 ngx_http_core_loc_conf_t *clcf; | |
726 | |
727 if (r->headers_in.host) { | |
728 for (len = 0; len < r->headers_in.host->value.len; len++) { | |
729 if (r->headers_in.host->value.data[len] == ':') { | |
730 break; | |
731 } | |
732 } | |
733 r->headers_in.host_name_len = len; | |
734 | |
735 /* find the name based server configuration */ | |
736 | |
737 name = r->virtual_names->elts; | |
738 for (i = 0; i < r->virtual_names->nelts; i++) { | |
739 if (r->headers_in.host_name_len != name[i].name.len) { | |
740 continue; | |
741 } | |
742 | |
743 if (ngx_strncasecmp(r->headers_in.host->value.data, | |
744 name[i].name.data, | |
745 r->headers_in.host_name_len) == 0) | |
746 { | |
747 r->srv_conf = name[i].core_srv_conf->ctx->srv_conf; | |
748 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; | |
749 | |
750 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
751 r->connection->log->file = clcf->err_log->file; | |
752 r->connection->log->log_level = clcf->err_log->log_level; | |
753 | |
754 break; | |
755 } | |
756 } | |
757 | |
758 } else { | |
759 if (r->http_version > NGX_HTTP_VERSION_10) { | |
760 return NGX_HTTP_PARSE_NO_HOST_HEADER; | |
761 } | |
762 r->headers_in.host_name_len = 0; | |
763 } | |
764 | |
765 if (r->headers_in.content_length) { | |
766 r->headers_in.content_length_n = | |
767 ngx_atoi(r->headers_in.content_length->value.data, | |
768 r->headers_in.content_length->value.len); | |
769 | |
770 if (r->headers_in.content_length_n == NGX_ERROR) { | |
771 return NGX_HTTP_PARSE_INVALID_CL_HEADER; | |
772 } | |
773 } | |
774 | |
775 if (r->headers_in.connection) { | |
776 if (r->headers_in.connection->value.len == 5 | |
777 && ngx_strcasecmp(r->headers_in.connection->value.data, "close") | |
778 == 0) | |
779 { | |
780 r->headers_in.connection_type = NGX_HTTP_CONNECTION_CLOSE; | |
781 | |
782 } else if (r->headers_in.connection->value.len == 10 | |
783 && ngx_strcasecmp(r->headers_in.connection->value.data, | |
784 "keep-alive") == 0) | |
785 { | |
786 r->headers_in.connection_type = NGX_HTTP_CONNECTION_KEEP_ALIVE; | |
787 | |
788 if (r->headers_in.keep_alive) { | |
789 r->headers_in.keep_alive_n = | |
790 ngx_atoi(r->headers_in.keep_alive->value.data, | |
791 r->headers_in.keep_alive->value.len); | |
792 } | |
793 } | |
794 } | |
795 | |
796 return NGX_OK; | |
766 } | 797 } |
767 | 798 |
768 | 799 |
769 void ngx_http_finalize_request(ngx_http_request_t *r, int rc) | 800 void ngx_http_finalize_request(ngx_http_request_t *r, int rc) |
770 { | 801 { |
1281 } | 1312 } |
1282 | 1313 |
1283 | 1314 |
1284 int ngx_http_send_last(ngx_http_request_t *r) | 1315 int ngx_http_send_last(ngx_http_request_t *r) |
1285 { | 1316 { |
1286 ngx_hunk_t *h; | 1317 ngx_hunk_t *h; |
1318 ngx_chain_t out; | |
1287 | 1319 |
1288 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); | 1320 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); |
1289 h->type = NGX_HUNK_LAST; | 1321 h->type = NGX_HUNK_LAST; |
1290 | 1322 out.hunk = h; |
1291 return ngx_http_output_filter(r, h); | 1323 out.next = NULL; |
1324 | |
1325 return ngx_http_output_filter(r, &out); | |
1292 } | 1326 } |
1293 | 1327 |
1294 | 1328 |
1295 void ngx_http_close_request(ngx_http_request_t *r, int error) | 1329 void ngx_http_close_request(ngx_http_request_t *r, int error) |
1296 { | 1330 { |