# HG changeset patch
# User Quanah Gibson-Mount <quanah@zimbra.com>
# Date 1398357557 18000
# Node ID 4b7d2e503c06758330aabcc21ffbbab77f09568e
# Parent 1b0c55d38d0b7ba69dcad79760a3fadc30696a9d
HTTP: Add client source port to any error that is logged
For TRAC ticket 531
diff -r 1b0c55d38d0b -r 4b7d2e503c06 src/http/ngx_http_request.c
|
a
|
b
|
|
| 3548 | 3548 | u_char *p; |
| 3549 | 3549 | ngx_http_request_t *r; |
| 3550 | 3550 | ngx_http_log_ctx_t *ctx; |
| | 3551 | ngx_uint_t remote_port=0; |
| | 3552 | struct sockaddr_in *sin; |
| | 3553 | #if (NGX_HAVE_INET6) |
| | 3554 | struct sockaddr_in6 *sin6; |
| | 3555 | #endif |
| 3551 | 3556 | |
| 3552 | 3557 | if (log->action) { |
| 3553 | 3558 | p = ngx_snprintf(buf, len, " while %s", log->action); |
| … |
… |
|
| 3557 | 3562 | |
| 3558 | 3563 | ctx = log->data; |
| 3559 | 3564 | |
| 3560 | | p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text); |
| 3561 | | len -= p - buf; |
| 3562 | | |
| 3563 | 3565 | r = ctx->request; |
| 3564 | | |
| 3565 | 3566 | if (r) { |
| | 3567 | switch (r->connection->sockaddr->sa_family) { |
| | 3568 | #if (NGX_HAVE_INET6) |
| | 3569 | case AF_INET6: |
| | 3570 | sin6 = (struct sockaddr_in6 *) r->connection->sockaddr; |
| | 3571 | remote_port = ntohs(sin6->sin6_port); |
| | 3572 | break; |
| | 3573 | #endif |
| | 3574 | |
| | 3575 | default: /* AF_INET */ |
| | 3576 | sin = (struct sockaddr_in *) r->connection->sockaddr; |
| | 3577 | remote_port = ntohs(sin->sin_port); |
| | 3578 | break; |
| | 3579 | } |
| | 3580 | |
| | 3581 | if (remote_port && remote_port < 65536) { |
| | 3582 | p = ngx_snprintf(buf, len, ", client: %V:%ui", &ctx->connection->addr_text,remote_port); |
| | 3583 | } else { |
| | 3584 | p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text); |
| | 3585 | } |
| | 3586 | len -= p - buf; |
| | 3587 | |
| 3566 | 3588 | return r->log_handler(r, ctx->current_request, p, len); |
| 3567 | | |
| 3568 | 3589 | } else { |
| | 3590 | p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text); |
| 3569 | 3591 | p = ngx_snprintf(p, len, ", server: %V", |
| 3570 | 3592 | &ctx->connection->listening->addr_text); |
| 3571 | 3593 | } |