uclient-http: fix data_eof for body-less responses master
authorFelix Fietkau <nbd@nbd.name>
Fri, 20 Feb 2026 08:36:40 +0000 (08:36 +0000)
committerFelix Fietkau <nbd@nbd.name>
Fri, 20 Feb 2026 09:02:16 +0000 (09:02 +0000)
HEAD, 204 and 304 responses have no body by definition. When the
server includes a Content-Length header (indicating the resource
size, not the response body size), uclient_notify_eof() failed to
set data_eof, causing a spurious "Connection reset prematurely"
error.

Fixes: https://github.com/openwrt/uclient/issues/15
Signed-off-by: Felix Fietkau <nbd@nbd.name>
uclient-http.c

index ce046c34101a1cbddedccd43ae9bf74c64b5e310..2952e36c04b44a810483eb612aaa3e1309c6db63 100644 (file)
@@ -209,6 +209,13 @@ static void uclient_http_request_disconnect(struct uclient *cl)
        uloop_timeout_set(&uh->disconnect_t, 1);
 }
 
+static bool uclient_http_bodyless_response(struct uclient_http *uh)
+{
+       return uh->req_type == REQ_HEAD ||
+              uh->uc.status_code == 204 ||
+              uh->uc.status_code == 304;
+}
+
 static void uclient_notify_eof(struct uclient_http *uh)
 {
        struct ustream *us = uh->us;
@@ -224,8 +231,9 @@ static void uclient_notify_eof(struct uclient_http *uh)
                        return;
        }
 
-       if ((uh->content_length < 0 && uh->read_chunked >= 0) ||
-                       uh->content_length == 0)
+       if (uclient_http_bodyless_response(uh) ||
+           (uh->content_length < 0 && uh->read_chunked >= 0) ||
+           uh->content_length == 0)
                uh->uc.data_eof = true;
 
        uclient_backend_set_eof(&uh->uc);
@@ -685,8 +693,7 @@ static void uclient_http_process_headers_cb(struct uloop_timeout *timeout)
        if (uh->eof || seq != uh->seq)
                return;
 
-       if (uh->req_type == REQ_HEAD || uh->uc.status_code == 204 ||
-                       uh->content_length == 0) {
+       if (uclient_http_bodyless_response(uh) || uh->content_length == 0) {
                uh->eof = true;
                uclient_notify_eof(uh);
                return;