comparison src/http/ngx_http_upstream.c @ 527:7fa11e5c6e96 release-0.1.38

nginx-0.1.38-RELEASE import *) Feature: the "limit_rate" directive is supported in in proxy and FastCGI mode. *) Feature: the "X-Accel-Limit-Rate" response header line is supported in proxy and FastCGI mode. *) Feature: the "break" directive. *) Feature: the "log_not_found" directive. *) Bugfix: the response status code was not changed when request was redirected by the ""X-Accel-Redirect" header line. *) Bugfix: the variables set by the "set" directive could not be used in SSI. *) Bugfix: the segmentation fault may occurred if the SSI page has more than one remote subrequest. *) Bugfix: nginx treated the backend response as invalid if the status line in the header was transferred in two packets; the bug had appeared in 0.1.29. *) Feature: the "ssi_types" directive. *) Feature: the "autoindex_exact_size" directive. *) Bugfix: the ngx_http_autoindex_module did not support the long file names in UTF-8. *) Feature: the IMAP/POP3 proxy.
author Igor Sysoev <igor@sysoev.ru>
date Fri, 08 Jul 2005 14:34:20 +0000
parents 09b42134ac0c
children e5d7d0334fdb
comparison
equal deleted inserted replaced
526:e31ce4d8b8e6 527:7fa11e5c6e96
37 static ngx_int_t 37 static ngx_int_t
38 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r, 38 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
39 ngx_table_elt_t *h, ngx_uint_t offset); 39 ngx_table_elt_t *h, ngx_uint_t offset);
40 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, 40 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r,
41 ngx_table_elt_t *h, ngx_uint_t offset); 41 ngx_table_elt_t *h, ngx_uint_t offset);
42 static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r,
43 ngx_table_elt_t *h, ngx_uint_t offset);
42 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, 44 static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r,
43 ngx_table_elt_t *h, ngx_uint_t offset); 45 ngx_table_elt_t *h, ngx_uint_t offset);
44 static ngx_int_t 46 static ngx_int_t
45 ngx_http_upstream_conditional_copy_header_line(ngx_http_request_t *r, 47 ngx_http_upstream_conditional_copy_header_line(ngx_http_request_t *r,
46 ngx_table_elt_t *h, ngx_uint_t offset); 48 ngx_table_elt_t *h, ngx_uint_t offset);
141 { ngx_string("X-Accel-Redirect"), 143 { ngx_string("X-Accel-Redirect"),
142 ngx_http_upstream_process_header_line, 144 ngx_http_upstream_process_header_line,
143 offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect), 145 offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect),
144 ngx_http_upstream_ignore_header_line, 0, 0 }, 146 ngx_http_upstream_ignore_header_line, 0, 0 },
145 147
148 { ngx_string("X-Accel-Limit-Rate"),
149 ngx_http_upstream_process_limit_rate, 0,
150 ngx_http_upstream_ignore_header_line, 0, 0 },
151
146 #if (NGX_HTTP_GZIP) 152 #if (NGX_HTTP_GZIP)
147 { ngx_string("Content-Encoding"), 153 { ngx_string("Content-Encoding"),
148 ngx_http_upstream_process_header_line, 154 ngx_http_upstream_process_header_line,
149 offsetof(ngx_http_upstream_headers_in_t, content_encoding), 155 offsetof(ngx_http_upstream_headers_in_t, content_encoding),
150 ngx_http_upstream_copy_content_encoding, 0, 0 }, 156 ngx_http_upstream_copy_content_encoding, 0, 0 },
297 char buf[1]; 303 char buf[1];
298 ngx_err_t err; 304 ngx_err_t err;
299 ngx_connection_t *c; 305 ngx_connection_t *c;
300 ngx_http_upstream_t *u; 306 ngx_http_upstream_t *u;
301 307
302 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, 308 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0,
303 "http upstream check client, write event:%d", ev->write); 309 "http upstream check client, write event:%d, \"%V\"",
310 ev->write, &r->uri);
304 311
305 c = r->connection; 312 c = r->connection;
306 u = r->upstream; 313 u = r->upstream;
307 314
315 if (c->closed) {
316 ngx_http_upstream_finalize_request(r, u,
317 NGX_HTTP_CLIENT_CLOSED_REQUEST);
318 return;
319 }
320
308 if (u->peer.connection == NULL) { 321 if (u->peer.connection == NULL) {
309 return; 322 return;
310 } 323 }
311 324
312 #if (NGX_HAVE_KQUEUE) 325 #if (NGX_HAVE_KQUEUE)
316 if (!ev->pending_eof) { 329 if (!ev->pending_eof) {
317 return; 330 return;
318 } 331 }
319 332
320 ev->eof = 1; 333 ev->eof = 1;
334 c->closed = 1;
321 335
322 if (ev->kq_errno) { 336 if (ev->kq_errno) {
323 ev->error = 1; 337 ev->error = 1;
324 } 338 }
325 339
326 if (!u->cachable && u->peer.connection) { 340 if (!u->cachable && u->peer.connection) {
327 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno, 341 ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
328 "kevent() reported that client closed " 342 "kevent() reported that client closed prematurely "
329 "prematurely connection, " 343 "connection, so upstream connection is closed too");
330 "so upstream connection is closed too");
331 ngx_http_upstream_finalize_request(r, u, 344 ngx_http_upstream_finalize_request(r, u,
332 NGX_HTTP_CLIENT_CLOSED_REQUEST); 345 NGX_HTTP_CLIENT_CLOSED_REQUEST);
333 return; 346 return;
334 } 347 }
335 348
372 if (n > 0) { 385 if (n > 0) {
373 return; 386 return;
374 } 387 }
375 388
376 ev->eof = 1; 389 ev->eof = 1;
390 c->closed = 1;
377 391
378 if (n == -1) { 392 if (n == -1) {
379 if (err == NGX_EAGAIN) { 393 if (err == NGX_EAGAIN) {
380 return; 394 return;
381 } 395 }
922 } 936 }
923 937
924 } 938 }
925 } 939 }
926 940
941 r->headers_out.status_line.len = 0;
942
927 ngx_http_internal_redirect(r, 943 ngx_http_internal_redirect(r,
928 &r->upstream->headers_in.x_accel_redirect->value, 944 &r->upstream->headers_in.x_accel_redirect->value,
929 NULL); 945 NULL);
930 return; 946 return;
931 } 947 }
1153 1169
1154 p = &u->pipe; 1170 p = &u->pipe;
1155 1171
1156 if (ev->timedout) { 1172 if (ev->timedout) {
1157 if (ev->write) { 1173 if (ev->write) {
1158 p->downstream_error = 1; 1174 if (ev->delayed) {
1159 ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, 1175
1160 "client timed out"); 1176 ev->timedout = 0;
1177 ev->delayed = 0;
1178
1179 if (!ev->ready) {
1180 ngx_add_timer(ev, p->send_timeout);
1181
1182 if (ngx_handle_write_event(ev, p->send_lowat) == NGX_ERROR)
1183 {
1184 ngx_http_upstream_finalize_request(r, u, 0);
1185 return;
1186 }
1187
1188 return;
1189 }
1190
1191 if (ngx_event_pipe(p, ev->write) == NGX_ABORT) {
1192 ngx_http_upstream_finalize_request(r, u, 0);
1193 return;
1194 }
1195
1196 } else {
1197 p->downstream_error = 1;
1198 ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT,
1199 "client timed out");
1200 }
1161 1201
1162 } else { 1202 } else {
1163 p->upstream_error = 1; 1203 p->upstream_error = 1;
1164 ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, 1204 ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT,
1165 "upstream timed out"); 1205 "upstream timed out");
1166 } 1206 }
1167 1207
1168 } else { 1208 } else {
1209 if (ev->write && ev->delayed) {
1210 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
1211 "http downstream delayed");
1212
1213 if (ngx_handle_write_event(ev, p->send_lowat) == NGX_ERROR) {
1214 return;
1215 }
1216
1217 return;
1218 }
1219
1169 if (ngx_event_pipe(p, ev->write) == NGX_ABORT) { 1220 if (ngx_event_pipe(p, ev->write) == NGX_ABORT) {
1170 ngx_http_upstream_finalize_request(r, u, 0); 1221 ngx_http_upstream_finalize_request(r, u, 0);
1171 return; 1222 return;
1172 } 1223 }
1173 } 1224 }
1279 status = NGX_HTTP_BAD_GATEWAY; 1330 status = NGX_HTTP_BAD_GATEWAY;
1280 } 1331 }
1281 } 1332 }
1282 1333
1283 if (r->connection->write->eof) { 1334 if (r->connection->write->eof) {
1335 r->connection->closed = 1;
1284 ngx_http_upstream_finalize_request(r, u, 1336 ngx_http_upstream_finalize_request(r, u,
1285 NGX_HTTP_CLIENT_CLOSED_REQUEST); 1337 NGX_HTTP_CLIENT_CLOSED_REQUEST);
1286 return; 1338 return;
1287 } 1339 }
1288 1340
1425 1477
1426 static ngx_int_t 1478 static ngx_int_t
1427 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, 1479 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
1428 ngx_uint_t offset) 1480 ngx_uint_t offset)
1429 { 1481 {
1482 return NGX_OK;
1483 }
1484
1485
1486 static ngx_int_t
1487 ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h,
1488 ngx_uint_t offset)
1489 {
1490 ngx_int_t n;
1491
1492 r->upstream->headers_in.x_accel_limit_rate = h;
1493
1494 n = ngx_atoi(h->value.data, h->value.len);
1495
1496 if (n != NGX_ERROR) {
1497 r->limit_rate = (size_t) n;
1498 }
1499
1430 return NGX_OK; 1500 return NGX_OK;
1431 } 1501 }
1432 1502
1433 1503
1434 static ngx_int_t 1504 static ngx_int_t