Ticket #531: hg-http.patch

File hg-http.patch, 2.0 KB (added by Quanah Gibson-Mount, 12 years ago)

This patch adds the source port to all http(s) error output

  • src/http/ngx_http_request.c

    # 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  
    35483548    u_char              *p;
    35493549    ngx_http_request_t  *r;
    35503550    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
    35513556
    35523557    if (log->action) {
    35533558        p = ngx_snprintf(buf, len, " while %s", log->action);
    … …  
    35573562
    35583563    ctx = log->data;
    35593564
    3560     p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text);
    3561     len -= p - buf;
    3562 
    35633565    r = ctx->request;
    3564 
    35653566    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   
    35663588        return r->log_handler(r, ctx->current_request, p, len);
    3567 
    35683589    } else {
     3590        p = ngx_snprintf(buf, len, ", client: %V", &ctx->connection->addr_text);
    35693591        p = ngx_snprintf(p, len, ", server: %V",
    35703592                         &ctx->connection->listening->addr_text);
    35713593    }