Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 2402:cd6a1abe11a7
$upstream_response_length
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 11 Dec 2008 15:30:52 +0000 |
parents | dbe746851b31 |
children | 89ac47d91fc1 |
comparison
equal
deleted
inserted
replaced
2401:39f3b4f9989e | 2402:cd6a1abe11a7 |
---|---|
94 ngx_http_variable_value_t *v, uintptr_t data); | 94 ngx_http_variable_value_t *v, uintptr_t data); |
95 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, | 95 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, |
96 ngx_http_variable_value_t *v, uintptr_t data); | 96 ngx_http_variable_value_t *v, uintptr_t data); |
97 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, | 97 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, |
98 ngx_http_variable_value_t *v, uintptr_t data); | 98 ngx_http_variable_value_t *v, uintptr_t data); |
99 static ngx_int_t ngx_http_upstream_response_length_variable( | |
100 ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); | |
99 | 101 |
100 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); | 102 static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
101 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, | 103 static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, |
102 void *conf); | 104 void *conf); |
103 | 105 |
294 | 296 |
295 { ngx_string("upstream_response_time"), NULL, | 297 { ngx_string("upstream_response_time"), NULL, |
296 ngx_http_upstream_response_time_variable, 0, | 298 ngx_http_upstream_response_time_variable, 0, |
297 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 }, | 299 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
298 | 300 |
301 { ngx_string("upstream_response_length"), NULL, | |
302 ngx_http_upstream_response_length_variable, 0, | |
303 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
304 | |
299 { ngx_null_string, NULL, NULL, 0, 0, 0 } | 305 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
300 }; | 306 }; |
301 | 307 |
302 | 308 |
303 static ngx_http_upstream_next_t ngx_http_upstream_next_errors[] = { | 309 static ngx_http_upstream_next_t ngx_http_upstream_next_errors[] = { |
1377 n = u->buffer.last - u->buffer.pos; | 1383 n = u->buffer.last - u->buffer.pos; |
1378 | 1384 |
1379 if (n) { | 1385 if (n) { |
1380 u->buffer.last -= n; | 1386 u->buffer.last -= n; |
1381 | 1387 |
1388 u->state->response_length += n; | |
1389 | |
1382 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { | 1390 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
1383 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); | 1391 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
1384 return; | 1392 return; |
1385 } | 1393 } |
1386 | 1394 |
1579 if (n == 0 || n == NGX_ERROR) { | 1587 if (n == 0 || n == NGX_ERROR) { |
1580 ngx_http_upstream_finalize_request(r, u, n); | 1588 ngx_http_upstream_finalize_request(r, u, n); |
1581 return; | 1589 return; |
1582 } | 1590 } |
1583 | 1591 |
1592 u->state->response_length += n; | |
1593 | |
1584 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { | 1594 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
1585 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); | 1595 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); |
1586 return; | 1596 return; |
1587 } | 1597 } |
1588 | 1598 |
1607 | 1617 |
1608 static void | 1618 static void |
1609 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) | 1619 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) |
1610 { | 1620 { |
1611 int tcp_nodelay; | 1621 int tcp_nodelay; |
1612 ssize_t size; | 1622 ssize_t n; |
1613 ngx_int_t rc; | 1623 ngx_int_t rc; |
1614 ngx_event_pipe_t *p; | 1624 ngx_event_pipe_t *p; |
1615 ngx_connection_t *c; | 1625 ngx_connection_t *c; |
1616 ngx_pool_cleanup_t *cl; | 1626 ngx_pool_cleanup_t *cl; |
1617 ngx_pool_cleanup_file_t *clf; | 1627 ngx_pool_cleanup_file_t *clf; |
1679 } | 1689 } |
1680 | 1690 |
1681 c->tcp_nodelay = NGX_TCP_NODELAY_SET; | 1691 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
1682 } | 1692 } |
1683 | 1693 |
1684 size = u->buffer.last - u->buffer.pos; | 1694 n = u->buffer.last - u->buffer.pos; |
1685 | 1695 |
1686 if (size) { | 1696 if (n) { |
1687 u->buffer.last = u->buffer.pos; | 1697 u->buffer.last = u->buffer.pos; |
1688 | 1698 |
1689 if (u->input_filter(u->input_filter_ctx, size) == NGX_ERROR) { | 1699 u->state->response_length += n; |
1700 | |
1701 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { | |
1690 ngx_http_upstream_finalize_request(r, u, 0); | 1702 ngx_http_upstream_finalize_request(r, u, 0); |
1691 return; | 1703 return; |
1692 } | 1704 } |
1693 | 1705 |
1694 ngx_http_upstream_process_non_buffered_downstream(r); | 1706 ngx_http_upstream_process_non_buffered_downstream(r); |
1958 if (n == NGX_AGAIN) { | 1970 if (n == NGX_AGAIN) { |
1959 break; | 1971 break; |
1960 } | 1972 } |
1961 | 1973 |
1962 if (n > 0) { | 1974 if (n > 0) { |
1975 u->state->response_length += n; | |
1976 | |
1963 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { | 1977 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) { |
1964 ngx_http_upstream_finalize_request(r, u, 0); | 1978 ngx_http_upstream_finalize_request(r, u, 0); |
1965 return; | 1979 return; |
1966 } | 1980 } |
1967 } | 1981 } |
2478 | 2492 |
2479 if (u->state && u->state->response_sec) { | 2493 if (u->state && u->state->response_sec) { |
2480 tp = ngx_timeofday(); | 2494 tp = ngx_timeofday(); |
2481 u->state->response_sec = tp->sec - u->state->response_sec; | 2495 u->state->response_sec = tp->sec - u->state->response_sec; |
2482 u->state->response_msec = tp->msec - u->state->response_msec; | 2496 u->state->response_msec = tp->msec - u->state->response_msec; |
2497 | |
2498 if (u->pipe) { | |
2499 u->state->response_length = u->pipe->read_length; | |
2500 } | |
2483 } | 2501 } |
2484 | 2502 |
2485 u->finalize_request(r, rc); | 2503 u->finalize_request(r, rc); |
2486 | 2504 |
2487 if (u->peer.free) { | 2505 if (u->peer.free) { |
3093 p = ngx_sprintf(p, "%d.%03d", ms / 1000, ms % 1000); | 3111 p = ngx_sprintf(p, "%d.%03d", ms / 1000, ms % 1000); |
3094 | 3112 |
3095 } else { | 3113 } else { |
3096 *p++ = '-'; | 3114 *p++ = '-'; |
3097 } | 3115 } |
3116 | |
3117 if (++i == r->upstream_states->nelts) { | |
3118 break; | |
3119 } | |
3120 | |
3121 if (state[i].peer) { | |
3122 *p++ = ','; | |
3123 *p++ = ' '; | |
3124 | |
3125 } else { | |
3126 *p++ = ' '; | |
3127 *p++ = ':'; | |
3128 *p++ = ' '; | |
3129 | |
3130 if (++i == r->upstream_states->nelts) { | |
3131 break; | |
3132 } | |
3133 | |
3134 continue; | |
3135 } | |
3136 } | |
3137 | |
3138 v->len = p - v->data; | |
3139 | |
3140 return NGX_OK; | |
3141 } | |
3142 | |
3143 | |
3144 static ngx_int_t | |
3145 ngx_http_upstream_response_length_variable(ngx_http_request_t *r, | |
3146 ngx_http_variable_value_t *v, uintptr_t data) | |
3147 { | |
3148 u_char *p; | |
3149 size_t len; | |
3150 ngx_uint_t i; | |
3151 ngx_http_upstream_state_t *state; | |
3152 | |
3153 v->valid = 1; | |
3154 v->no_cacheable = 0; | |
3155 v->not_found = 0; | |
3156 | |
3157 if (r->upstream_states == NULL || r->upstream_states->nelts == 0) { | |
3158 v->not_found = 1; | |
3159 return NGX_OK; | |
3160 } | |
3161 | |
3162 len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2); | |
3163 | |
3164 p = ngx_pnalloc(r->pool, len); | |
3165 if (p == NULL) { | |
3166 return NGX_ERROR; | |
3167 } | |
3168 | |
3169 v->data = p; | |
3170 | |
3171 i = 0; | |
3172 state = r->upstream_states->elts; | |
3173 | |
3174 for ( ;; ) { | |
3175 p = ngx_sprintf(p, "%O", state[i].response_length); | |
3098 | 3176 |
3099 if (++i == r->upstream_states->nelts) { | 3177 if (++i == r->upstream_states->nelts) { |
3100 break; | 3178 break; |
3101 } | 3179 } |
3102 | 3180 |