comparison src/http/ngx_http_request.c @ 613:c73c5c58c619 release-0.3.28

nginx-0.3.28-RELEASE import *) Feature: the "restrict_host_names" directive was canceled. *) Feature: the --with-cpu-opt=ppc64 configuration parameter. *) Bugfix: on some condition the proxied connection with a client was terminated prematurely. Thanks to Vladimir Shutoff. *) Bugfix: the "X-Accel-Limit-Rate" header line was not taken into account if the request was redirected using the "X-Accel-Redirect" header line. *) Bugfix: the "post_action" directive ran only after a successful completion of a request. *) Bugfix: the proxied response body generated by the "post_action" directive was transferred to a client.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 16 Feb 2006 15:26:46 +0000
parents 3f8a2132b93d
children 5ef026a2ac74
comparison
equal deleted inserted replaced
612:182bfe05e2c3 613:c73c5c58c619
23 ngx_table_elt_t *h, ngx_uint_t offset); 23 ngx_table_elt_t *h, ngx_uint_t offset);
24 static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r, 24 static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r,
25 ngx_table_elt_t *h, ngx_uint_t offset); 25 ngx_table_elt_t *h, ngx_uint_t offset);
26 26
27 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); 27 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
28 static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r); 28 static void ngx_http_find_virtual_server(ngx_http_request_t *r);
29 29
30 static void ngx_http_request_handler(ngx_event_t *ev); 30 static void ngx_http_request_handler(ngx_event_t *ev);
31 static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); 31 static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r);
32 static void ngx_http_writer(ngx_http_request_t *r); 32 static void ngx_http_writer(ngx_http_request_t *r);
33 33
37 37
38 static void ngx_http_set_keepalive(ngx_http_request_t *r); 38 static void ngx_http_set_keepalive(ngx_http_request_t *r);
39 static void ngx_http_keepalive_handler(ngx_event_t *ev); 39 static void ngx_http_keepalive_handler(ngx_event_t *ev);
40 static void ngx_http_set_lingering_close(ngx_http_request_t *r); 40 static void ngx_http_set_lingering_close(ngx_http_request_t *r);
41 static void ngx_http_lingering_close_handler(ngx_event_t *ev); 41 static void ngx_http_lingering_close_handler(ngx_event_t *ev);
42 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r);
42 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error); 43 static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error);
43 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error); 44 static void ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error);
44 static void ngx_http_close_connection(ngx_connection_t *c); 45 static void ngx_http_close_connection(ngx_connection_t *c);
45 46
46 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len); 47 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
1162 1163
1163 1164
1164 static ngx_int_t 1165 static ngx_int_t
1165 ngx_http_process_request_header(ngx_http_request_t *r) 1166 ngx_http_process_request_header(ngx_http_request_t *r)
1166 { 1167 {
1167 size_t len; 1168 size_t len;
1168 u_char *ua, *user_agent, ch; 1169 u_char *ua, *user_agent, ch;
1169 ngx_http_core_srv_conf_t *cscf;
1170 1170
1171 if (r->headers_in.host) { 1171 if (r->headers_in.host) {
1172 for (len = 0; len < r->headers_in.host->value.len; len++) { 1172 for (len = 0; len < r->headers_in.host->value.len; len++) {
1173 ch = r->headers_in.host->value.data[len]; 1173 ch = r->headers_in.host->value.data[len];
1174 1174
1183 len--; 1183 len--;
1184 } 1184 }
1185 1185
1186 r->headers_in.host_name_len = len; 1186 r->headers_in.host_name_len = len;
1187 1187
1188 if (ngx_http_find_virtual_server(r) != NGX_OK) { 1188 ngx_http_find_virtual_server(r);
1189 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1190 "client sent invalid \"Host\" header");
1191
1192 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1193
1194 if (cscf->restrict_host_names == NGX_HTTP_RESTRICT_HOST_CLOSE) {
1195 ngx_http_close_request(r, NGX_HTTP_BAD_REQUEST);
1196 return NGX_ERROR;
1197 }
1198
1199 ngx_http_finalize_request(r, NGX_HTTP_INVALID_HOST);
1200 return NGX_ERROR;
1201 }
1202 1189
1203 } else { 1190 } else {
1204 if (r->http_version > NGX_HTTP_VERSION_10) { 1191 if (r->http_version > NGX_HTTP_VERSION_10) {
1205 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1192 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1206 "client sent HTTP/1.1 request without \"Host\" header"); 1193 "client sent HTTP/1.1 request without \"Host\" header");
1314 1301
1315 return NGX_OK; 1302 return NGX_OK;
1316 } 1303 }
1317 1304
1318 1305
1319 static ngx_int_t 1306 static void
1320 ngx_http_find_virtual_server(ngx_http_request_t *r) 1307 ngx_http_find_virtual_server(ngx_http_request_t *r)
1321 { 1308 {
1322 size_t len; 1309 size_t len;
1323 u_char *host; 1310 u_char *host;
1324 ngx_http_virtual_names_t *vn; 1311 ngx_http_virtual_names_t *vn;
1326 ngx_http_core_srv_conf_t *cscf; 1313 ngx_http_core_srv_conf_t *cscf;
1327 1314
1328 vn = r->virtual_names; 1315 vn = r->virtual_names;
1329 1316
1330 if (vn == NULL) { 1317 if (vn == NULL) {
1331 return NGX_OK; 1318 return;
1332 } 1319 }
1333 1320
1334 host = r->headers_in.host->value.data; 1321 host = r->headers_in.host->value.data;
1335 len = r->headers_in.host_name_len; 1322 len = r->headers_in.host_name_len;
1336 1323
1349 if (cscf) { 1336 if (cscf) {
1350 goto found; 1337 goto found;
1351 } 1338 }
1352 } 1339 }
1353 1340
1354 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 1341 return;
1355
1356 if (cscf->restrict_host_names == NGX_HTTP_RESTRICT_HOST_OFF) {
1357 return NGX_OK;
1358 }
1359
1360 return NGX_ERROR;
1361 1342
1362 found: 1343 found:
1363 1344
1364 r->server_name.len = len; 1345 r->server_name.len = len;
1365 r->server_name.data = host; 1346 r->server_name.data = host;
1372 1353
1373 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { 1354 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
1374 r->connection->log->log_level = clcf->err_log->log_level; 1355 r->connection->log->log_level = clcf->err_log->log_level;
1375 } 1356 }
1376 1357
1377 return NGX_OK; 1358 return;
1378 } 1359 }
1379 1360
1380 1361
1381 static void 1362 static void
1382 ngx_http_request_handler(ngx_event_t *ev) 1363 ngx_http_request_handler(ngx_event_t *ev)
1409 1390
1410 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1391 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1411 "http finalize request: %d, \"%V?%V\"", 1392 "http finalize request: %d, \"%V?%V\"",
1412 rc, &r->uri, &r->args); 1393 rc, &r->uri, &r->args);
1413 1394
1414 if (rc == NGX_ERROR || r->connection->error) { 1395 if (rc == NGX_ERROR
1396 || rc == NGX_HTTP_REQUEST_TIME_OUT
1397 || r->connection->error)
1398 {
1399
1400 if (ngx_http_post_action(r) == NGX_OK) {
1401 return;
1402 }
1403
1415 ngx_http_close_request(r, 0); 1404 ngx_http_close_request(r, 0);
1416 return; 1405 return;
1417 } 1406 }
1418 1407
1419 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) { 1408 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) {
1513 if (r->connection->buffered) { 1502 if (r->connection->buffered) {
1514 (void) ngx_http_set_write_handler(r); 1503 (void) ngx_http_set_write_handler(r);
1515 return; 1504 return;
1516 } 1505 }
1517 1506
1518 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 1507 if (ngx_http_post_action(r) == NGX_OK) {
1519
1520 if (clcf->post_action.data) {
1521 r->http_version = NGX_HTTP_VERSION_9;
1522 r->header_only = 1;
1523 ngx_http_internal_redirect(r, &clcf->post_action, NULL);
1524 return; 1508 return;
1525 } 1509 }
1526 1510
1527 if (r->connection->read->timer_set) { 1511 if (r->connection->read->timer_set) {
1528 ngx_del_timer(r->connection->read); 1512 ngx_del_timer(r->connection->read);
1535 1519
1536 if (r->connection->destroyed) { 1520 if (r->connection->destroyed) {
1537 return; 1521 return;
1538 } 1522 }
1539 1523
1540 #if 0 1524 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1541 if (r->connection->read->pending_eof) {
1542 #if (NGX_HAVE_KQUEUE)
1543 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log,
1544 r->connection->read->kq_errno,
1545 "kevent() reported about an closed connection");
1546 #endif
1547 ngx_http_close_request(r, 0);
1548 return;
1549 }
1550 #endif
1551 1525
1552 if (!ngx_terminate 1526 if (!ngx_terminate
1553 && !ngx_exiting 1527 && !ngx_exiting
1554 && r->keepalive != 0 1528 && r->keepalive != 0
1555 && clcf->keepalive_timeout > 0) 1529 && clcf->keepalive_timeout > 0)
1614 if (!wev->delayed) { 1588 if (!wev->delayed) {
1615 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, 1589 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
1616 "client timed out"); 1590 "client timed out");
1617 c->timedout = 1; 1591 c->timedout = 1;
1618 1592
1619 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); 1593 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
1620 return; 1594 return;
1621 } 1595 }
1622 1596
1623 wev->timedout = 0; 1597 wev->timedout = 0;
1624 wev->delayed = 0; 1598 wev->delayed = 0;
2263 2237
2264 return ngx_http_output_filter(r, &out); 2238 return ngx_http_output_filter(r, &out);
2265 } 2239 }
2266 2240
2267 2241
2268 void 2242 static ngx_int_t
2243 ngx_http_post_action(ngx_http_request_t *r)
2244 {
2245 ngx_http_core_loc_conf_t *clcf;
2246
2247 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
2248
2249 if (clcf->post_action.data == NULL) {
2250 return NGX_DECLINED;
2251 }
2252
2253 r->http_version = NGX_HTTP_VERSION_9;
2254 r->header_only = 1;
2255
2256 ngx_http_internal_redirect(r, &clcf->post_action, NULL);
2257
2258 return NGX_OK;
2259 }
2260
2261
2262 static void
2269 ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error) 2263 ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error)
2270 { 2264 {
2271 ngx_connection_t *c; 2265 ngx_connection_t *c;
2272 ngx_http_cleanup_t *cln; 2266 ngx_http_cleanup_t *cln;
2273 2267
2283 ngx_http_request_done(r, error); 2277 ngx_http_request_done(r, error);
2284 ngx_http_close_connection(c); 2278 ngx_http_close_connection(c);
2285 } 2279 }
2286 2280
2287 2281
2288 void 2282 static void
2289 ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error) 2283 ngx_http_request_done(ngx_http_request_t *r, ngx_int_t error)
2290 { 2284 {
2291 ngx_log_t *log; 2285 ngx_log_t *log;
2292 ngx_uint_t i, n; 2286 ngx_uint_t i, n;
2293 struct linger linger; 2287 struct linger linger;