From 488f1d52cfd2fcca8e0f3785311c247d13cb0170 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 27 Mar 2024 11:52:49 +0100 Subject: [PATCH] http: add helper function for checking redirect status Signed-off-by: Felix Fietkau --- uclient-http.c | 8 +------- uclient.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/uclient-http.c b/uclient-http.c index c2bba6b..935d50f 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -1159,14 +1159,8 @@ int uclient_http_redirect(struct uclient *cl) if (cl->backend != &uclient_backend_http) return false; - switch (cl->status_code) { - case 301: - case 302: - case 307: - break; - default: + if (!uclient_http_status_redirect(cl)) return false; - } blobmsg_parse(&location, 1, &tb, blob_data(uh->meta.head), blob_len(uh->meta.head)); if (!tb) diff --git a/uclient.h b/uclient.h index 0901910..ffe159a 100644 --- a/uclient.h +++ b/uclient.h @@ -125,6 +125,18 @@ int uclient_http_set_header(struct uclient *cl, const char *name, const char *va int uclient_http_set_request_type(struct uclient *cl, const char *type); int uclient_http_redirect(struct uclient *cl); +static inline bool uclient_http_status_redirect(struct uclient *cl) +{ + switch (cl->status_code) { + case 301: + case 302: + case 307: + return true; + default: + return false; + } +} + int uclient_http_set_ssl_ctx(struct uclient *cl, const struct ustream_ssl_ops *ops, struct ustream_ssl_ctx *ctx, bool require_validation); int uclient_http_set_address_family(struct uclient *cl, int af); -- 2.30.2