Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 294:5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 23 Mar 2004 06:01:52 +0000 |
parents | ec3c049681fd |
children | 4a3f18406832 |
comparison
equal
deleted
inserted
replaced
293:ec3c049681fd | 294:5cfd65b8b0a7 |
---|---|
36 "client %s sent invalid method in HTTP/0.9 request", | 36 "client %s sent invalid method in HTTP/0.9 request", |
37 | 37 |
38 "client %s sent invalid header, URL: %s", | 38 "client %s sent invalid header, URL: %s", |
39 "client %s sent too long header line, URL: %s", | 39 "client %s sent too long header line, URL: %s", |
40 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", | 40 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", |
41 "client %s sent invalid \"Content-Length\" header, URL: %s", | 41 "client %s sent invalid \"Content-Length\" header, URL: %s" |
42 "client %s wanted to send too large body: " SIZE_T_FMT " bytes, URL: %s" | |
43 }; | 42 }; |
44 | 43 |
45 | 44 |
46 #if 0 | 45 #if 0 |
47 static void ngx_http_dummy(ngx_event_t *wev) | 46 static void ngx_http_dummy(ngx_event_t *wev) |
246 */ | 245 */ |
247 r->cleanup.nalloc = 5; | 246 r->cleanup.nalloc = 5; |
248 r->cleanup.size = sizeof(ngx_http_cleanup_t); | 247 r->cleanup.size = sizeof(ngx_http_cleanup_t); |
249 r->cleanup.pool = r->pool; | 248 r->cleanup.pool = r->pool; |
250 | 249 |
251 /* TODO: ngx_init_table */ | 250 |
252 if (!(r->headers_out.headers = ngx_create_table(r->pool, 20))) { | 251 /* init the r->headers_out.headers table */ |
252 | |
253 r->headers_out.headers.elts = ngx_pcalloc(r->pool, | |
254 20 * sizeof(ngx_table_elt_t)); | |
255 if (r->headers_out.headers.elts == NULL) { | |
253 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 256 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
254 ngx_http_close_connection(c); | 257 ngx_http_close_connection(c); |
255 return; | 258 return; |
256 } | 259 } |
260 /* r->headers_out.headers.nelts = 0; */ | |
261 r->headers_out.headers.nalloc = 20; | |
262 r->headers_out.headers.size = sizeof(ngx_table_elt_t); | |
263 r->headers_out.headers.pool = r->pool; | |
264 | |
257 | 265 |
258 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); | 266 r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); |
259 if (r->ctx == NULL) { | 267 if (r->ctx == NULL) { |
260 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 268 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
261 ngx_http_close_connection(c); | 269 ngx_http_close_connection(c); |
467 rev->event_handler = ngx_http_block_read; | 475 rev->event_handler = ngx_http_block_read; |
468 ngx_http_handler(r); | 476 ngx_http_handler(r); |
469 return; | 477 return; |
470 } | 478 } |
471 | 479 |
480 | |
481 /* init the r->headers_in.headers table */ | |
482 | |
483 r->headers_in.headers.elts = ngx_pcalloc(r->pool, | |
484 20 * sizeof(ngx_table_elt_t)); | |
485 if (r->headers_in.headers.elts == NULL) { | |
486 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
487 ngx_http_close_connection(c); | |
488 return; | |
489 } | |
490 | |
491 /* r->headers_in.headers.elts = NULL; */ | |
492 /* r->headers_in.headers.nelts = 0; */ | |
493 r->headers_in.headers.size = sizeof(ngx_table_elt_t); | |
494 r->headers_in.headers.nalloc = 20; | |
495 r->headers_in.headers.pool = r->pool; | |
496 | |
472 ctx = c->log->data; | 497 ctx = c->log->data; |
473 ctx->action = "reading client request headers"; | 498 ctx->action = "reading client request headers"; |
474 ctx->url = r->unparsed_uri.data; | 499 ctx->url = r->unparsed_uri.data; |
475 /* TODO: ngx_init_table */ | |
476 r->headers_in.headers = ngx_create_table(r->pool, 20); | |
477 | 500 |
478 if (cscf->large_client_header | 501 if (cscf->large_client_header |
479 && r->header_in->pos == r->header_in->last) | 502 && r->header_in->pos == r->header_in->last) |
480 { | 503 { |
481 r->header_in->pos = r->header_in->last = r->header_in->start; | 504 r->header_in->pos = r->header_in->last = r->header_in->start; |
846 r->headers_in.content_length->value.len); | 869 r->headers_in.content_length->value.len); |
847 | 870 |
848 if (r->headers_in.content_length_n == NGX_ERROR) { | 871 if (r->headers_in.content_length_n == NGX_ERROR) { |
849 return NGX_HTTP_PARSE_INVALID_CL_HEADER; | 872 return NGX_HTTP_PARSE_INVALID_CL_HEADER; |
850 } | 873 } |
851 | |
852 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
853 | |
854 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
855 "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT, | |
856 r->headers_in.content_length_n, | |
857 clcf->client_max_body_size); | |
858 | |
859 if (clcf->client_max_body_size | |
860 && clcf->client_max_body_size | |
861 < (size_t) r->headers_in.content_length_n) | |
862 { | |
863 return NGX_HTTP_PARSE_ENTITY_TOO_LARGE; | |
864 } | |
865 | |
866 } | 874 } |
867 | 875 |
868 if (r->headers_in.connection) { | 876 if (r->headers_in.connection) { |
869 if (r->headers_in.connection->value.len == 5 | 877 if (r->headers_in.connection->value.len == 5 |
870 && ngx_strcasecmp(r->headers_in.connection->value.data, "close") | 878 && ngx_strcasecmp(r->headers_in.connection->value.data, "close") |
909 ngx_del_timer(r->connection->read); | 917 ngx_del_timer(r->connection->read); |
910 } | 918 } |
911 | 919 |
912 if (r->connection->write->timer_set) { | 920 if (r->connection->write->timer_set) { |
913 ngx_del_timer(r->connection->write); | 921 ngx_del_timer(r->connection->write); |
922 } | |
923 | |
924 if (rc == NGX_HTTP_CLIENT_CLOSED_REQUEST || r->closed) { | |
925 ngx_http_close_request(r, 0); | |
926 ngx_http_close_connection(r->connection); | |
927 return; | |
914 } | 928 } |
915 | 929 |
916 ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); | 930 ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); |
917 | 931 |
918 return; | 932 return; |
1096 if (ngx_handle_level_read_event(rev) == NGX_ERROR) { | 1110 if (ngx_handle_level_read_event(rev) == NGX_ERROR) { |
1097 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 1111 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
1098 } | 1112 } |
1099 | 1113 |
1100 return ngx_http_read_discarded_body(r); | 1114 return ngx_http_read_discarded_body(r); |
1101 | |
1102 return NGX_OK; | |
1103 } | 1115 } |
1104 | 1116 |
1105 | 1117 |
1106 static void ngx_http_read_discarded_body_event(ngx_event_t *rev) | 1118 static void ngx_http_read_discarded_body_event(ngx_event_t *rev) |
1107 { | 1119 { |
1156 size = (ssize_t) clcf->discarded_buffer_size; | 1168 size = (ssize_t) clcf->discarded_buffer_size; |
1157 } | 1169 } |
1158 | 1170 |
1159 n = ngx_recv(r->connection, r->discarded_buffer, size); | 1171 n = ngx_recv(r->connection, r->discarded_buffer, size); |
1160 if (n == NGX_ERROR) { | 1172 if (n == NGX_ERROR) { |
1161 return NGX_HTTP_BAD_REQUEST; | 1173 |
1174 r->closed = 1; | |
1175 | |
1176 /* | |
1177 * when a client request body is discarded then we already set | |
1178 * some HTTP response code for client and we can ignore the error | |
1179 */ | |
1180 | |
1181 return NGX_OK; | |
1162 } | 1182 } |
1163 | 1183 |
1164 if (n == NGX_AGAIN) { | 1184 if (n == NGX_AGAIN) { |
1165 return NGX_AGAIN; | 1185 return NGX_AGAIN; |
1166 } | 1186 } |
1604 } | 1624 } |
1605 | 1625 |
1606 r->connection->log->handler = NULL; | 1626 r->connection->log->handler = NULL; |
1607 | 1627 |
1608 if (ctx->url) { | 1628 if (ctx->url) { |
1609 if (client_error == NGX_HTTP_PARSE_ENTITY_TOO_LARGE) { | 1629 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1610 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1611 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], | |
1612 ctx->client, r->headers_in.content_length_n, ctx->url); | |
1613 | |
1614 error = NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; | |
1615 r->lingering_close = 1; | |
1616 | |
1617 } else { | |
1618 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1619 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], | 1630 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], |
1620 ctx->client, ctx->url); | 1631 ctx->client, ctx->url); |
1621 } | |
1622 | 1632 |
1623 } else { | 1633 } else { |
1624 if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { | 1634 if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { |
1625 r->request_line.len = r->header_in->end - r->request_start; | 1635 r->request_line.len = r->header_in->end - r->request_start; |
1626 r->request_line.data = r->request_start; | 1636 r->request_line.data = r->request_start; |