diff options
| author | Felix Fietkau | 2024-03-27 10:52:49 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2024-03-27 10:52:49 +0000 |
| commit | 488f1d52cfd2fcca8e0f3785311c247d13cb0170 (patch) | |
| tree | 0424cfd967308b7f1ef21a844b2e796dbbaa3c5d | |
| parent | af1962b9a60930cd1f24eff2854bceaa2a6c964d (diff) | |
| download | uclient-488f1d52cfd2fcca8e0f3785311c247d13cb0170.tar.gz | |
http: add helper function for checking redirect status
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | uclient-http.c | 8 | ||||
| -rw-r--r-- | 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) @@ -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); |