From 39d7d0ba0799fcff6baee52b6525f45739593cfd Mon Sep 17 00:00:00 2001
From: Sergey Kandaurov <pluknet@nginx.com>
Date: Wed, 29 Apr 2026 23:02:20 +0400
Subject: [PATCH] Upstream: fixed parsing of split status lines

If the first response line was split across reads and it didn't appear
a status line, the portion already processed was lost.  To preserve ABI,
the change reuses r->header_name_start for proper backtracking on status
line fallback.
---
 src/http/modules/ngx_http_proxy_module.c | 5 +++++
 src/http/modules/ngx_http_scgi_module.c  | 5 +++++
 src/http/modules/ngx_http_uwsgi_module.c | 5 +++++
 3 files changed, 15 insertions(+)

--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1728,6 +1728,10 @@ ngx_http_proxy_process_status_line(ngx_h
 
     u = r->upstream;
 
+    if (r->state == 0) {
+        r->header_name_start = u->buffer.pos;
+    }
+
     rc = ngx_http_parse_status_line(r, &u->buffer, &ctx->status);
 
     if (rc == NGX_AGAIN) {
@@ -1735,6 +1739,7 @@ ngx_http_proxy_process_status_line(ngx_h
     }
 
     if (rc == NGX_ERROR) {
+        u->buffer.pos = r->header_name_start;
 
 #if (NGX_HTTP_CACHE)
 
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -976,6 +976,10 @@ ngx_http_scgi_process_status_line(ngx_ht
 
     u = r->upstream;
 
+    if (r->state == 0) {
+        r->header_name_start = u->buffer.pos;
+    }
+
     rc = ngx_http_parse_status_line(r, &u->buffer, status);
 
     if (rc == NGX_AGAIN) {
@@ -984,6 +988,7 @@ ngx_http_scgi_process_status_line(ngx_ht
 
     if (rc == NGX_ERROR) {
         u->process_header = ngx_http_scgi_process_header;
+        u->buffer.pos = r->header_name_start;
         r->state = 0;
         return ngx_http_scgi_process_header(r);
     }
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -1186,6 +1186,10 @@ ngx_http_uwsgi_process_status_line(ngx_h
 
     u = r->upstream;
 
+    if (r->state == 0) {
+        r->header_name_start = u->buffer.pos;
+    }
+
     rc = ngx_http_parse_status_line(r, &u->buffer, status);
 
     if (rc == NGX_AGAIN) {
@@ -1194,6 +1198,7 @@ ngx_http_uwsgi_process_status_line(ngx_h
 
     if (rc == NGX_ERROR) {
         u->process_header = ngx_http_uwsgi_process_header;
+        u->buffer.pos = r->header_name_start;
         r->state = 0;
         return ngx_http_uwsgi_process_header(r);
     }
