Mercurial > hg > nginx
comparison src/http/modules/ngx_http_fastcgi_module.c @ 3025:baff3edcb6e2
refactor fastcgi stderr handling
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 12 Aug 2009 14:38:44 +0000 |
parents | 5957e869f04d |
children | d5d1ad05d3a6 |
comparison
equal
deleted
inserted
replaced
3024:8101d9101ed8 | 3025:baff3edcb6e2 |
---|---|
1063 | 1063 |
1064 | 1064 |
1065 static ngx_int_t | 1065 static ngx_int_t |
1066 ngx_http_fastcgi_process_header(ngx_http_request_t *r) | 1066 ngx_http_fastcgi_process_header(ngx_http_request_t *r) |
1067 { | 1067 { |
1068 u_char *p, *start, *last, *part_start, *part_end; | 1068 u_char *p, *msg, *start, *last, |
1069 *part_start, *part_end; | |
1069 size_t size; | 1070 size_t size; |
1070 ngx_str_t *status_line, line, *pattern; | 1071 ngx_str_t *status_line, *pattern; |
1071 ngx_int_t rc, status; | 1072 ngx_int_t rc, status; |
1072 ngx_buf_t buf; | 1073 ngx_buf_t buf; |
1073 ngx_uint_t i; | 1074 ngx_uint_t i; |
1074 ngx_table_elt_t *h; | 1075 ngx_table_elt_t *h; |
1075 ngx_http_upstream_t *u; | 1076 ngx_http_upstream_t *u; |
1149 /* f->state == ngx_http_fastcgi_st_data */ | 1150 /* f->state == ngx_http_fastcgi_st_data */ |
1150 | 1151 |
1151 if (f->type == NGX_HTTP_FASTCGI_STDERR) { | 1152 if (f->type == NGX_HTTP_FASTCGI_STDERR) { |
1152 | 1153 |
1153 if (f->length) { | 1154 if (f->length) { |
1154 line.data = u->buffer.pos; | 1155 msg = u->buffer.pos; |
1155 | 1156 |
1156 if (u->buffer.pos + f->length <= u->buffer.last) { | 1157 if (u->buffer.pos + f->length <= u->buffer.last) { |
1157 line.len = f->length; | |
1158 u->buffer.pos += f->length; | 1158 u->buffer.pos += f->length; |
1159 f->length = 0; | 1159 f->length = 0; |
1160 f->state = ngx_http_fastcgi_st_padding; | 1160 f->state = ngx_http_fastcgi_st_padding; |
1161 | 1161 |
1162 } else { | 1162 } else { |
1163 line.len = u->buffer.last - u->buffer.pos; | |
1164 f->length -= u->buffer.last - u->buffer.pos; | 1163 f->length -= u->buffer.last - u->buffer.pos; |
1165 u->buffer.pos = u->buffer.last; | 1164 u->buffer.pos = u->buffer.last; |
1166 } | 1165 } |
1167 | 1166 |
1168 while (line.data[line.len - 1] == LF | 1167 for (p = u->buffer.pos - 1; msg < p; p--) { |
1169 || line.data[line.len - 1] == CR | 1168 if (*p != LF && *p != CR && *p != '.' && *p != ' ') { |
1170 || line.data[line.len - 1] == '.' | 1169 break; |
1171 || line.data[line.len - 1] == ' ') | 1170 } |
1172 { | |
1173 line.len--; | |
1174 } | 1171 } |
1175 | 1172 |
1173 p++; | |
1174 | |
1176 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1175 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1177 "FastCGI sent in stderr: \"%V\"", &line); | 1176 "FastCGI sent in stderr: \"%*s\"", p - msg, msg); |
1178 | 1177 |
1179 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); | 1178 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
1180 | 1179 |
1181 if (flcf->catch_stderr) { | 1180 if (flcf->catch_stderr) { |
1182 pattern = flcf->catch_stderr->elts; | 1181 pattern = flcf->catch_stderr->elts; |
1183 | 1182 |
1184 line.data[line.len - 1] = '\0'; | |
1185 | |
1186 for (i = 0; i < flcf->catch_stderr->nelts; i++) { | 1183 for (i = 0; i < flcf->catch_stderr->nelts; i++) { |
1187 if (ngx_strstr(line.data, pattern[i].data)) { | 1184 if (ngx_strnstr(msg, (char *) pattern[i].data, |
1185 p - msg) | |
1186 != NULL) | |
1187 { | |
1188 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | 1188 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
1189 } | 1189 } |
1190 } | 1190 } |
1191 } | 1191 } |
1192 | 1192 |
1450 | 1450 |
1451 | 1451 |
1452 static ngx_int_t | 1452 static ngx_int_t |
1453 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) | 1453 ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) |
1454 { | 1454 { |
1455 u_char *m, *msg; | |
1455 ngx_int_t rc; | 1456 ngx_int_t rc; |
1456 ngx_buf_t *b, **prev; | 1457 ngx_buf_t *b, **prev; |
1457 ngx_str_t line; | |
1458 ngx_chain_t *cl; | 1458 ngx_chain_t *cl; |
1459 ngx_http_request_t *r; | 1459 ngx_http_request_t *r; |
1460 ngx_http_fastcgi_ctx_t *f; | 1460 ngx_http_fastcgi_ctx_t *f; |
1461 | 1461 |
1462 if (buf->pos == buf->last) { | 1462 if (buf->pos == buf->last) { |
1536 | 1536 |
1537 if (f->pos == f->last) { | 1537 if (f->pos == f->last) { |
1538 break; | 1538 break; |
1539 } | 1539 } |
1540 | 1540 |
1541 line.data = f->pos; | 1541 msg = f->pos; |
1542 | 1542 |
1543 if (f->pos + f->length <= f->last) { | 1543 if (f->pos + f->length <= f->last) { |
1544 line.len = f->length; | |
1545 f->pos += f->length; | 1544 f->pos += f->length; |
1546 f->length = 0; | 1545 f->length = 0; |
1547 f->state = ngx_http_fastcgi_st_padding; | 1546 f->state = ngx_http_fastcgi_st_padding; |
1548 | 1547 |
1549 } else { | 1548 } else { |
1550 line.len = f->last - f->pos; | |
1551 f->length -= f->last - f->pos; | 1549 f->length -= f->last - f->pos; |
1552 f->pos = f->last; | 1550 f->pos = f->last; |
1553 } | 1551 } |
1554 | 1552 |
1555 while (line.data[line.len - 1] == LF | 1553 for (m = f->pos - 1; msg < m; m--) { |
1556 || line.data[line.len - 1] == CR | 1554 if (*m != LF && *m != CR && *m != '.' && *m != ' ') { |
1557 || line.data[line.len - 1] == '.' | 1555 break; |
1558 || line.data[line.len - 1] == ' ') | 1556 } |
1559 { | |
1560 line.len--; | |
1561 } | 1557 } |
1562 | 1558 |
1563 ngx_log_error(NGX_LOG_ERR, p->log, 0, | 1559 ngx_log_error(NGX_LOG_ERR, p->log, 0, |
1564 "FastCGI sent in stderr: \"%V\"", &line); | 1560 "FastCGI sent in stderr: \"%*s\"", |
1561 m + 1 - msg, msg); | |
1565 | 1562 |
1566 if (f->pos == f->last) { | 1563 if (f->pos == f->last) { |
1567 break; | 1564 break; |
1568 } | 1565 } |
1569 | 1566 |