summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2026-02-20 08:36:40 +0000
committerFelix Fietkau2026-02-20 09:02:16 +0000
commit7a0aa2e4afb4993b7985094aa6847b9fcb04fae8 (patch)
tree2f89c0f157632e15e764e813040deb7400415766
parenta1531e89f6c22f92a2ac52b0408a7f5c755a09f2 (diff)
downloaduclient-master.tar.gz
uclient-http: fix data_eof for body-less responsesHEADmaster
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>
-rw-r--r--uclient-http.c15
1 files changed, 11 insertions, 4 deletions
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;