mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
$upstream_response_length
This commit is contained in:
@@ -96,6 +96,8 @@ static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r,
|
|||||||
ngx_http_variable_value_t *v, uintptr_t data);
|
ngx_http_variable_value_t *v, uintptr_t data);
|
||||||
static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
|
static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
|
||||||
ngx_http_variable_value_t *v, uintptr_t data);
|
ngx_http_variable_value_t *v, uintptr_t data);
|
||||||
|
static ngx_int_t ngx_http_upstream_response_length_variable(
|
||||||
|
ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
|
||||||
|
|
||||||
static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
|
static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
|
||||||
static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
@@ -296,6 +298,10 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = {
|
|||||||
ngx_http_upstream_response_time_variable, 0,
|
ngx_http_upstream_response_time_variable, 0,
|
||||||
NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
||||||
|
|
||||||
|
{ ngx_string("upstream_response_length"), NULL,
|
||||||
|
ngx_http_upstream_response_length_variable, 0,
|
||||||
|
NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
||||||
|
|
||||||
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1379,6 +1385,8 @@ ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||||||
if (n) {
|
if (n) {
|
||||||
u->buffer.last -= n;
|
u->buffer.last -= n;
|
||||||
|
|
||||||
|
u->state->response_length += n;
|
||||||
|
|
||||||
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
||||||
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
||||||
return;
|
return;
|
||||||
@@ -1581,6 +1589,8 @@ ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u->state->response_length += n;
|
||||||
|
|
||||||
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
||||||
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
||||||
return;
|
return;
|
||||||
@@ -1609,7 +1619,7 @@ static void
|
|||||||
ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
||||||
{
|
{
|
||||||
int tcp_nodelay;
|
int tcp_nodelay;
|
||||||
ssize_t size;
|
ssize_t n;
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
ngx_event_pipe_t *p;
|
ngx_event_pipe_t *p;
|
||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
@@ -1681,12 +1691,14 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|||||||
c->tcp_nodelay = NGX_TCP_NODELAY_SET;
|
c->tcp_nodelay = NGX_TCP_NODELAY_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = u->buffer.last - u->buffer.pos;
|
n = u->buffer.last - u->buffer.pos;
|
||||||
|
|
||||||
if (size) {
|
if (n) {
|
||||||
u->buffer.last = u->buffer.pos;
|
u->buffer.last = u->buffer.pos;
|
||||||
|
|
||||||
if (u->input_filter(u->input_filter_ctx, size) == NGX_ERROR) {
|
u->state->response_length += n;
|
||||||
|
|
||||||
|
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
||||||
ngx_http_upstream_finalize_request(r, u, 0);
|
ngx_http_upstream_finalize_request(r, u, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1960,6 +1972,8 @@ ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
|
u->state->response_length += n;
|
||||||
|
|
||||||
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
|
||||||
ngx_http_upstream_finalize_request(r, u, 0);
|
ngx_http_upstream_finalize_request(r, u, 0);
|
||||||
return;
|
return;
|
||||||
@@ -2480,6 +2494,10 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
|
|||||||
tp = ngx_timeofday();
|
tp = ngx_timeofday();
|
||||||
u->state->response_sec = tp->sec - u->state->response_sec;
|
u->state->response_sec = tp->sec - u->state->response_sec;
|
||||||
u->state->response_msec = tp->msec - u->state->response_msec;
|
u->state->response_msec = tp->msec - u->state->response_msec;
|
||||||
|
|
||||||
|
if (u->pipe) {
|
||||||
|
u->state->response_length = u->pipe->read_length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u->finalize_request(r, rc);
|
u->finalize_request(r, rc);
|
||||||
@@ -3123,6 +3141,66 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t
|
||||||
|
ngx_http_upstream_response_length_variable(ngx_http_request_t *r,
|
||||||
|
ngx_http_variable_value_t *v, uintptr_t data)
|
||||||
|
{
|
||||||
|
u_char *p;
|
||||||
|
size_t len;
|
||||||
|
ngx_uint_t i;
|
||||||
|
ngx_http_upstream_state_t *state;
|
||||||
|
|
||||||
|
v->valid = 1;
|
||||||
|
v->no_cacheable = 0;
|
||||||
|
v->not_found = 0;
|
||||||
|
|
||||||
|
if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
|
||||||
|
v->not_found = 1;
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2);
|
||||||
|
|
||||||
|
p = ngx_pnalloc(r->pool, len);
|
||||||
|
if (p == NULL) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
v->data = p;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
state = r->upstream_states->elts;
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
|
p = ngx_sprintf(p, "%O", state[i].response_length);
|
||||||
|
|
||||||
|
if (++i == r->upstream_states->nelts) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state[i].peer) {
|
||||||
|
*p++ = ',';
|
||||||
|
*p++ = ' ';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = ':';
|
||||||
|
*p++ = ' ';
|
||||||
|
|
||||||
|
if (++i == r->upstream_states->nelts) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v->len = p - v->data;
|
||||||
|
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t
|
ngx_int_t
|
||||||
ngx_http_upstream_header_variable(ngx_http_request_t *r,
|
ngx_http_upstream_header_variable(ngx_http_request_t *r,
|
||||||
ngx_http_variable_value_t *v, uintptr_t data)
|
ngx_http_variable_value_t *v, uintptr_t data)
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ typedef struct {
|
|||||||
ngx_uint_t status;
|
ngx_uint_t status;
|
||||||
time_t response_sec;
|
time_t response_sec;
|
||||||
ngx_uint_t response_msec;
|
ngx_uint_t response_msec;
|
||||||
|
off_t response_length;
|
||||||
|
|
||||||
ngx_str_t *peer;
|
ngx_str_t *peer;
|
||||||
} ngx_http_upstream_state_t;
|
} ngx_http_upstream_state_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user