nginx-0.3.33-RELEASE import

    *) Feature: the "http_503" parameter of the "proxy_next_upstream" or
       "fastcgi_next_upstream" directives.

    *) Bugfix: ngx_http_perl_module did not work with inlined in the
       configuration code, if it was not started with the "sub" word.

    *) Bugfix: in the "post_action" directive.
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 715b070..66e221f 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -161,6 +161,7 @@
     { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
     { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
     { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
+    { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
     { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
     { ngx_null_string, 0 }
 };
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 34e6dd1..e8d3107 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -121,6 +121,7 @@
     { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
     { ngx_string("invalid_header"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
     { ngx_string("http_500"), NGX_HTTP_UPSTREAM_FT_HTTP_500 },
+    { ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
     { ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
     { ngx_null_string, 0 }
 };
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
index 0a982e6..0bcad5c 100644
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -692,10 +692,18 @@
 static void
 ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv)
 {
-    if (ngx_strncmp(handler->data, "sub ", 4) == 0
-        || ngx_strncmp(handler->data, "use ", 4) == 0)
+    u_char  *p;
+
+    for (p = handler->data; *p; p++) {
+        if (*p != ' ' && *p != '\t' && *p != CR && *p != LF) {
+            break;
+        }
+    }
+
+    if (ngx_strncmp(p, "sub ", 4) == 0
+        || ngx_strncmp(p, "use ", 4) == 0)
     {
-        *sv = eval_pv((char *) handler->data, FALSE);
+        *sv = eval_pv((char *) p, FALSE);
 
         return;
     }
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 26a1d69..8e9d0b3 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1003,12 +1003,9 @@
 ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
     size_t reserved)
 {
-    u_char                       *last;
-    size_t                        alias, len;
-    ngx_http_script_code_pt       code;
-    ngx_http_script_engine_t      e;
-    ngx_http_core_loc_conf_t     *clcf;
-    ngx_http_script_len_code_pt   lcode;
+    u_char                    *last;
+    size_t                     alias;
+    ngx_http_core_loc_conf_t  *clcf;
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
@@ -1021,11 +1018,13 @@
         return NULL;
     }
 
+    reserved += r->uri.len - alias + 1;
+
     if (clcf->root_lengths == NULL) {
 
         r->root_length = clcf->root.len;
 
-        path->len = clcf->root.len + r->uri.len - alias + 1 + reserved;
+        path->len = clcf->root.len + reserved;
 
         path->data = ngx_palloc(r->pool, path->len);
         if (path->data == NULL) {
@@ -1033,43 +1032,18 @@
         }
 
         last = ngx_copy(path->data, clcf->root.data, clcf->root.len);
-        last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
 
-        return last;
+    } else {
+        last = ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
+                                   clcf->root_values->elts);
+        if (last == NULL) {
+            return NULL;
+        }
+
+        r->root_length = path->len - reserved;
     }
 
-    ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
-
-    e.ip = clcf->root_lengths->elts;
-    e.request = r;
-    e.flushed = 1;
-
-    len = 0;
-
-    while (*(uintptr_t *) e.ip) {
-        lcode = *(ngx_http_script_len_code_pt *) e.ip;
-        len += lcode(&e);
-    }
-
-    r->root_length = len;
-
-    len += r->uri.len - alias + 1 + reserved;
-
-    path->len = len;
-    path->data = ngx_palloc(r->pool, len);
-    if (path->data == NULL) {
-        return NULL;
-    }
-
-    e.ip = clcf->root_values->elts;
-    e.pos = path->data;
-
-    while (*(uintptr_t *) e.ip) {
-        code = *(ngx_http_script_code_pt *) e.ip;
-        code((ngx_http_script_engine_t *) &e);
-    }
-
-    last = ngx_cpystrn(e.pos, r->uri.data + alias, r->uri.len - alias + 1);
+    last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
 
     return last;
 }
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index ba08e59..2ec6979 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -682,6 +682,8 @@
         /* end of header line */
         case sw_almost_done:
             switch (ch) {
+            case CR:
+                break;
             case LF:
                 goto done;
             default:
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 348c84b..870dd8b 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2249,6 +2249,9 @@
         return NGX_DECLINED;
     }
 
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "post action: \"%V\"", &clcf->post_action);
+
     r->http_version = NGX_HTTP_VERSION_9;
     r->header_only = 1;
 
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
index b46c9bb..dc7b895 100644
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -294,6 +294,44 @@
 }
 
 
+u_char *
+ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,
+    void *code_lengths, size_t len, void *code_values)
+{
+    ngx_http_script_code_pt      code;
+    ngx_http_script_len_code_pt  lcode;
+    ngx_http_script_engine_t     e;
+
+    ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
+
+    e.ip = code_lengths;
+    e.request = r;
+    e.flushed = 1;
+
+    while (*(uintptr_t *) e.ip) {
+        lcode = *(ngx_http_script_len_code_pt *) e.ip;
+        len += lcode(&e);
+    }
+
+
+    value->len = len;
+    value->data = ngx_palloc(r->pool, len);
+    if (value->data == NULL) {
+        return NULL;
+    }
+
+    e.ip = code_values;
+    e.pos = value->data;
+
+    while (*(uintptr_t *) e.ip) {
+        code = *(ngx_http_script_code_pt *) e.ip;
+        code((ngx_http_script_engine_t *) &e);
+    }
+
+    return e.pos;
+}
+
+
 void
 ngx_http_script_flush_no_cachable_variables(ngx_http_request_t *r,
     ngx_array_t *indices)
diff --git a/src/http/ngx_http_script.h b/src/http/ngx_http_script.h
index 46e448a..5c53aec 100644
--- a/src/http/ngx_http_script.h
+++ b/src/http/ngx_http_script.h
@@ -152,6 +152,8 @@
 
 ngx_uint_t ngx_http_script_variables_count(ngx_str_t *value);
 ngx_int_t ngx_http_script_compile(ngx_http_script_compile_t *sc);
+u_char *ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,
+    void *code_lengths, size_t reserved, void *code_values);
 void ngx_http_script_flush_no_cachable_variables(ngx_http_request_t *r,
     ngx_array_t *indices);
 
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 7860818..9fd1a1e 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -1947,7 +1947,11 @@
 
     r->connection->log->action = "sending to client";
 
-    if (rc == 0 && r == r->main) {
+    if (rc == 0
+        && r == r->main
+             /* not a post_action */
+        && !(r->http_version == NGX_HTTP_VERSION_9 && r->header_only))
+    {
         rc = ngx_http_send_special(r, NGX_HTTP_LAST);
     }
 
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index a178029..117def1 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -16,13 +16,14 @@
 #include <ngx_http.h>
 
 
-#define NGX_HTTP_UPSTREAM_FT_ERROR           0x02
-#define NGX_HTTP_UPSTREAM_FT_TIMEOUT         0x04
-#define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER  0x08
-#define NGX_HTTP_UPSTREAM_FT_HTTP_500        0x10
-#define NGX_HTTP_UPSTREAM_FT_HTTP_404        0x20
-#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x40
-#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x80
+#define NGX_HTTP_UPSTREAM_FT_ERROR           0x002
+#define NGX_HTTP_UPSTREAM_FT_TIMEOUT         0x004
+#define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER  0x008
+#define NGX_HTTP_UPSTREAM_FT_HTTP_500        0x010
+#define NGX_HTTP_UPSTREAM_FT_HTTP_503        0x020
+#define NGX_HTTP_UPSTREAM_FT_HTTP_404        0x040
+#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK       0x080
+#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING     0x100
 
 
 #define NGX_HTTP_UPSTREAM_INVALID_HEADER     40