allowing handling 400 errors via proxy_pass
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 8788dee..fc24d90 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -514,12 +514,7 @@
         } else {
             r->lingering_close = 0;
         }
-    }
 
-    r->valid_unparsed_uri = 1;
-    r->valid_location = 1;
-
-    if (!r->internal) {
         r->phase_handler = 0;
 
     } else {
@@ -527,6 +522,12 @@
         r->phase_handler = cmcf->phase_engine.server_rewrite_index;
     }
 
+    if (r->unparsed_uri.len) {
+        r->valid_unparsed_uri = 1;
+    }
+
+    r->valid_location = 1;
+
     r->write_event_handler = ngx_http_core_run_phases;
     ngx_http_core_run_phases(r);
 }