Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 415:3c56e834be46
nginx-0.0.10-2004-09-05-23:54:02 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 05 Sep 2004 19:54:02 +0000 |
parents | d6e2b445c1b8 |
children | b9bd635011de |
comparison
equal
deleted
inserted
replaced
414:388a842cbbe1 | 415:3c56e834be46 |
---|---|
38 "client %s sent too long URI", | 38 "client %s sent too long URI", |
39 "client %s sent invalid method in HTTP/0.9 request", | 39 "client %s sent invalid method in HTTP/0.9 request", |
40 | 40 |
41 "client %s sent invalid header, URL: %s", | 41 "client %s sent invalid header, URL: %s", |
42 "client %s sent too long header line, URL: %s", | 42 "client %s sent too long header line, URL: %s", |
43 "client %s sent too many headers, URL: %s", | |
43 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", | 44 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", |
44 "client %s sent invalid \"Content-Length\" header, URL: %s", | 45 "client %s sent invalid \"Content-Length\" header, URL: %s", |
45 "client %s sent POST method without \"Content-Length\" header, URL: %s", | 46 "client %s sent POST method without \"Content-Length\" header, URL: %s", |
46 "client %s sent plain HTTP request to HTTPS port, URL: %s", | 47 "client %s sent plain HTTP request to HTTPS port, URL: %s", |
47 "client %s sent invalid \"Host\" header \"%s\", URL: %s" | 48 "client %s sent invalid \"Host\" header \"%s\", URL: %s" |
307 r->cleanup.nalloc = 5; | 308 r->cleanup.nalloc = 5; |
308 r->cleanup.size = sizeof(ngx_http_cleanup_t); | 309 r->cleanup.size = sizeof(ngx_http_cleanup_t); |
309 r->cleanup.pool = r->pool; | 310 r->cleanup.pool = r->pool; |
310 | 311 |
311 | 312 |
313 if (ngx_init_list(&r->headers_out.headers, r->pool, 2, | |
314 sizeof(ngx_table_elt_t)) == NGX_ERROR) | |
315 { | |
316 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
317 ngx_http_close_connection(c); | |
318 return; | |
319 } | |
320 | |
321 | |
322 #if 0 | |
312 /* init the r->headers_out.headers table */ | 323 /* init the r->headers_out.headers table */ |
313 | 324 |
314 r->headers_out.headers.elts = ngx_pcalloc(r->pool, | 325 r->headers_out.headers.elts = ngx_pcalloc(r->pool, |
315 20 * sizeof(ngx_table_elt_t)); | 326 20 * sizeof(ngx_table_elt_t)); |
316 if (r->headers_out.headers.elts == NULL) { | 327 if (r->headers_out.headers.elts == NULL) { |
320 } | 331 } |
321 /* r->headers_out.headers.nelts = 0; */ | 332 /* r->headers_out.headers.nelts = 0; */ |
322 r->headers_out.headers.nalloc = 20; | 333 r->headers_out.headers.nalloc = 20; |
323 r->headers_out.headers.size = sizeof(ngx_table_elt_t); | 334 r->headers_out.headers.size = sizeof(ngx_table_elt_t); |
324 r->headers_out.headers.pool = r->pool; | 335 r->headers_out.headers.pool = r->pool; |
336 #endif | |
325 | 337 |
326 | 338 |
327 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); | 339 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); |
328 if (r->ctx == NULL) { | 340 if (r->ctx == NULL) { |
329 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 341 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
605 ngx_http_handler(r); | 617 ngx_http_handler(r); |
606 return; | 618 return; |
607 } | 619 } |
608 | 620 |
609 | 621 |
610 /* init the r->headers_in.headers table */ | 622 if (ngx_init_list(&r->headers_in.headers, r->pool, 2, |
611 | 623 sizeof(ngx_table_elt_t)) == NGX_ERROR) |
612 r->headers_in.headers.elts = ngx_pcalloc(r->pool, | 624 { |
613 20 * sizeof(ngx_table_elt_t)); | |
614 if (r->headers_in.headers.elts == NULL) { | |
615 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 625 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
616 ngx_http_close_connection(c); | 626 ngx_http_close_connection(c); |
617 return; | 627 return; |
618 } | 628 } |
619 | 629 |
620 /* r->headers_in.headers.nelts = 0; */ | 630 |
621 r->headers_in.headers.size = sizeof(ngx_table_elt_t); | 631 if (ngx_init_array0(&r->headers_in.cookies, r->pool, 5, |
622 r->headers_in.headers.nalloc = 20; | 632 sizeof(ngx_table_elt_t *)) == NGX_ERROR) |
623 r->headers_in.headers.pool = r->pool; | 633 { |
624 | |
625 | |
626 /* init the r->headers_in.cookies array */ | |
627 | |
628 r->headers_in.cookies.elts = ngx_pcalloc(r->pool, | |
629 5 * sizeof(ngx_uint_t)); | |
630 if (r->headers_in.cookies.elts == NULL) { | |
631 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 634 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
632 ngx_http_close_connection(c); | 635 ngx_http_close_connection(c); |
633 return; | 636 return; |
634 } | 637 } |
635 | |
636 /* r->headers_in.cookies.nelts = 0; */ | |
637 r->headers_in.cookies.size = sizeof(ngx_uint_t); | |
638 r->headers_in.cookies.nalloc = 5; | |
639 r->headers_in.cookies.pool = r->pool; | |
640 | 638 |
641 | 639 |
642 ctx = c->log->data; | 640 ctx = c->log->data; |
643 ctx->action = "reading client request headers"; | 641 ctx->action = "reading client request headers"; |
644 ctx->url = r->unparsed_uri.data; | 642 ctx->url = r->unparsed_uri.data; |
729 | 727 |
730 static void ngx_http_process_request_headers(ngx_event_t *rev) | 728 static void ngx_http_process_request_headers(ngx_event_t *rev) |
731 { | 729 { |
732 ssize_t n; | 730 ssize_t n; |
733 ngx_int_t rc, i, offset; | 731 ngx_int_t rc, i, offset; |
734 ngx_uint_t *cookie; | 732 ngx_table_elt_t *h, **cookie; |
735 ngx_table_elt_t *h; | |
736 ngx_connection_t *c; | 733 ngx_connection_t *c; |
737 ngx_http_request_t *r; | 734 ngx_http_request_t *r; |
738 ngx_http_core_srv_conf_t *cscf; | 735 ngx_http_core_srv_conf_t *cscf; |
739 | 736 |
740 c = rev->data; | 737 c = rev->data; |
759 if (n == NGX_AGAIN || n == NGX_ERROR) { | 756 if (n == NGX_AGAIN || n == NGX_ERROR) { |
760 return; | 757 return; |
761 } | 758 } |
762 } | 759 } |
763 | 760 |
761 if (r->headers_n > 100) { | |
762 ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_MANY_HEADERS, | |
763 NGX_HTTP_BAD_REQUEST); | |
764 return; | |
765 } | |
766 | |
764 rc = ngx_http_parse_header_line(r, r->header_in); | 767 rc = ngx_http_parse_header_line(r, r->header_in); |
765 | 768 |
766 if (rc == NGX_OK) { | 769 if (rc == NGX_OK) { |
767 | 770 |
768 /* a header line has been parsed successfully */ | 771 /* a header line has been parsed successfully */ |
769 | 772 |
770 h = ngx_http_add_header(&r->headers_in, ngx_http_headers_in); | 773 r->headers_n++; |
771 if (h == NULL) { | 774 |
775 if (!(h = ngx_push_list(&r->headers_in.headers))) { | |
772 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 776 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
773 ngx_http_close_connection(c); | 777 ngx_http_close_connection(c); |
774 return; | 778 return; |
775 } | 779 } |
776 | 780 |
807 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 811 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
808 ngx_http_close_connection(c); | 812 ngx_http_close_connection(c); |
809 return; | 813 return; |
810 } | 814 } |
811 | 815 |
812 *cookie = r->headers_in.headers.nelts - 1; | 816 *cookie = h; |
813 | 817 |
814 } else { | 818 } else { |
815 | 819 |
816 for (i = 0; ngx_http_headers_in[i].name.len != 0; i++) { | 820 for (i = 0; ngx_http_headers_in[i].name.len != 0; i++) { |
817 if (ngx_http_headers_in[i].name.len != h->key.len) { | 821 if (ngx_http_headers_in[i].name.len != h->key.len) { |
1367 } | 1371 } |
1368 | 1372 |
1369 | 1373 |
1370 static void ngx_http_read_discarded_body_event(ngx_event_t *rev) | 1374 static void ngx_http_read_discarded_body_event(ngx_event_t *rev) |
1371 { | 1375 { |
1372 int rc; | 1376 ngx_int_t rc; |
1373 ngx_connection_t *c; | 1377 ngx_connection_t *c; |
1374 ngx_http_request_t *r; | 1378 ngx_http_request_t *r; |
1375 | 1379 |
1376 c = rev->data; | 1380 c = rev->data; |
1377 r = c->data; | 1381 r = c->data; |
1444 } | 1448 } |
1445 | 1449 |
1446 | 1450 |
1447 static void ngx_http_set_keepalive(ngx_http_request_t *r) | 1451 static void ngx_http_set_keepalive(ngx_http_request_t *r) |
1448 { | 1452 { |
1449 int len; | 1453 size_t len; |
1450 ngx_buf_t *b; | 1454 ngx_buf_t *b; |
1451 ngx_event_t *rev, *wev; | 1455 ngx_event_t *rev, *wev; |
1452 ngx_connection_t *c; | 1456 ngx_connection_t *c; |
1453 ngx_http_log_ctx_t *ctx; | 1457 ngx_http_log_ctx_t *ctx; |
1454 ngx_http_core_srv_conf_t *cscf; | 1458 ngx_http_core_srv_conf_t *cscf; |