[PATCH 02 of 12] Proxy: reworked HTTP/0.9 handling

Maxim Dounin mdounin at mdounin.ru
Fri Aug 8 20:08:57 UTC 2025


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1754683242 -10800
#      Fri Aug 08 23:00:42 2025 +0300
# Node ID 2bdee8408a2305c96e4a8e6ada355228a1ac62bc
# Parent  3b2af53cea942782c3aed07279a88c2d6ceef7c7
Proxy: reworked HTTP/0.9 handling.

Previous behaviour was to downgrade the client connection to HTTP/0.9
and return the upstream response as is.  However, this approach doesn't
really work with HTTP/2, and will break HTTP/3 as currently implemented
(as it relies on r->http_version).  Further, this approach is potentially
unsafe: if a status line is not recognized as HTTP/1.x by nginx, but
accepted by the client, the response can be recognized as multiple
responses.

Now, instead of downgrading client connection to HTTP/0.9, we generate
a 200 response with the response body received via HTTP/0.9, much like
the memcached module does.

Additionally, now logging is done consistently at the "debug" level,
and special handling for cache is removed.  This resolves various
issues with cache enabled, such as missing status in $upstream_status
and no logging at all.

diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1826,28 +1826,16 @@ ngx_http_proxy_process_status_line(ngx_h
 
     if (rc == NGX_ERROR) {
 
-#if (NGX_HTTP_CACHE)
-
-        if (r->cache) {
-            r->http_version = NGX_HTTP_VERSION_9;
-            return NGX_OK;
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http proxy no HTTP/1.0 header");
+
+        u->headers_in.status_n = 200;
+        u->headers_in.connection_close = 1;
+
+        if (u->state && u->state->status == 0) {
+            u->state->status = NGX_HTTP_OK;
         }
 
-#endif
-
-        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                      "upstream sent no valid HTTP/1.0 header");
-
-#if 0
-        if (u->accel) {
-            return NGX_HTTP_UPSTREAM_INVALID_HEADER;
-        }
-#endif
-
-        r->http_version = NGX_HTTP_VERSION_9;
-        u->state->status = NGX_HTTP_OK;
-        u->headers_in.connection_close = 1;
-
         return NGX_OK;
     }
 



More information about the nginx-devel mailing list