Mercurial > hg > nginx-ranges
comparison src/http/ngx_http_parse.c @ 56:3050baa54a26 NGINX_0_1_28
nginx 0.1.28
*) Bugfix: nginx hogs CPU while proxying the huge files.
*) Bugfix: nginx could not be built by gcc 4.0 on Linux.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 08 Apr 2005 00:00:00 +0400 |
parents | bcb5fce0b038 |
children | b55cbf18157e |
comparison
equal
deleted
inserted
replaced
55:729de7d75018 | 56:3050baa54a26 |
---|---|
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 | 10 |
11 | 11 |
12 ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) | 12 ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b) |
13 { | 13 { |
14 u_char ch, *p, *m; | 14 u_char c, ch, *p, *m; |
15 enum { | 15 enum { |
16 sw_start = 0, | 16 sw_start = 0, |
17 sw_method, | 17 sw_method, |
18 sw_space_after_method, | 18 sw_space_after_method, |
19 sw_spaces_before_uri, | 19 sw_spaces_before_uri, |
107 } | 107 } |
108 break; | 108 break; |
109 | 109 |
110 /* space* before URI */ | 110 /* space* before URI */ |
111 case sw_spaces_before_uri: | 111 case sw_spaces_before_uri: |
112 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { | 112 |
113 c = (u_char) (ch | 0x20); | |
114 if (c >= 'a' && c <= 'f') { | |
113 r->schema_start = p; | 115 r->schema_start = p; |
114 state = sw_schema; | 116 state = sw_schema; |
115 break; | 117 break; |
116 } | 118 } |
117 | 119 |
126 return NGX_HTTP_PARSE_INVALID_REQUEST; | 128 return NGX_HTTP_PARSE_INVALID_REQUEST; |
127 } | 129 } |
128 break; | 130 break; |
129 | 131 |
130 case sw_schema: | 132 case sw_schema: |
131 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { | 133 |
134 c = (u_char) (ch | 0x20); | |
135 if (c >= 'a' && c <= 'f') { | |
132 break; | 136 break; |
133 } | 137 } |
134 | 138 |
135 switch (ch) { | 139 switch (ch) { |
136 case ':': | 140 case ':': |
162 return NGX_HTTP_PARSE_INVALID_REQUEST; | 166 return NGX_HTTP_PARSE_INVALID_REQUEST; |
163 } | 167 } |
164 break; | 168 break; |
165 | 169 |
166 case sw_host: | 170 case sw_host: |
167 if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') | 171 |
168 || (ch >= '0' && ch <= '9') || ch == '.' || ch == '-') | 172 c = (u_char) (ch | 0x20); |
173 if (c >= 'a' && c <= 'f') { | |
174 break; | |
175 } | |
176 | |
177 if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '-') | |
169 { | 178 { |
170 break; | 179 break; |
171 } | 180 } |
172 | 181 |
173 switch (ch) { | 182 switch (ch) { |
202 break; | 211 break; |
203 | 212 |
204 /* check "/.", "//", "%", and "\" (Win32) in URI */ | 213 /* check "/.", "//", "%", and "\" (Win32) in URI */ |
205 case sw_after_slash_in_uri: | 214 case sw_after_slash_in_uri: |
206 | 215 |
207 if ((ch >= 'a' && ch <= 'z') | 216 c = (u_char) (ch | 0x20); |
208 || (ch >= 'A' && ch <= 'Z') | 217 if (c >= 'a' && c <= 'f') { |
209 || (ch >= '0' && ch <= '9')) | 218 state = sw_check_uri; |
210 { | 219 break; |
220 } | |
221 | |
222 if (ch >= '0' && ch <= '9') { | |
211 state = sw_check_uri; | 223 state = sw_check_uri; |
212 break; | 224 break; |
213 } | 225 } |
214 | 226 |
215 switch (ch) { | 227 switch (ch) { |
261 break; | 273 break; |
262 | 274 |
263 /* check "/", "%" and "\" (Win32) in URI */ | 275 /* check "/", "%" and "\" (Win32) in URI */ |
264 case sw_check_uri: | 276 case sw_check_uri: |
265 | 277 |
266 if ((ch >= 'a' && ch <= 'z') | 278 c = (u_char) (ch | 0x20); |
267 || (ch >= 'A' && ch <= 'Z') | 279 if (c >= 'a' && c <= 'f') { |
268 || (ch >= '0' && ch <= '9')) | 280 break; |
269 { | 281 } |
282 | |
283 if (ch >= '0' && ch <= '9') { | |
270 break; | 284 break; |
271 } | 285 } |
272 | 286 |
273 switch (ch) { | 287 switch (ch) { |
274 case '/': | 288 case '/': |
488 } | 502 } |
489 | 503 |
490 | 504 |
491 ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b) | 505 ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b) |
492 { | 506 { |
493 u_char c, ch, *p; | 507 u_char c, ch, *p; |
508 ngx_uint_t hash; | |
494 enum { | 509 enum { |
495 sw_start = 0, | 510 sw_start = 0, |
496 sw_name, | 511 sw_name, |
497 sw_space_before_value, | 512 sw_space_before_value, |
498 sw_value, | 513 sw_value, |
502 sw_almost_done, | 517 sw_almost_done, |
503 sw_header_almost_done | 518 sw_header_almost_done |
504 } state; | 519 } state; |
505 | 520 |
506 state = r->state; | 521 state = r->state; |
522 hash = r->header_hash; | |
507 | 523 |
508 for (p = b->pos; p < b->last; p++) { | 524 for (p = b->pos; p < b->last; p++) { |
509 ch = *p; | 525 ch = *p; |
510 | 526 |
511 switch (state) { | 527 switch (state) { |
526 state = sw_name; | 542 state = sw_name; |
527 r->header_name_start = p; | 543 r->header_name_start = p; |
528 | 544 |
529 c = (u_char) (ch | 0x20); | 545 c = (u_char) (ch | 0x20); |
530 if (c >= 'a' && c <= 'z') { | 546 if (c >= 'a' && c <= 'z') { |
547 hash = c; | |
531 break; | 548 break; |
532 } | 549 } |
533 | 550 |
534 if (ch == '-') { | 551 if (ch == '-') { |
552 hash = ch; | |
535 break; | 553 break; |
536 } | 554 } |
537 | 555 |
538 if (ch >= '0' && ch <= '9') { | 556 if (ch >= '0' && ch <= '9') { |
557 hash = ch; | |
539 break; | 558 break; |
540 } | 559 } |
541 | 560 |
542 r->invalid_header = 1; | 561 r->invalid_header = 1; |
543 state = sw_skip_line; | 562 state = sw_skip_line; |
548 | 567 |
549 /* header name */ | 568 /* header name */ |
550 case sw_name: | 569 case sw_name: |
551 c = (u_char) (ch | 0x20); | 570 c = (u_char) (ch | 0x20); |
552 if (c >= 'a' && c <= 'z') { | 571 if (c >= 'a' && c <= 'z') { |
572 hash += c; | |
553 break; | 573 break; |
554 } | 574 } |
555 | 575 |
556 if (ch == ':') { | 576 if (ch == ':') { |
557 r->header_name_end = p; | 577 r->header_name_end = p; |
558 state = sw_space_before_value; | 578 state = sw_space_before_value; |
559 break; | 579 break; |
560 } | 580 } |
561 | 581 |
562 if (ch == '-') { | 582 if (ch == '-') { |
583 hash += ch; | |
563 break; | 584 break; |
564 } | 585 } |
565 | 586 |
566 if (ch >= '0' && ch <= '9') { | 587 if (ch >= '0' && ch <= '9') { |
588 hash += ch; | |
567 break; | 589 break; |
568 } | 590 } |
569 | 591 |
570 /* IIS may send the duplicate "HTTP/1.1 ..." lines */ | 592 /* IIS may send the duplicate "HTTP/1.1 ..." lines */ |
571 if (ch == '/' | 593 if (ch == '/' |
679 } | 701 } |
680 } | 702 } |
681 | 703 |
682 b->pos = p; | 704 b->pos = p; |
683 r->state = state; | 705 r->state = state; |
706 r->header_hash = hash; | |
684 | 707 |
685 return NGX_AGAIN; | 708 return NGX_AGAIN; |
686 | 709 |
687 done: | 710 done: |
688 | 711 |
689 b->pos = p + 1; | 712 b->pos = p + 1; |
690 r->state = sw_start; | 713 r->state = sw_start; |
714 r->header_hash = hash; | |
691 | 715 |
692 return NGX_OK; | 716 return NGX_OK; |
693 | 717 |
694 header_done: | 718 header_done: |
695 | 719 |