diff src/http/modules/proxy/ngx_http_proxy_upstream.c @ 50:72eb30262aac NGINX_0_1_25

nginx 0.1.25 *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <http://sysoev.ru>
date Sat, 19 Mar 2005 00:00:00 +0300
parents 6cfc63e68377
children bcb5fce0b038
line wrap: on
line diff
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -58,7 +58,8 @@ int ngx_http_proxy_request_upstream(ngx_
 
     r = p->request;
 
-    if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t)))) {
+    u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t));
+    if (u == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -85,7 +86,7 @@ int ngx_http_proxy_request_upstream(ngx_
 
 static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
 {
-    size_t                           len;
+    size_t                           len, loc_len;
     ngx_uint_t                       i, escape, *index;
     ngx_buf_t                       *b;
     ngx_chain_t                     *chain;
@@ -94,6 +95,7 @@ static ngx_chain_t *ngx_http_proxy_creat
     ngx_http_request_t              *r;
     ngx_http_variable_t             *var;
     ngx_http_variable_value_t       *value;
+    ngx_http_core_loc_conf_t        *clcf;
     ngx_http_core_main_conf_t       *cmcf;
     ngx_http_proxy_upstream_conf_t  *uc;
 
@@ -112,16 +114,23 @@ static ngx_chain_t *ngx_http_proxy_creat
         len = r->method_name.len;
     }
 
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+#if (NGX_PCRE)
+    loc_len = (clcf->regex) ? 1 : clcf->name.len;
+#else
+    loc_len = clcf->name.len;
+#endif
+
     if (r->quoted_uri) {
-        escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
-                                    r->uri.len - uc->location->len,
-                                    NGX_ESCAPE_URI);
+        escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len,
+                                    r->uri.len - loc_len, NGX_ESCAPE_URI);
     } else {
         escape = 0;
     }
 
     len += uc->uri.len
-        + r->uri.len - uc->location->len + escape
+        + r->uri.len - loc_len + escape
         + sizeof("?") - 1 + r->args.len
         + sizeof(http_version) - 1
         + sizeof(connection_close_header) - 1
@@ -190,7 +199,8 @@ static ngx_chain_t *ngx_http_proxy_creat
 
         for (i = 0; i < p->lcf->x_vars->nelts; i++) {
 
-            if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
+            value = ngx_http_get_indexed_variable(r, index[i]);
+            if (value == NULL) {
                 continue;
             }
 
@@ -233,11 +243,13 @@ static ngx_chain_t *ngx_http_proxy_creat
     len++;
 #endif
 
-    if (!(b = ngx_create_temp_buf(r->pool, len))) {
+    b = ngx_create_temp_buf(r->pool, len);
+    if (b == NULL) {
         return NULL;
     }
 
-    if (!(chain = ngx_alloc_chain_link(r->pool))) {
+    chain = ngx_alloc_chain_link(r->pool);
+    if (chain == NULL) {
         return NULL;
     }
 
@@ -258,14 +270,13 @@ static ngx_chain_t *ngx_http_proxy_creat
     b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len);
 
     if (escape) {
-        ngx_escape_uri(b->last, r->uri.data + uc->location->len,
-                       r->uri.len - uc->location->len, NGX_ESCAPE_URI);
-        b->last += r->uri.len - uc->location->len + escape;
+        ngx_escape_uri(b->last, r->uri.data + loc_len,
+                       r->uri.len - loc_len, NGX_ESCAPE_URI);
+        b->last += r->uri.len - loc_len + escape;
 
     } else {
-        b->last = ngx_cpymem(b->last,
-                             r->uri.data + uc->location->len,
-                             r->uri.len - uc->location->len);
+        b->last = ngx_cpymem(b->last, r->uri.data + loc_len,
+                             r->uri.len - loc_len);
     }
 
     if (r->args.len > 0) {
@@ -379,7 +390,8 @@ static ngx_chain_t *ngx_http_proxy_creat
     if (p->lcf->x_vars) {
         for (i = 0; i < p->lcf->x_vars->nelts; i++) {
 
-            if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
+            value = ngx_http_get_indexed_variable(r, index[i]);
+            if (value == NULL) {
                 continue;
             }
 
@@ -506,7 +518,8 @@ static void ngx_http_proxy_init_upstream
     }
 
 
-    if (!(cl = ngx_http_proxy_create_request(p))) {
+    cl = ngx_http_proxy_create_request(p);
+    if (cl == NULL) {
         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -517,7 +530,8 @@ static void ngx_http_proxy_init_upstream
 
     r->request_body->bufs = cl;
 
-    if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) {
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t));
+    if (ctx == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -531,7 +545,8 @@ static void ngx_http_proxy_init_upstream
     r->connection->log->handler = ngx_http_proxy_log_error;
     p->action = "connecting to upstream";
 
-    if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) {
+    output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+    if (output == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -544,7 +559,8 @@ static void ngx_http_proxy_init_upstream
     output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
     output->output_filter = ngx_chain_writer;
 
-    if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
+    writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t));
+    if (writer == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -603,7 +619,8 @@ static void ngx_http_proxy_reinit_upstre
 
     state = p->state->cache_state;
 
-    if (!(p->state = ngx_push_array(&p->states))) {
+    p->state = ngx_array_push(&p->states);
+    if (p->state == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -775,7 +792,8 @@ static void ngx_http_proxy_connect(ngx_h
     if (r->request_body->buf) {
         if (r->request_body->temp_file) {
 
-            if (!(output->free = ngx_alloc_chain_link(r->pool))) {
+            output->free = ngx_alloc_chain_link(r->pool);
+            if (output->free == NULL) {
                 ngx_http_proxy_finalize_request(p,
                                                 NGX_HTTP_INTERNAL_SERVER_ERROR);
                 return;
@@ -1005,7 +1023,7 @@ static void ngx_http_proxy_process_upstr
     rc = ngx_http_proxy_parse_status_line(p);
 
     if (rc == NGX_AGAIN) {
-        if (p->header_in->pos == p->header_in->last) {
+        if (p->header_in->pos == p->header_in->end) {
             ngx_log_error(NGX_LOG_ERR, rev->log, 0,
                           "upstream sent too long status line");
             ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_INVALID_HEADER);
@@ -1158,7 +1176,8 @@ static void ngx_http_proxy_process_upstr
 
             /* a header line has been parsed successfully */
 
-            if (!(h = ngx_list_push(&p->upstream->headers_in.headers))) {
+            h = ngx_list_push(&p->upstream->headers_in.headers);
+            if (h == NULL) {
                 ngx_http_proxy_finalize_request(p,
                                                 NGX_HTTP_INTERNAL_SERVER_ERROR);
                 return;
@@ -1315,6 +1334,11 @@ static void ngx_http_proxy_send_response
 
     rc = ngx_http_send_header(r);
 
+    if (rc == NGX_ERROR || rc > NGX_OK) {
+        ngx_http_proxy_finalize_request(p, rc);
+        return;
+    }
+
     p->header_sent = 1;
 
     if (p->cache && p->cache->ctx.file.fd != NGX_INVALID_FILE) {
@@ -1361,7 +1385,8 @@ static void ngx_http_proxy_send_response
 
     ep->cachable = p->cachable;
 
-    if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+    ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+    if (ep->temp_file == NULL) {
         ngx_http_proxy_finalize_request(p, 0);
         return;
     }
@@ -1381,7 +1406,8 @@ static void ngx_http_proxy_send_response
     ep->max_temp_file_size = p->lcf->max_temp_file_size;
     ep->temp_file_write_size = p->lcf->temp_file_write_size;
 
-    if (!(ep->preread_bufs = ngx_alloc_chain_link(r->pool))) {
+    ep->preread_bufs = ngx_alloc_chain_link(r->pool);
+    if (ep->preread_bufs == NULL) {
         ngx_http_proxy_finalize_request(p, 0);
         return;
     }
@@ -1467,7 +1493,6 @@ static void ngx_http_proxy_process_body(
         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
                        "http proxy process upstream");
         p = c->data;
-        r = p->request;
         p->action = "reading upstream body";
     }