mirror of
https://github.com/nginx/nginx.git
synced 2025-01-08 23:23:02 -06:00
store the upstream states before X-Accel-Redirect to a next upstream
This commit is contained in:
parent
eb21763fa1
commit
e0f866273f
@ -329,6 +329,8 @@ struct ngx_http_request_s {
|
|||||||
ngx_http_cache_t *cache;
|
ngx_http_cache_t *cache;
|
||||||
|
|
||||||
ngx_http_upstream_t *upstream;
|
ngx_http_upstream_t *upstream;
|
||||||
|
ngx_array_t *upstream_states;
|
||||||
|
/* of ngx_http_upstream_state_t */
|
||||||
|
|
||||||
ngx_pool_t *pool;
|
ngx_pool_t *pool;
|
||||||
ngx_buf_t *header_in;
|
ngx_buf_t *header_in;
|
||||||
|
@ -328,12 +328,25 @@ ngx_http_upstream_init(ngx_http_request_t *r)
|
|||||||
|
|
||||||
u->writer.pool = r->pool;
|
u->writer.pool = r->pool;
|
||||||
|
|
||||||
if (ngx_array_init(&u->states, r->pool, 1,
|
if (r->upstream_states == NULL) {
|
||||||
sizeof(ngx_http_upstream_state_t))
|
|
||||||
!= NGX_OK)
|
r->upstream_states = ngx_array_create(r->pool, 1,
|
||||||
{
|
sizeof(ngx_http_upstream_state_t));
|
||||||
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
if (r->upstream_states == NULL) {
|
||||||
return;
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
u->state = ngx_array_push(r->upstream_states);
|
||||||
|
if (u->state == NULL) {
|
||||||
|
ngx_http_upstream_finalize_request(r, u,
|
||||||
|
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
cln = ngx_http_cleanup_add(r, 0);
|
cln = ngx_http_cleanup_add(r, 0);
|
||||||
@ -509,7 +522,7 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||||||
u->state->response_msec = tp->msec - u->state->response_msec;
|
u->state->response_msec = tp->msec - u->state->response_msec;
|
||||||
}
|
}
|
||||||
|
|
||||||
u->state = ngx_array_push(&u->states);
|
u->state = ngx_array_push(r->upstream_states);
|
||||||
if (u->state == NULL) {
|
if (u->state == NULL) {
|
||||||
ngx_http_upstream_finalize_request(r, u,
|
ngx_http_upstream_finalize_request(r, u,
|
||||||
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
@ -2502,21 +2515,18 @@ ngx_http_upstream_status_variable(ngx_http_request_t *r,
|
|||||||
u_char *p;
|
u_char *p;
|
||||||
size_t len;
|
size_t len;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_http_upstream_t *u;
|
|
||||||
ngx_http_upstream_state_t *state;
|
ngx_http_upstream_state_t *state;
|
||||||
|
|
||||||
v->valid = 1;
|
v->valid = 1;
|
||||||
v->no_cachable = 0;
|
v->no_cachable = 0;
|
||||||
v->not_found = 0;
|
v->not_found = 0;
|
||||||
|
|
||||||
u = r->upstream;
|
if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
|
||||||
|
|
||||||
if (u == NULL || u->states.nelts == 0) {
|
|
||||||
v->not_found = 1;
|
v->not_found = 1;
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = u->states.nelts * (3 + 2);
|
len = r->upstream_states->nelts * (3 + 2);
|
||||||
|
|
||||||
p = ngx_palloc(r->pool, len);
|
p = ngx_palloc(r->pool, len);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
@ -2526,22 +2536,35 @@ ngx_http_upstream_status_variable(ngx_http_request_t *r,
|
|||||||
v->data = p;
|
v->data = p;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
state = u->states.elts;
|
state = r->upstream_states->elts;
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
if (state[i].status == 0) {
|
if (state[i].status) {
|
||||||
*p++ = '-';
|
p = ngx_sprintf(p, "%ui", state[i].status);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
p = ngx_sprintf(p, "%ui", state[i].status);
|
*p++ = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++i == u->states.nelts) {
|
if (++i == r->upstream_states->nelts) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = ',';
|
if (state[i].peer) {
|
||||||
*p++ = ' ';
|
*p++ = ',';
|
||||||
|
*p++ = ' ';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = ':';
|
||||||
|
*p++ = ' ';
|
||||||
|
|
||||||
|
if (++i == r->upstream_states->nelts) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v->len = p - v->data;
|
v->len = p - v->data;
|
||||||
@ -2558,21 +2581,18 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
|
|||||||
size_t len;
|
size_t len;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_msec_int_t ms;
|
ngx_msec_int_t ms;
|
||||||
ngx_http_upstream_t *u;
|
|
||||||
ngx_http_upstream_state_t *state;
|
ngx_http_upstream_state_t *state;
|
||||||
|
|
||||||
v->valid = 1;
|
v->valid = 1;
|
||||||
v->no_cachable = 0;
|
v->no_cachable = 0;
|
||||||
v->not_found = 0;
|
v->not_found = 0;
|
||||||
|
|
||||||
u = r->upstream;
|
if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
|
||||||
|
|
||||||
if (u == NULL || u->states.nelts == 0) {
|
|
||||||
v->not_found = 1;
|
v->not_found = 1;
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = u->states.nelts * (NGX_TIME_T_LEN + 4 + 2);
|
len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2);
|
||||||
|
|
||||||
p = ngx_palloc(r->pool, len);
|
p = ngx_palloc(r->pool, len);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
@ -2582,24 +2602,37 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
|
|||||||
v->data = p;
|
v->data = p;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
state = u->states.elts;
|
state = r->upstream_states->elts;
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
if (state[i].status == 0) {
|
if (state[i].status) {
|
||||||
*p++ = '-';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ms = state[i].response_sec * 1000 + state[i].response_msec;
|
ms = state[i].response_sec * 1000 + state[i].response_msec;
|
||||||
ms = (ms >= 0) ? ms : 0;
|
ms = (ms >= 0) ? ms : 0;
|
||||||
p = ngx_sprintf(p, "%d.%03d", ms / 1000, ms % 1000);
|
p = ngx_sprintf(p, "%d.%03d", ms / 1000, ms % 1000);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*p++ = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++i == u->states.nelts) {
|
if (++i == r->upstream_states->nelts) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = ',';
|
if (state[i].peer) {
|
||||||
*p++ = ' ';
|
*p++ = ',';
|
||||||
|
*p++ = ' ';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = ':';
|
||||||
|
*p++ = ' ';
|
||||||
|
|
||||||
|
if (++i == r->upstream_states->nelts) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v->len = p - v->data;
|
v->len = p - v->data;
|
||||||
|
@ -232,7 +232,6 @@ struct ngx_http_upstream_s {
|
|||||||
ngx_str_t method;
|
ngx_str_t method;
|
||||||
|
|
||||||
ngx_http_upstream_state_t *state;
|
ngx_http_upstream_state_t *state;
|
||||||
ngx_array_t states; /* of ngx_http_upstream_state_t */
|
|
||||||
|
|
||||||
ngx_str_t uri;
|
ngx_str_t uri;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user