uclient-http: fix HTTP authentication after deferred header processing
authorFelix Fietkau <nbd@nbd.name>
Fri, 13 Feb 2026 07:30:42 +0000 (07:30 +0000)
committerFelix Fietkau <nbd@nbd.name>
Fri, 13 Feb 2026 07:30:42 +0000 (07:30 +0000)
Move uclient_http_process_headers() into the deferred callback so that
auth_type is captured before it gets updated. The previous refactor in
commit 80c9bd29c233 ("uclient-http: fix hang on HTTP to HTTPS redirect")
moved the auth_type snapshot after uclient_http_process_headers() had
already changed it from AUTH_TYPE_UNKNOWN, causing the 401 retry path
to never trigger.

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

index fce62bb06815b53165dc7adc988d387b99f49b66..5e46e7087337a12047336c991a9b6d226be442dd 100644 (file)
@@ -647,6 +647,8 @@ static void uclient_http_process_headers_cb(struct uloop_timeout *timeout)
        enum auth_type auth_type = uh->auth_type;
        unsigned int seq = uh->seq;
 
+       uclient_http_process_headers(uh);
+
        if (auth_type == AUTH_TYPE_UNKNOWN && uh->uc.status_code == 401 &&
            (uh->req_type == REQ_HEAD || uh->req_type == REQ_GET)) {
                uclient_http_connect(&uh->uc);
@@ -677,7 +679,6 @@ static void uclient_http_headers_complete(struct uclient_http *uh)
 {
        uh->state = HTTP_STATE_PROCESS_HEADERS;
        uh->uc.meta = uh->meta.head;
-       uclient_http_process_headers(uh);
 
        uh->process_headers_t.cb = uclient_http_process_headers_cb;
        uloop_timeout_set(&uh->process_headers_t, 1);