From: Felix Fietkau Date: Fri, 20 Feb 2026 08:36:40 +0000 (+0000) Subject: uclient-http: fix data_eof for body-less responses X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=7a0aa2e4afb4993b7985094aa6847b9fcb04fae8;p=project%2Fuclient.git uclient-http: fix data_eof for body-less responses 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 --- diff --git a/uclient-http.c b/uclient-http.c index ce046c3..2952e36 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -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;