Commit e8f56d91 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

range: Move more parsing logic to http_GetRange()

parent 3e0717e5
......@@ -640,7 +640,8 @@ int http_GetHdrField(const struct http *hp, hdr_t,
double http_GetHdrQ(const struct http *hp, hdr_t, const char *field);
ssize_t http_GetContentLength(const struct http *hp);
ssize_t http_GetContentRange(const struct http *hp, ssize_t *lo, ssize_t *hi);
const char * http_GetRange(const struct http *hp, ssize_t *lo, ssize_t *hi);
const char * http_GetRange(const struct http *hp, ssize_t *lo, ssize_t *hi,
ssize_t len);
uint16_t http_GetStatus(const struct http *hp);
int http_IsStatus(const struct http *hp, int);
void http_SetStatus(struct http *to, uint16_t status, const char *reason);
......
......@@ -958,7 +958,7 @@ http_GetContentRange(const struct http *hp, ssize_t *lo, ssize_t *hi)
}
const char *
http_GetRange(const struct http *hp, ssize_t *lo, ssize_t *hi)
http_GetRange(const struct http *hp, ssize_t *lo, ssize_t *hi, ssize_t len)
{
ssize_t tmp_lo, tmp_hi;
const char *b, *t;
......@@ -1003,6 +1003,26 @@ http_GetRange(const struct http *hp, ssize_t *lo, ssize_t *hi)
b++;
if (*b != '\0')
return ("Trailing stuff");
assert(*lo >= -1);
assert(*hi >= -1);
if (len <= 0)
return (NULL); // Allow 200 response
if (*lo < 0) {
assert(*hi > 0);
*lo = len - *hi;
if (*lo < 0)
*lo = 0;
*hi = len - 1;
} else if (len >= 0 && (*hi >= len || *hi < 0)) {
*hi = len - 1;
}
if (*lo >= len)
return ("low range beyond object");
return (NULL);
}
......
......@@ -108,25 +108,13 @@ vrg_dorange(struct req *req, void **priv)
struct vrg_priv *vrg_priv;
const char *err;
err = http_GetRange(req->http, &low, &high);
err = http_GetRange(req->http, &low, &high, req->resp_len);
if (err != NULL)
return (err);
assert(low >= -1);
assert(high >= -1);
if (low < 0) {
if (req->resp_len < 0 || high < 0)
return (NULL); // Allow 200 response
assert(high > 0);
low = req->resp_len - high;
if (low < 0)
low = 0;
high = req->resp_len - 1;
} else if (req->resp_len >= 0 && (high >= req->resp_len || high < 0))
high = req->resp_len - 1;
else if (high < 0)
return (NULL); // Allow 200 response
if (low < 0 || high < 0)
return (NULL); // Allow 200 response
/*
* else (bo != NULL) {
* We assume that the client knows what it's doing and trust
......@@ -134,9 +122,6 @@ vrg_dorange(struct req *req, void **priv)
* }
*/
if (req->resp_len >= 0 && low >= req->resp_len)
return ("low range beyond object");
if (req->resp_len >= 0) {
http_PrintfHeader(req->resp, "Content-Range: bytes %jd-%jd/%jd",
(intmax_t)low, (intmax_t)high, (intmax_t)req->resp_len);
......@@ -268,7 +253,7 @@ VRG_CheckBo(struct busyobj *bo)
if (!cache_param->http_range_support)
return (0);
err = http_GetRange(bo->bereq0, &rlo, &rhi);
err = http_GetRange(bo->bereq0, &rlo, &rhi, -1);
clen = http_GetContentLength(bo->beresp);
crlen = http_GetContentRange(bo->beresp, &crlo, &crhi);
......
......@@ -58,6 +58,7 @@
* binary/load-time compatible, increment MAJOR version
*
* NEXT (2023-03-15)
* [cache.h] http_GetRange() changed
* 16.0 (2022-09-15)
* VMOD C-prototypes moved into JSON
* VRT_AddVDP() deprecated
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment