src/http/ngx_http_upstream.c:837: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned64 by call to `ngx_http_upstream_connect`.

src/http/ngx_http_upstream.c:837:5: Call
835.     ngx_resolve_name_done(ctx);
836. 
837.     ngx_http_upstream_connect(r, r->upstream);
         ^
838. }
839. 

src/http/ngx_http_upstream.c:1027:1: Parameter `r->uri.len`
  1025. 
  1026. 
  1027. static void
        ^
  1028. ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
  1029. {

src/http/ngx_http_upstream.c:1158:5: Call
  1156. #endif
  1157. 
  1158.     ngx_http_upstream_send_request(r, u);
            ^
  1159. }
  1160. 

src/http/ngx_http_upstream.c:1297:1: Parameter `r->uri.len`
    1295. 
    1296. 
    1297. static void
          ^
    1298. ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
    1299. {

src/http/ngx_http_upstream.c:1368:9: Call
    1366.          */
    1367. 
    1368.         ngx_http_upstream_process_header(r, u);
                  ^
    1369.         return;
    1370.     }

src/http/ngx_http_upstream.c:1420:1: Parameter `r->uri.len`
      1418. 
      1419. 
      1420. static void
            ^
      1421. ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
      1422. {

src/http/ngx_http_upstream.c:1551:13: Call
      1549.         }
      1550. 
      1551.         if (ngx_http_upstream_test_next(r, u) == NGX_OK) {
                        ^
      1552.             return;
      1553.         }

src/http/ngx_http_upstream.c:1607:1: Parameter `r->uri.len`
        1605. 
        1606. 
        1607. static ngx_int_t
              ^
        1608. ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
        1609. {

src/http/ngx_http_upstream.c:1622:13: Call
        1620. 
        1621.         if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) {
        1622.             ngx_http_upstream_next(r, u, un->mask);
                          ^
        1623.             return NGX_OK;
        1624.         }

src/http/ngx_http_upstream.c:2707:1: Parameter `r->uri.len`
          2705. 
          2706. 
          2707. static void
                ^
          2708. ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
          2709.     ngx_uint_t ft_type)

src/http/ngx_http_upstream.c:2785:26: Call
          2783.                 if (rc == NGX_OK) {
          2784.                     u->cache_status = NGX_HTTP_CACHE_STALE;
          2785.                     rc = ngx_http_upstream_cache_send(r, u);
                                         ^
          2786.                 }
          2787. 

src/http/ngx_http_upstream.c:740:1: Parameter `r->uri.len`
            738. 
            739. 
            740. static ngx_int_t
                 ^
            741. ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u)
            742. {

src/http/ngx_http_upstream.c:767:13: Call
            765.     if (rc == NGX_OK) {
            766. 
            767.         if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {
                             ^
            768.             return NGX_DONE;
            769.         }

src/http/ngx_http_upstream.c:1753:1: Parameter `r->uri.len`
              1751. 
              1752. 
              1753. static ngx_int_t
                    ^
              1754. ngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)
              1755. {

src/http/ngx_http_upstream.c:1768:9: Call
              1766.         && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT))
              1767.     {
              1768.         ngx_http_upstream_finalize_request(r, u, NGX_DECLINED);
                            ^
              1769. 
              1770.         part = &u->headers_in.headers.part;

src/http/ngx_http_upstream.c:2846:1: Parameter `r->uri.len`
                2844. 
                2845. 
                2846. static void
                      ^
                2847. ngx_http_upstream_finalize_request(ngx_http_request_t *r,
                2848.     ngx_http_upstream_t *u, ngx_int_t rc)

src/http/ngx_http_upstream.c:2950:5: Call
                2948.     }
                2949. 
                2950.     ngx_http_finalize_request(r, rc);
                          ^
                2951. }
                2952. 

src/http/ngx_http_request.c:1831:1: Parameter `r->uri.len`
                  1829. 
                  1830. 
                  1831. void
                        ^
                  1832. ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
                  1833. {

src/http/ngx_http_request.c:1904:38: Call
                  1902.         c->write->handler = ngx_http_request_handler;
                  1903. 
                  1904.         ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));
                                                             ^
                  1905.         return;
                  1906.     }

src/http/ngx_http_special_response.c:333:1: Parameter `r->uri.len`
                    331. 
                    332. 
                    333. ngx_int_t
                         ^
                    334. ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
                    335. {

src/http/ngx_http_special_response.c:383:24: Call
                    381.         for (i = 0; i < clcf->error_pages->nelts; i++) {
                    382.             if (err_page[i].status == error) {
                    383.                 return ngx_http_send_error_page(r, &err_page[i]);
                                                ^
                    384.             }
                    385.         }

src/http/ngx_http_special_response.c:504:1: Parameter `r->uri.len`
                      502. 
                      503. 
                      504. static ngx_int_t
                           ^
                      505. ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
                      506. {

src/http/ngx_http_special_response.c:540:16: Call
                      538.         }
                      539. 
                      540.         return ngx_http_internal_redirect(r, &uri, &args);
                                          ^
                      541.     }
                      542. 

src/http/ngx_http_core_module.c:2163:1: Parameter `r->uri.len`
                        2161. 
                        2162. 
                        2163. ngx_int_t
                              ^
                        2164. ngx_http_internal_redirect(ngx_http_request_t *r,
                        2165.     ngx_str_t *uri, ngx_str_t *args)

src/http/ngx_http_core_module.c:2194:5: Call
                        2192.                    "internal redirect: \"%V?%V\"", uri, &r->args);
                        2193. 
                        2194.     ngx_http_set_exten(r);
                                  ^
                        2195. 
                        2196.     /* clear the modules contexts */

src/http/ngx_http_core_module.c:1672:1: <LHS trace>
1670. 
1671. 
1672. void
      ^
1673. ngx_http_set_exten(ngx_http_request_t *r)
1674. {

src/http/ngx_http_core_module.c:1672:1: Parameter `r->uri.len`
                          1670. 
                          1671. 
                          1672. void
                                ^
                          1673. ngx_http_set_exten(ngx_http_request_t *r)
                          1674. {

src/http/ngx_http_core_module.c:1680:10: Binary operation: ([0, +oo] - 1):unsigned64 by call to `ngx_http_upstream_connect` 
                          1678.     r->exten.data = NULL;
                          1679. 
                          1680.     for (i = r->uri.len - 1; i > 1; i--) {
                                         ^
                          1681.         if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
                          1682. 

void
ngx_http_set_exten(ngx_http_request_t *r)
{
    ngx_int_t  i;
    r->exten.len = 0;
    r->exten.data = NULL;
    for (i = r->uri.len - 1; i > 1; i--) {
        if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
            r->exten.len = r->uri.len - i - 1;
            r->exten.data = &r->uri.data[i + 1];
            return;
        } else if (r->uri.data[i] == '/') {
            return;
        }
    }
    return;
}
['static void\nngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)\n{\n    ngx_http_request_t            *r;\n    ngx_http_upstream_resolved_t  *ur;\n    r = ctx->data;\n    r->upstream->resolved->ctx = NULL;\n    if (ctx->state) {\n        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n                      "%V could not be resolved (%i: %s)",\n                      &ctx->name, ctx->state,\n                      ngx_resolver_strerror(ctx->state));\n        ngx_resolve_name_done(ctx);\n        ngx_http_finalize_request(r, NGX_HTTP_BAD_GATEWAY);\n        return;\n    }\n    ur = r->upstream->resolved;\n    ur->naddrs = ctx->naddrs;\n    ur->addrs = ctx->addrs;\n#if (NGX_DEBUG)\n    {\n    in_addr_t   addr;\n    ngx_uint_t  i;\n    for (i = 0; i < ctx->naddrs; i++) {\n        addr = ntohl(ur->addrs[i]);\n        ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "name was resolved to %ud.%ud.%ud.%ud",\n                       (addr >> 24) & 0xff, (addr >> 16) & 0xff,\n                       (addr >> 8) & 0xff, addr & 0xff);\n    }\n    }\n#endif\n    if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) {\n        ngx_resolve_name_done(ctx);\n        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    ngx_resolve_name_done(ctx);\n    ngx_http_upstream_connect(r, r->upstream);\n}', 'static void\nngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ngx_int_t          rc;\n    ngx_time_t        *tp;\n    ngx_connection_t  *c;\n    r->connection->log->action = "connecting to upstream";\n    r->connection->single_connection = 0;\n    if (u->state && u->state->response_sec) {\n        tp = ngx_timeofday();\n        u->state->response_sec = tp->sec - u->state->response_sec;\n        u->state->response_msec = tp->msec - u->state->response_msec;\n    }\n    u->state = ngx_array_push(r->upstream_states);\n    if (u->state == NULL) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));\n    tp = ngx_timeofday();\n    u->state->response_sec = tp->sec;\n    u->state->response_msec = tp->msec;\n    rc = ngx_event_connect_peer(&u->peer);\n    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "http upstream connect: %i", rc);\n    if (rc == NGX_ERROR) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    u->state->peer = u->peer.name;\n    if (rc == NGX_BUSY) {\n        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE);\n        return;\n    }\n    if (rc == NGX_DECLINED) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n        return;\n    }\n    c = u->peer.connection;\n    c->data = r;\n    c->write->handler = ngx_http_upstream_handler;\n    c->read->handler = ngx_http_upstream_handler;\n    u->write_event_handler = ngx_http_upstream_send_request_handler;\n    u->read_event_handler = ngx_http_upstream_process_header;\n    c->sendfile &= r->connection->sendfile;\n    u->output.sendfile = c->sendfile;\n    c->pool = r->pool;\n    c->log = r->connection->log;\n    c->read->log = c->log;\n    c->write->log = c->log;\n    u->writer.out = NULL;\n    u->writer.last = &u->writer.out;\n    u->writer.connection = c;\n    u->writer.limit = 0;\n    if (u->request_sent) {\n        if (ngx_http_upstream_reinit(r, u) != NGX_OK) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n    }\n    if (r->request_body\n        && r->request_body->buf\n        && r->request_body->temp_file\n        && r == r->main)\n    {\n        u->output.free = ngx_alloc_chain_link(r->pool);\n        if (u->output.free == NULL) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n        u->output.free->buf = r->request_body->buf;\n        u->output.free->next = NULL;\n        u->output.allocated = 1;\n        r->request_body->buf->pos = r->request_body->buf->start;\n        r->request_body->buf->last = r->request_body->buf->start;\n        r->request_body->buf->tag = u->output.tag;\n    }\n    u->request_sent = 0;\n    if (rc == NGX_AGAIN) {\n        ngx_add_timer(c->write, u->conf->connect_timeout);\n        return;\n    }\n#if (NGX_HTTP_SSL)\n    if (u->ssl && c->ssl == NULL) {\n        ngx_http_upstream_ssl_init_connection(r, u, c);\n        return;\n    }\n#endif\n    ngx_http_upstream_send_request(r, u);\n}', 'static void\nngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ngx_int_t          rc;\n    ngx_connection_t  *c;\n    c = u->peer.connection;\n    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                   "http upstream send request");\n    if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n        return;\n    }\n    c->log->action = "sending request to upstream";\n    rc = ngx_output_chain(&u->output, u->request_sent ? NULL : u->request_bufs);\n    u->request_sent = 1;\n    if (rc == NGX_ERROR) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n        return;\n    }\n    if (c->write->timer_set) {\n        ngx_del_timer(c->write);\n    }\n    if (rc == NGX_AGAIN) {\n        ngx_add_timer(c->write, u->conf->send_timeout);\n        if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n        return;\n    }\n    if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {\n        if (ngx_tcp_push(c->fd) == NGX_ERROR) {\n            ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,\n                          ngx_tcp_push_n " failed");\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n        c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;\n    }\n    ngx_add_timer(c->read, u->conf->read_timeout);\n#if 1\n    if (c->read->ready) {\n        ngx_http_upstream_process_header(r, u);\n        return;\n    }\n#endif\n    u->write_event_handler = ngx_http_upstream_dummy_handler;\n    if (ngx_handle_write_event(c->write, 0) != NGX_OK) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n}', 'static void\nngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ssize_t            n;\n    ngx_int_t          rc;\n    ngx_connection_t  *c;\n    c = u->peer.connection;\n    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                   "http upstream process header");\n    c->log->action = "reading response header from upstream";\n    if (c->read->timedout) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);\n        return;\n    }\n    if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n        return;\n    }\n    if (u->buffer.start == NULL) {\n        u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);\n        if (u->buffer.start == NULL) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n        u->buffer.pos = u->buffer.start;\n        u->buffer.last = u->buffer.start;\n        u->buffer.end = u->buffer.start + u->conf->buffer_size;\n        u->buffer.temporary = 1;\n        u->buffer.tag = u->output.tag;\n        if (ngx_list_init(&u->headers_in.headers, r->pool, 8,\n                          sizeof(ngx_table_elt_t))\n            != NGX_OK)\n        {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return;\n        }\n#if (NGX_HTTP_CACHE)\n        if (r->cache) {\n            u->buffer.pos += r->cache->header_start;\n            u->buffer.last = u->buffer.pos;\n        }\n#endif\n    }\n    for ( ;; ) {\n        n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);\n        if (n == NGX_AGAIN) {\n#if 0\n            ngx_add_timer(rev, u->read_timeout);\n#endif\n            if (ngx_handle_read_event(c->read, 0) != NGX_OK) {\n                ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n                return;\n            }\n            return;\n        }\n        if (n == 0) {\n            ngx_log_error(NGX_LOG_ERR, c->log, 0,\n                          "upstream prematurely closed connection");\n        }\n        if (n == NGX_ERROR || n == 0) {\n            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n            return;\n        }\n        u->buffer.last += n;\n#if 0\n        u->valid_header_in = 0;\n        u->peer.cached = 0;\n#endif\n        rc = u->process_header(r);\n        if (rc == NGX_AGAIN) {\n            if (u->buffer.pos == u->buffer.end) {\n                ngx_log_error(NGX_LOG_ERR, c->log, 0,\n                              "upstream sent too big header");\n                ngx_http_upstream_next(r, u,\n                                       NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n                return;\n            }\n            continue;\n        }\n        break;\n    }\n    if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n        return;\n    }\n    if (rc == NGX_ERROR) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST) {\n        if (r->subrequest_in_memory) {\n            u->buffer.last = u->buffer.pos;\n        }\n        if (ngx_http_upstream_test_next(r, u) == NGX_OK) {\n            return;\n        }\n        if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) {\n            return;\n        }\n    }\n    if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {\n        return;\n    }\n    if (!r->subrequest_in_memory) {\n        ngx_http_upstream_send_response(r, u);\n        return;\n    }\n    if (u->input_filter == NULL) {\n        u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;\n        u->input_filter = ngx_http_upstream_non_buffered_filter;\n        u->input_filter_ctx = r;\n    }\n    if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return;\n    }\n    n = u->buffer.last - u->buffer.pos;\n    if (n) {\n        u->buffer.last -= n;\n        u->state->response_length += n;\n        if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {\n            ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n            return;\n        }\n        if (u->length == 0) {\n            ngx_http_upstream_finalize_request(r, u, 0);\n            return;\n        }\n    }\n    u->read_event_handler = ngx_http_upstream_process_body_in_memory;\n    ngx_http_upstream_process_body_in_memory(r, u);\n}', 'static ngx_int_t\nngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ngx_uint_t                 status;\n    ngx_http_upstream_next_t  *un;\n    status = u->headers_in.status_n;\n    for (un = ngx_http_upstream_next_errors; un->status; un++) {\n        if (status != un->status) {\n            continue;\n        }\n        if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) {\n            ngx_http_upstream_next(r, u, un->mask);\n            return NGX_OK;\n        }\n#if (NGX_HTTP_CACHE)\n        if (u->cache_status == NGX_HTTP_CACHE_EXPIRED\n            && (u->conf->cache_use_stale & un->mask))\n        {\n            ngx_int_t  rc;\n            rc = u->reinit_request(r);\n            if (rc == NGX_OK) {\n                u->cache_status = NGX_HTTP_CACHE_STALE;\n                rc = ngx_http_upstream_cache_send(r, u);\n            }\n            ngx_http_upstream_finalize_request(r, u, rc);\n            return NGX_OK;\n        }\n#endif\n    }\n    return NGX_DECLINED;\n}', 'static void\nngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,\n    ngx_uint_t ft_type)\n{\n    ngx_uint_t  status, state;\n    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "http next upstream, %xi", ft_type);\n#if 0\n    ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock);\n#endif\n    if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) {\n        state = NGX_PEER_NEXT;\n    } else {\n        state = NGX_PEER_FAILED;\n    }\n    if (ft_type != NGX_HTTP_UPSTREAM_FT_NOLIVE) {\n        u->peer.free(&u->peer, u->peer.data, state);\n    }\n    if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) {\n        ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT,\n                      "upstream timed out");\n    }\n    if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {\n        status = 0;\n    } else {\n        switch(ft_type) {\n        case NGX_HTTP_UPSTREAM_FT_TIMEOUT:\n            status = NGX_HTTP_GATEWAY_TIME_OUT;\n            break;\n        case NGX_HTTP_UPSTREAM_FT_HTTP_500:\n            status = NGX_HTTP_INTERNAL_SERVER_ERROR;\n            break;\n        case NGX_HTTP_UPSTREAM_FT_HTTP_404:\n            status = NGX_HTTP_NOT_FOUND;\n            break;\n        default:\n            status = NGX_HTTP_BAD_GATEWAY;\n        }\n    }\n    if (r->connection->error) {\n        ngx_http_upstream_finalize_request(r, u,\n                                           NGX_HTTP_CLIENT_CLOSED_REQUEST);\n        return;\n    }\n    if (status) {\n        u->state->status = status;\n        if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) {\n#if (NGX_HTTP_CACHE)\n            if (u->cache_status == NGX_HTTP_CACHE_EXPIRED\n                && (u->conf->cache_use_stale & ft_type))\n            {\n                ngx_int_t  rc;\n                rc = u->reinit_request(r);\n                if (rc == NGX_OK) {\n                    u->cache_status = NGX_HTTP_CACHE_STALE;\n                    rc = ngx_http_upstream_cache_send(r, u);\n                }\n                ngx_http_upstream_finalize_request(r, u, rc);\n                return;\n            }\n#endif\n            ngx_http_upstream_finalize_request(r, u, status);\n            return;\n        }\n    }\n    if (u->peer.connection) {\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "close http upstream connection: %d",\n                       u->peer.connection->fd);\n#if (NGX_HTTP_SSL)\n        if (u->peer.connection->ssl) {\n            u->peer.connection->ssl->no_wait_shutdown = 1;\n            u->peer.connection->ssl->no_send_shutdown = 1;\n            (void) ngx_ssl_shutdown(u->peer.connection);\n        }\n#endif\n        ngx_close_connection(u->peer.connection);\n    }\n#if 0\n    if (u->conf->busy_lock && !u->busy_locked) {\n        ngx_http_upstream_busy_lock(p);\n        return;\n    }\n#endif\n    ngx_http_upstream_connect(r, u);\n}', 'static ngx_int_t\nngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ngx_int_t          rc;\n    ngx_http_cache_t  *c;\n    r->cached = 1;\n    c = r->cache;\n    u->buffer = *c->buf;\n    u->buffer.pos += c->header_start;\n    ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));\n    if (ngx_list_init(&u->headers_in.headers, r->pool, 8,\n                      sizeof(ngx_table_elt_t))\n        != NGX_OK)\n    {\n        return NGX_ERROR;\n    }\n    rc = u->process_header(r);\n    if (rc == NGX_OK) {\n        if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {\n            return NGX_DONE;\n        }\n        return ngx_http_cache_send(r);\n    }\n    if (rc == NGX_ERROR) {\n        return NGX_ERROR;\n    }\n    return rc;\n}', 'static ngx_int_t\nngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    ngx_str_t                      *uri, args;\n    ngx_uint_t                      i, flags;\n    ngx_list_part_t                *part;\n    ngx_table_elt_t                *h;\n    ngx_http_upstream_header_t     *hh;\n    ngx_http_upstream_main_conf_t  *umcf;\n    umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n    if (u->headers_in.x_accel_redirect\n        && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT))\n    {\n        ngx_http_upstream_finalize_request(r, u, NGX_DECLINED);\n        part = &u->headers_in.headers.part;\n        h = part->elts;\n        for (i = 0;  ; i++) {\n            if (i >= part->nelts) {\n                if (part->next == NULL) {\n                    break;\n                }\n                part = part->next;\n                h = part->elts;\n                i = 0;\n            }\n            hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,\n                               h[i].lowcase_key, h[i].key.len);\n            if (hh && hh->redirect) {\n                if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {\n                    ngx_http_finalize_request(r,\n                                              NGX_HTTP_INTERNAL_SERVER_ERROR);\n                    return NGX_DONE;\n                }\n            }\n        }\n        uri = &u->headers_in.x_accel_redirect->value;\n        args.len = 0;\n        args.data = NULL;\n        flags = 0;\n        if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) {\n            ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);\n            return NGX_DONE;\n        }\n        if (flags & NGX_HTTP_ZERO_IN_URI) {\n            r->zero_in_uri = 1;\n        }\n        if (r->method != NGX_HTTP_HEAD) {\n            r->method = NGX_HTTP_GET;\n        }\n        r->valid_unparsed_uri = 0;\n        ngx_http_internal_redirect(r, uri, &args);\n        ngx_http_finalize_request(r, NGX_DONE);\n        return NGX_DONE;\n    }\n    part = &u->headers_in.headers.part;\n    h = part->elts;\n    for (i = 0;  ; i++) {\n        if (i >= part->nelts) {\n            if (part->next == NULL) {\n                break;\n            }\n            part = part->next;\n            h = part->elts;\n            i = 0;\n        }\n        if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,\n                          h[i].lowcase_key, h[i].key.len))\n        {\n            continue;\n        }\n        hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,\n                           h[i].lowcase_key, h[i].key.len);\n        if (hh) {\n            if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {\n                ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n                return NGX_DONE;\n            }\n            continue;\n        }\n        if (ngx_http_upstream_copy_header_line(r, &h[i], 0) != NGX_OK) {\n            ngx_http_upstream_finalize_request(r, u,\n                                               NGX_HTTP_INTERNAL_SERVER_ERROR);\n            return NGX_DONE;\n        }\n    }\n    if (r->headers_out.server && r->headers_out.server->value.data == NULL) {\n        r->headers_out.server->hash = 0;\n    }\n    if (r->headers_out.date && r->headers_out.date->value.data == NULL) {\n        r->headers_out.date->hash = 0;\n    }\n    r->headers_out.status = u->headers_in.status_n;\n    r->headers_out.status_line = u->headers_in.status_line;\n    u->headers_in.content_length_n = r->headers_out.content_length_n;\n    if (r->headers_out.content_length_n != -1) {\n        u->length = (size_t) r->headers_out.content_length_n;\n    } else {\n        u->length = NGX_MAX_SIZE_T_VALUE;\n    }\n    return NGX_OK;\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n    ngx_http_upstream_t *u, ngx_int_t rc)\n{\n    ngx_time_t  *tp;\n    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "finalize http upstream request: %i", rc);\n    if (u->cleanup) {\n        *u->cleanup = NULL;\n    }\n    if (u->state && u->state->response_sec) {\n        tp = ngx_timeofday();\n        u->state->response_sec = tp->sec - u->state->response_sec;\n        u->state->response_msec = tp->msec - u->state->response_msec;\n        if (u->pipe) {\n            u->state->response_length = u->pipe->read_length;\n        }\n    }\n    u->finalize_request(r, rc);\n    if (u->peer.free) {\n        u->peer.free(&u->peer, u->peer.data, 0);\n    }\n    if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n        if (u->peer.connection->ssl) {\n            u->peer.connection->ssl->no_wait_shutdown = 1;\n            (void) ngx_ssl_shutdown(u->peer.connection);\n        }\n#endif\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "close http upstream connection: %d",\n                       u->peer.connection->fd);\n        ngx_close_connection(u->peer.connection);\n    }\n    u->peer.connection = NULL;\n    if (u->pipe && u->pipe->temp_file) {\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "http upstream temp fd: %d",\n                       u->pipe->temp_file->file.fd);\n    }\n#if (NGX_HTTP_CACHE)\n    if (u->cacheable && r->cache) {\n        time_t  valid;\n        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                       "http upstream cache fd: %d",\n                       r->cache->file.fd);\n        if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n            valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n            if (valid) {\n                r->cache->valid_sec = ngx_time() + valid;\n                r->cache->error = rc;\n            }\n        }\n        ngx_http_file_cache_free(r, u->pipe->temp_file);\n    }\n#endif\n    if (u->header_sent\n        && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))\n    {\n        rc = 0;\n    }\n    if (rc == NGX_DECLINED) {\n        return;\n    }\n    r->connection->log->action = "sending to client";\n    if (rc == 0) {\n        rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n    }\n    ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n    ngx_connection_t          *c;\n    ngx_http_request_t        *pr;\n    ngx_http_core_loc_conf_t  *clcf;\n    c = r->connection;\n    ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                   "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n                   rc, &r->uri, &r->args, r == c->data, r->main->count);\n    if (rc == NGX_DONE) {\n        ngx_http_finalize_connection(r);\n        return;\n    }\n    if (rc == NGX_OK && r->filter_finalize) {\n        c->error = 1;\n        return;\n    }\n    if (rc == NGX_DECLINED) {\n        r->content_handler = NULL;\n        r->write_event_handler = ngx_http_core_run_phases;\n        ngx_http_core_run_phases(r);\n        return;\n    }\n    if (r != r->main && r->post_subrequest) {\n        rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n    }\n    if (rc == NGX_ERROR\n        || rc == NGX_HTTP_REQUEST_TIME_OUT\n        || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n        || c->error)\n    {\n        if (ngx_http_post_action(r) == NGX_OK) {\n            return;\n        }\n        if (r->main->blocked) {\n            r->write_event_handler = ngx_http_request_finalizer;\n        }\n        ngx_http_terminate_request(r, rc);\n        return;\n    }\n    if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n        || rc == NGX_HTTP_CREATED\n        || rc == NGX_HTTP_NO_CONTENT)\n    {\n        if (rc == NGX_HTTP_CLOSE) {\n            ngx_http_terminate_request(r, rc);\n            return;\n        }\n        if (r == r->main) {\n            if (c->read->timer_set) {\n                ngx_del_timer(c->read);\n            }\n            if (c->write->timer_set) {\n                ngx_del_timer(c->write);\n            }\n        }\n        c->read->handler = ngx_http_request_handler;\n        c->write->handler = ngx_http_request_handler;\n        ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n        return;\n    }\n    if (r != r->main) {\n        if (r->buffered || r->postponed) {\n            if (ngx_http_set_write_handler(r) != NGX_OK) {\n                ngx_http_terminate_request(r, 0);\n            }\n            return;\n        }\n#if (NGX_DEBUG)\n        if (r != c->data) {\n            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                           "http finalize non-active request: \\"%V?%V\\"",\n                           &r->uri, &r->args);\n        }\n#endif\n        pr = r->parent;\n        if (r == c->data) {\n            r->main->count--;\n            if (!r->logged) {\n                clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n                if (clcf->log_subrequest) {\n                    ngx_http_log_request(r);\n                }\n                r->logged = 1;\n            } else {\n                ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n                              "subrequest: \\"%V?%V\\" logged again",\n                              &r->uri, &r->args);\n            }\n            r->done = 1;\n            if (pr->postponed && pr->postponed->request == r) {\n                pr->postponed = pr->postponed->next;\n            }\n            c->data = pr;\n        } else {\n            r->write_event_handler = ngx_http_request_finalizer;\n            if (r->waited) {\n                r->done = 1;\n            }\n        }\n        if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n            r->main->count++;\n            ngx_http_terminate_request(r, 0);\n            return;\n        }\n        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n                       "http wake parent request: \\"%V?%V\\"",\n                       &pr->uri, &pr->args);\n        return;\n    }\n    if (r->buffered || c->buffered || r->postponed || r->blocked) {\n        if (ngx_http_set_write_handler(r) != NGX_OK) {\n            ngx_http_terminate_request(r, 0);\n        }\n        return;\n    }\n    if (r != c->data) {\n        ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n                      "http finalize non-active request: \\"%V?%V\\"",\n                      &r->uri, &r->args);\n        return;\n    }\n    r->done = 1;\n    if (!r->post_action) {\n        r->request_complete = 1;\n    }\n    if (ngx_http_post_action(r) == NGX_OK) {\n        return;\n    }\n    if (c->read->timer_set) {\n        ngx_del_timer(c->read);\n    }\n    if (c->write->timer_set) {\n        c->write->delayed = 0;\n        ngx_del_timer(c->write);\n    }\n    if (c->read->eof) {\n        ngx_http_close_request(r, 0);\n        return;\n    }\n    ngx_http_finalize_connection(r);\n}', 'ngx_int_t\nngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)\n{\n    ngx_uint_t                 i, err;\n    ngx_http_err_page_t       *err_page;\n    ngx_http_core_loc_conf_t  *clcf;\n    ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "http special response: %d, \\"%V?%V\\"",\n                   error, &r->uri, &r->args);\n    r->err_status = error;\n    if (r->keepalive) {\n        switch (error) {\n            case NGX_HTTP_BAD_REQUEST:\n            case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:\n            case NGX_HTTP_REQUEST_URI_TOO_LARGE:\n            case NGX_HTTP_TO_HTTPS:\n            case NGX_HTTPS_CERT_ERROR:\n            case NGX_HTTPS_NO_CERT:\n            case NGX_HTTP_INTERNAL_SERVER_ERROR:\n                r->keepalive = 0;\n        }\n    }\n    if (r->lingering_close == 1) {\n        switch (error) {\n            case NGX_HTTP_BAD_REQUEST:\n            case NGX_HTTP_TO_HTTPS:\n            case NGX_HTTPS_CERT_ERROR:\n            case NGX_HTTPS_NO_CERT:\n                r->lingering_close = 0;\n        }\n    }\n    r->headers_out.content_type.len = 0;\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {\n        if (clcf->recursive_error_pages == 0) {\n            r->error_page = 1;\n        }\n        err_page = clcf->error_pages->elts;\n        for (i = 0; i < clcf->error_pages->nelts; i++) {\n            if (err_page[i].status == error) {\n                return ngx_http_send_error_page(r, &err_page[i]);\n            }\n        }\n    }\n    r->expect_tested = 1;\n    if (ngx_http_discard_request_body(r) != NGX_OK) {\n        error = NGX_HTTP_INTERNAL_SERVER_ERROR;\n    }\n    if (clcf->msie_refresh\n        && r->headers_in.msie\n        && (error == NGX_HTTP_MOVED_PERMANENTLY\n            || error == NGX_HTTP_MOVED_TEMPORARILY))\n    {\n        return ngx_http_send_refresh(r);\n    }\n    if (error == NGX_HTTP_CREATED) {\n        err = 0;\n        r->header_only = 1;\n    } else if (error == NGX_HTTP_NO_CONTENT) {\n        err = 0;\n    } else if (error >= NGX_HTTP_MOVED_PERMANENTLY\n               && error < NGX_HTTP_LAST_LEVEL_300)\n    {\n        err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_LEVEL_200;\n    } else if (error >= NGX_HTTP_BAD_REQUEST\n               && error < NGX_HTTP_LAST_LEVEL_400)\n    {\n        err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_LEVEL_200\n                                           + NGX_HTTP_LEVEL_300;\n    } else if (error >= NGX_HTTP_OWN_CODES\n               && error < NGX_HTTP_LAST_LEVEL_500)\n    {\n        err = error - NGX_HTTP_OWN_CODES + NGX_HTTP_LEVEL_200\n                                         + NGX_HTTP_LEVEL_300\n                                         + NGX_HTTP_LEVEL_400;\n        switch (error) {\n            case NGX_HTTP_TO_HTTPS:\n            case NGX_HTTPS_CERT_ERROR:\n            case NGX_HTTPS_NO_CERT:\n                r->err_status = NGX_HTTP_BAD_REQUEST;\n                break;\n        }\n    } else {\n        err = 0;\n    }\n    return ngx_http_send_special_response(r, clcf, err);\n}', 'static ngx_int_t\nngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)\n{\n    ngx_int_t                  overwrite;\n    ngx_str_t                  uri, args;\n    ngx_table_elt_t           *location;\n    ngx_http_core_loc_conf_t  *clcf;\n    overwrite = err_page->overwrite;\n    if (overwrite && overwrite != NGX_HTTP_OK) {\n        r->expect_tested = 1;\n    }\n    r->err_status = overwrite;\n    r->zero_in_uri = 0;\n    if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {\n        return NGX_ERROR;\n    }\n    if (uri.data[0] == \'/\') {\n        if (err_page->value.lengths) {\n            ngx_http_split_args(r, &uri, &args);\n        } else {\n            args = err_page->args;\n        }\n        if (r->method != NGX_HTTP_HEAD) {\n            r->method = NGX_HTTP_GET;\n            r->method_name = ngx_http_get_name;\n        }\n        return ngx_http_internal_redirect(r, &uri, &args);\n    }\n    if (uri.data[0] == \'@\') {\n        return ngx_http_named_location(r, &uri);\n    }\n    location = ngx_list_push(&r->headers_out.headers);\n    if (location == NULL) {\n        return NGX_ERROR;\n    }\n    r->err_status = NGX_HTTP_MOVED_TEMPORARILY;\n    location->hash = 1;\n    location->key.len = sizeof("Location") - 1;\n    location->key.data = (u_char *) "Location";\n    location->value = uri;\n    r->headers_out.location = location;\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    if (clcf->msie_refresh && r->headers_in.msie) {\n        return ngx_http_send_refresh(r);\n    }\n    return ngx_http_send_special_response(r, clcf, NGX_HTTP_MOVED_TEMPORARILY\n                                                   - NGX_HTTP_MOVED_PERMANENTLY\n                                                   + NGX_HTTP_LEVEL_200);\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n    ngx_str_t *uri, ngx_str_t *args)\n{\n    ngx_http_core_srv_conf_t  *cscf;\n    r->uri_changes--;\n    if (r->uri_changes == 0) {\n        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n                      "rewrite or internal redirection cycle "\n                      "while internal redirect to \\"%V\\"", uri);\n        r->main->count++;\n        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n        return NGX_DONE;\n    }\n    r->uri = *uri;\n    if (args) {\n        r->args = *args;\n    } else {\n        r->args.len = 0;\n        r->args.data = NULL;\n    }\n    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "internal redirect: \\"%V?%V\\"", uri, &r->args);\n    ngx_http_set_exten(r);\n    ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n    cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n    r->loc_conf = cscf->ctx->loc_conf;\n    ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n    r->cache = NULL;\n#endif\n    r->internal = 1;\n    r->main->count++;\n    ngx_http_handler(r);\n    return NGX_DONE;\n}', "void\nngx_http_set_exten(ngx_http_request_t *r)\n{\n    ngx_int_t  i;\n    r->exten.len = 0;\n    r->exten.data = NULL;\n    for (i = r->uri.len - 1; i > 1; i--) {\n        if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {\n            r->exten.len = r->uri.len - i - 1;\n            r->exten.data = &r->uri.data[i + 1];\n            return;\n        } else if (r->uri.data[i] == '/') {\n            return;\n        }\n    }\n    return;\n}"]