summaryrefslogtreecommitdiff
path: root/libfetch/http.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-07-16 10:22:42 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-16 10:25:14 +0300
commitd909ebc25b23c0ccd698f161ab624c3cdc890e35 (patch)
tree8dcac9a3c3168a650c5a4719f75dcaec70211ac0 /libfetch/http.c
parentb2819a6d5a7d9fa1a6e96e7a4d5e034b7fb63ac0 (diff)
downloadapk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.tar.gz
apk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.tar.bz2
apk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.tar.xz
apk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.zip
libfetch: simplify code by merging protocol error handling branches
removes some code duplication
Diffstat (limited to 'libfetch/http.c')
-rw-r--r--libfetch/http.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/libfetch/http.c b/libfetch/http.c
index bb01fdc..59d6292 100644
--- a/libfetch/http.c
+++ b/libfetch/http.c
@@ -1044,8 +1044,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
fetch_syserr();
goto ouch;
case hdr_error:
- http_seterr(HTTP_PROTOCOL_ERROR);
- goto ouch;
+ goto protocol_error;
case hdr_connection:
/* XXX too weak? */
keep_alive = (strcasecmp(p, "keep-alive") == 0);
@@ -1154,18 +1153,14 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
}
/* check for inconsistencies */
- if (clength != -1 && length != -1 && clength != length) {
- http_seterr(HTTP_PROTOCOL_ERROR);
- goto ouch;
- }
+ if (clength != -1 && length != -1 && clength != length)
+ goto protocol_error;
if (clength == -1)
clength = length;
if (clength != -1)
length = offset + clength;
- if (length != -1 && size != -1 && length != size) {
- http_seterr(HTTP_PROTOCOL_ERROR);
- goto ouch;
- }
+ if (length != -1 && size != -1 && length != size)
+ goto protocol_error;
if (size == -1)
size = length;
@@ -1176,10 +1171,8 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
}
/* too far? */
- if (URL->offset > 0 && offset > URL->offset) {
- http_seterr(HTTP_PROTOCOL_ERROR);
- goto ouch;
- }
+ if (URL->offset > 0 && offset > URL->offset)
+ goto protocol_error;
/* report back real offset and size */
URL->offset = offset;
@@ -1222,6 +1215,8 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
return (f);
+protocol_error:
+ http_seterr(HTTP_PROTOCOL_ERROR);
ouch:
if (url != URL)
fetchFreeURL(url);