Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 164:84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 29 Oct 2003 08:30:44 +0000 |
parents | 88abd07d9f62 |
children | 894a01c6aea3 |
comparison
equal
deleted
inserted
replaced
163:fb61ba77beba | 164:84036764e215 |
---|---|
42 "client %s sent invalid \"Content-Length\" header, URL: %s" | 42 "client %s sent invalid \"Content-Length\" header, URL: %s" |
43 }; | 43 }; |
44 | 44 |
45 | 45 |
46 | 46 |
47 static ngx_http_header_t headers_in[] = { | 47 ngx_http_header_t ngx_http_headers_in[] = { |
48 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) }, | 48 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) }, |
49 { ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) }, | 49 { ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) }, |
50 { ngx_string("If-Modified-Since"), | 50 { ngx_string("If-Modified-Since"), |
51 offsetof(ngx_http_headers_in_t, if_modified_since) }, | 51 offsetof(ngx_http_headers_in_t, if_modified_since) }, |
52 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) }, | 52 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) }, |
64 | 64 |
65 { ngx_null_string, 0 } | 65 { ngx_null_string, 0 } |
66 }; | 66 }; |
67 | 67 |
68 | 68 |
69 ngx_http_header_t ngx_http_headers_out[] = { | |
70 { ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) }, | |
71 { ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) }, | |
72 { ngx_string("Content-Type"), | |
73 offsetof(ngx_http_headers_out_t, content_type) }, | |
74 { ngx_string("Content-Length"), | |
75 offsetof(ngx_http_headers_out_t, content_length) }, | |
76 { ngx_string("Content-Encoding"), | |
77 offsetof(ngx_http_headers_out_t, content_encoding) }, | |
78 | |
79 /* Location */ | |
80 | |
81 { ngx_string("Last-Modified"), | |
82 offsetof(ngx_http_headers_out_t, last_modified) }, | |
83 { ngx_string("Accept-Ranges"), | |
84 offsetof(ngx_http_headers_out_t, accept_ranges) }, | |
85 | |
86 { ngx_null_string, 0 } | |
87 }; | |
88 | |
89 | |
69 static void ngx_http_dummy(ngx_event_t *wev) | 90 static void ngx_http_dummy(ngx_event_t *wev) |
70 { | 91 { |
71 return; | 92 return; |
72 } | 93 } |
73 | 94 |
104 | 125 |
105 rev = c->read; | 126 rev = c->read; |
106 rev->event_handler = ngx_http_init_request; | 127 rev->event_handler = ngx_http_init_request; |
107 | 128 |
108 if (rev->ready) { | 129 if (rev->ready) { |
109 /* deferred accept */ | 130 /* deferred accept, aio, iocp, epoll */ |
110 ngx_http_init_request(rev); | 131 ngx_http_init_request(rev); |
111 return; | 132 return; |
112 } | 133 } |
113 | 134 |
114 ngx_add_timer(rev, c->listening->post_accept_timeout); | 135 ngx_add_timer(rev, c->listening->post_accept_timeout); |
115 | 136 |
116 if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_EDGE_EVENT)) { | 137 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
117 /* aio, iocp, epoll */ | |
118 ngx_http_init_request(rev); | |
119 return; | |
120 } | |
121 | |
122 if (ngx_handle_read_event(rev) == NGX_ERROR) { | |
123 ngx_http_close_connection(c); | 138 ngx_http_close_connection(c); |
124 return; | 139 return; |
125 } | 140 } |
126 | 141 |
127 #if 0 | 142 #if 0 |
254 if (r->pool == NULL) { | 269 if (r->pool == NULL) { |
255 ngx_http_close_connection(c); | 270 ngx_http_close_connection(c); |
256 return; | 271 return; |
257 } | 272 } |
258 | 273 |
259 r->headers_out.headers = ngx_create_table(r->pool, 10); | 274 r->headers_out.headers = ngx_create_table(r->pool, 1); |
260 if (r->headers_out.headers == NULL) { | 275 if (r->headers_out.headers == NULL) { |
261 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 276 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
262 ngx_http_close_connection(c); | 277 ngx_http_close_connection(c); |
263 return; | 278 return; |
264 } | 279 } |
449 } | 464 } |
450 | 465 |
451 lctx = c->log->data; | 466 lctx = c->log->data; |
452 lctx->action = "reading client request headers"; | 467 lctx->action = "reading client request headers"; |
453 lctx->url = r->unparsed_uri.data; | 468 lctx->url = r->unparsed_uri.data; |
454 r->headers_in.headers = ngx_create_table(r->pool, 10); | 469 r->headers_in.headers = ngx_create_table(r->pool, 1); |
455 | 470 |
456 if (cscf->large_client_header | 471 if (cscf->large_client_header |
457 && r->header_in->pos == r->header_in->last) | 472 && r->header_in->pos == r->header_in->last) |
458 { | 473 { |
459 r->header_in->pos = r->header_in->last = r->header_in->start; | 474 r->header_in->pos = r->header_in->last = r->header_in->start; |
558 | 573 |
559 if (rc == NGX_OK) { | 574 if (rc == NGX_OK) { |
560 | 575 |
561 /* a header line has been parsed successfully */ | 576 /* a header line has been parsed successfully */ |
562 | 577 |
563 h = ngx_push_table(r->headers_in.headers); | 578 if (!(h = ngx_http_add_header(&r->headers_in, ngx_http_headers_in))) |
564 if (h == NULL) { | 579 { |
565 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 580 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
566 ngx_http_close_connection(c); | 581 ngx_http_close_connection(c); |
567 return; | 582 return; |
568 } | 583 } |
569 | 584 |
591 h->key.data[h->key.len] = '\0'; | 606 h->key.data[h->key.len] = '\0'; |
592 h->value.data = r->header_start; | 607 h->value.data = r->header_start; |
593 h->value.data[h->value.len] = '\0'; | 608 h->value.data[h->value.len] = '\0'; |
594 } | 609 } |
595 | 610 |
596 for (i = 0; headers_in[i].name.len != 0; i++) { | 611 for (i = 0; ngx_http_headers_in[i].name.len != 0; i++) { |
597 if (headers_in[i].name.len != h->key.len) { | 612 if (ngx_http_headers_in[i].name.len != h->key.len) { |
598 continue; | 613 continue; |
599 } | 614 } |
600 | 615 |
601 if (ngx_strcasecmp(headers_in[i].name.data, h->key.data) == 0) { | 616 if (ngx_strcasecmp(ngx_http_headers_in[i].name.data, |
602 *((ngx_table_elt_t **) | 617 h->key.data) == 0) |
603 ((char *) &r->headers_in + headers_in[i].offset)) = h; | 618 { |
619 *((ngx_table_elt_t **) ((char *) &r->headers_in | |
620 + ngx_http_headers_in[i].offset)) = h; | |
604 break; | 621 break; |
605 } | 622 } |
606 } | 623 } |
607 | 624 |
608 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ | 625 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _ |
690 rev = r->connection->read; | 707 rev = r->connection->read; |
691 | 708 |
692 n = r->header_in->last - r->header_in->pos; | 709 n = r->header_in->last - r->header_in->pos; |
693 | 710 |
694 if (n > 0) { | 711 if (n > 0) { |
695 #if 0 | |
696 /* TODO: THINK - AIO ??? */ | |
697 rev->ready = 0; | |
698 #endif | |
699 return n; | 712 return n; |
700 } | 713 } |
701 | 714 |
702 n = ngx_recv(r->connection, r->header_in->last, | 715 n = ngx_recv(r->connection, r->header_in->last, |
703 r->header_in->end - r->header_in->last); | 716 r->header_in->end - r->header_in->last); |
707 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 720 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
708 ngx_add_timer(rev, cscf->client_header_timeout); | 721 ngx_add_timer(rev, cscf->client_header_timeout); |
709 r->header_timeout_set = 1; | 722 r->header_timeout_set = 1; |
710 } | 723 } |
711 | 724 |
712 if (ngx_handle_read_event(rev) == NGX_ERROR) { | 725 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
713 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 726 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
714 ngx_http_close_connection(r->connection); | 727 ngx_http_close_connection(r->connection); |
715 return NGX_ERROR; | 728 return NGX_ERROR; |
716 } | 729 } |
717 | 730 |
1155 return; | 1168 return; |
1156 } | 1169 } |
1157 c->tcp_nopush = 0; | 1170 c->tcp_nopush = 0; |
1158 } | 1171 } |
1159 | 1172 |
1160 if (rev->ready || (ngx_event_flags & NGX_USE_AIO_EVENT)) { | 1173 if (rev->ready) { |
1161 ngx_http_keepalive_handler(rev); | 1174 ngx_http_keepalive_handler(rev); |
1162 } | 1175 } |
1163 } | 1176 } |
1164 | 1177 |
1165 | 1178 |
1254 ngx_http_close_request(r, 0); | 1267 ngx_http_close_request(r, 0); |
1255 ngx_http_close_connection(c); | 1268 ngx_http_close_connection(c); |
1256 return; | 1269 return; |
1257 } | 1270 } |
1258 | 1271 |
1259 if (rev->ready || (ngx_event_flags & NGX_USE_AIO_EVENT)) { | 1272 if (rev->ready) { |
1260 ngx_http_lingering_close_handler(rev); | 1273 ngx_http_lingering_close_handler(rev); |
1261 } | 1274 } |
1262 } | 1275 } |
1263 | 1276 |
1264 | 1277 |