comparison src/http/ngx_http_parse.c @ 198:e6da4931e0e0 NGINX_0_3_46

nginx 0.3.46 *) Feature: the "proxy_hide_header", "proxy_pass_header", "fastcgi_hide_header", and "fastcgi_pass_header" directives. *) Change: the "proxy_pass_x_powered_by", "fastcgi_x_powered_by", and "proxy_pass_server" directives were canceled. *) Feature: the "X-Accel-Buffering" response header line is supported in proxy mode. *) Bugfix: the reconfiguration bug and memory leaks in the ngx_http_perl_module.
author Igor Sysoev <http://sysoev.ru>
date Thu, 11 May 2006 00:00:00 +0400
parents af37b7cb6698
children 3866d57d9cfd
comparison
equal deleted inserted replaced
197:93658b91fad2 198:e6da4931e0e0
6 6
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 10
11
12 /* gcc, icc, msvc and others compile these switches as an jump table */
11 13
12 ngx_int_t 14 ngx_int_t
13 ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) 15 ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
14 { 16 {
15 u_char c, ch, *p, *m; 17 u_char c, ch, *p, *m;
41 state = r->state; 43 state = r->state;
42 44
43 for (p = b->pos; p < b->last; p++) { 45 for (p = b->pos; p < b->last; p++) {
44 ch = *p; 46 ch = *p;
45 47
46 /* gcc 2.95.2 and msvc 6.0 compile this switch as an jump table */
47
48 switch (state) { 48 switch (state) {
49 49
50 /* HTTP methods: GET, HEAD, POST */ 50 /* HTTP methods: GET, HEAD, POST */
51 case sw_start: 51 case sw_start:
52 r->request_start = p; 52 r->request_start = p;
526 526
527 ngx_int_t 527 ngx_int_t
528 ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b) 528 ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
529 { 529 {
530 u_char c, ch, *p; 530 u_char c, ch, *p;
531 ngx_uint_t hash; 531 ngx_uint_t hash, i;
532 enum { 532 enum {
533 sw_start = 0, 533 sw_start = 0,
534 sw_name, 534 sw_name,
535 sw_space_before_value, 535 sw_space_before_value,
536 sw_value, 536 sw_value,
538 sw_ignore_line, 538 sw_ignore_line,
539 sw_almost_done, 539 sw_almost_done,
540 sw_header_almost_done 540 sw_header_almost_done
541 } state; 541 } state;
542 542
543 static u_char lowcase[] =
544 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
545 "\0\0\0\0\0\0\0\0\0\0\0\0\0-\0\0" "0123456789\0\0\0\0\0\0"
546 "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0\0"
547 "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0\0"
548 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
549 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
550 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
551 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
552
543 state = r->state; 553 state = r->state;
544 hash = r->header_hash; 554 hash = r->header_hash;
555 i = r->lowcase_index;
545 556
546 for (p = b->pos; p < b->last; p++) { 557 for (p = b->pos; p < b->last; p++) {
547 ch = *p; 558 ch = *p;
548 559
549 switch (state) { 560 switch (state) {
562 goto header_done; 573 goto header_done;
563 default: 574 default:
564 state = sw_name; 575 state = sw_name;
565 r->header_name_start = p; 576 r->header_name_start = p;
566 577
567 c = (u_char) (ch | 0x20); 578 c = lowcase[ch];
568 if (c >= 'a' && c <= 'z') { 579
569 hash = c; 580 if (c) {
570 break; 581 hash = ngx_hash(0, c);
571 } 582 r->lowcase_header[0] = c;
572 583 i = 1;
573 if (ch >= '0' && ch <= '9') {
574 hash = ch;
575 break; 584 break;
576 } 585 }
577 586
578 r->invalid_header = 1; 587 r->invalid_header = 1;
579 588
582 } 591 }
583 break; 592 break;
584 593
585 /* header name */ 594 /* header name */
586 case sw_name: 595 case sw_name:
587 c = (u_char) (ch | 0x20); 596 c = lowcase[ch];
588 if (c >= 'a' && c <= 'z') { 597
589 hash += c; 598 if (c) {
599 hash = ngx_hash(hash, c);
600 r->lowcase_header[i++] = c;
601 i &= ~NGX_HTTP_LC_HEADER_LEN;
590 break; 602 break;
591 } 603 }
592 604
593 if (ch == ':') { 605 if (ch == ':') {
594 r->header_name_end = p; 606 r->header_name_end = p;
595 state = sw_space_before_value; 607 state = sw_space_before_value;
596 break;
597 }
598
599 if (ch == '-') {
600 hash += ch;
601 break;
602 }
603
604 if (ch >= '0' && ch <= '9') {
605 hash += ch;
606 break; 608 break;
607 } 609 }
608 610
609 if (ch == CR) { 611 if (ch == CR) {
610 r->header_name_end = p; 612 r->header_name_end = p;
724 } 726 }
725 727
726 b->pos = p; 728 b->pos = p;
727 r->state = state; 729 r->state = state;
728 r->header_hash = hash; 730 r->header_hash = hash;
731 r->lowcase_index = i;
729 732
730 return NGX_AGAIN; 733 return NGX_AGAIN;
731 734
732 done: 735 done:
733 736
734 b->pos = p + 1; 737 b->pos = p + 1;
735 r->state = sw_start; 738 r->state = sw_start;
736 r->header_hash = hash; 739 r->header_hash = hash;
740 r->lowcase_index = i;
737 741
738 return NGX_OK; 742 return NGX_OK;
739 743
740 header_done: 744 header_done:
741 745