[nginx] Proxy: reworked HTTP/0.9 handling.
Maxim Dounin
mdounin at mdounin.ru
Mon Aug 18 00:30:23 UTC 2025
details: http://freenginx.org/hg/nginx/rev/3e14a0ff0d0e
branches:
changeset: 9399:3e14a0ff0d0e
user: Maxim Dounin <mdounin at mdounin.ru>
date: Mon Aug 18 03:18:16 2025 +0300
description:
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.
diffstat:
src/http/modules/ngx_http_proxy_module.c | 28 ++++++++--------------------
1 files changed, 8 insertions(+), 20 deletions(-)
diffs (40 lines):
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