Commit 4d5a73ba authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Don't frob http->status directly to test value, we need to take

account for the extra two digits made available for VCL.
parent a25a2b67
......@@ -967,6 +967,7 @@ int http_GetHdrField(const struct http *hp, const char *hdr,
const char *field, char **ptr);
double http_GetHdrQ(const struct http *hp, const char *hdr, const char *field);
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 *http_GetReq(const struct http *hp);
int http_HdrIs(const struct http *hp, const char *hdr, const char *val);
......
......@@ -203,7 +203,7 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
http_CopyHome(bo->bereq0);
}
if (bo->ims_obj != NULL && bo->ims_obj->http->status == 200) {
if (bo->ims_obj != NULL && http_IsStatus(bo->ims_obj->http, 200)) {
if (http_GetHdr(bo->ims_obj->http, H_Last_Modified, &p)) {
http_PrintfHeader(bo->bereq0,
"If-Modified-Since: %s", p);
......@@ -351,10 +351,10 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
AZ(bo->do_esi);
if (bo->ims_obj != NULL && bo->beresp->status == 304) {
if (bo->ims_obj != NULL && http_IsStatus(bo->beresp, 304)) {
http_Merge(bo->ims_obj->http, bo->beresp,
bo->ims_obj->changed_gzip);
assert(bo->beresp->status == 200);
assert(http_IsStatus(bo->beresp, 200));
do_ims = 1;
} else
do_ims = 0;
......
......@@ -532,6 +532,15 @@ http_GetStatus(const struct http *hp)
return (hp->status);
}
int
http_IsStatus(const struct http *hp, int val)
{
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
assert(val >= 100 && val <= 999);
return (val == (hp->status % 1000));
}
/*--------------------------------------------------------------------
* Setting the status will also set the Reason appropriately
*/
......
......@@ -93,7 +93,7 @@ v1d_dorange(struct req *req, struct busyobj *bo, const char *r)
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
assert(http_GetStatus(req->resp) == 200);
assert(http_IsStatus(req->resp, 200));
/* We must snapshot the length if we're streaming from the backend */
if (bo != NULL)
......@@ -244,7 +244,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
/* In ESI mode, we can't know the aggregate length */
req->res_mode &= ~RES_LEN;
req->res_mode |= RES_ESI;
} else if (req->resp->status == 304) {
} else if (http_IsStatus(req->resp, 304)) {
req->res_mode &= ~RES_LEN;
http_Unset(req->resp, H_Content_Length);
req->wantbody = 0;
......@@ -308,7 +308,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
req->wantbody &&
!(req->res_mode & (RES_ESI|RES_ESI_CHILD)) &&
cache_param->http_range_support &&
http_GetStatus(req->resp) == 200) {
http_IsStatus(req->resp, 200)) {
http_SetHeader(req->resp, "Accept-Ranges: bytes");
if (http_GetHdr(req->http, H_Range, &r))
v1d_dorange(req, bo, r);
......@@ -373,7 +373,7 @@ V1D_Deliver_Synth(struct req *req)
AN(req->synth_body);
req->res_mode = 0;
if (req->resp->status == 304) {
if (http_IsStatus(req->resp, 304)) {
req->res_mode &= ~RES_LEN;
http_Unset(req->resp, H_Content_Length);
req->wantbody = 0;
......@@ -422,7 +422,7 @@ V1D_Deliver_Synth(struct req *req)
req->wantbody &&
!(req->res_mode & RES_ESI_CHILD) &&
cache_param->http_range_support &&
http_GetStatus(req->resp) == 200) {
http_IsStatus(req->resp, 200)) {
http_SetHeader(req->resp, "Accept-Ranges: bytes");
if (http_GetHdr(req->http, H_Range, &r))
v1d_dorange(req, NULL, r);
......
......@@ -163,7 +163,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
if (!(req->objcore->flags & OC_F_PASS)
&& req->esi_level == 0
&& http_GetStatus(req->resp) == 200
&& http_IsStatus(req->resp, 200)
&& req->http->conds && RFC2616_Do_Cond(req)) {
http_PutResponse(req->resp, "HTTP/1.1", 304, NULL);
req->wantbody = 0;
......
......@@ -207,16 +207,17 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats)
return (BS_NONE);
}
if (hp->status <= 199) {
if (http_GetStatus(hp) <= 199) {
/*
* 1xx responses never have a body.
* [RFC2616 4.3 p33]
* ... but we should never see them.
*/
stats->fetch_1xx++;
return (BS_NONE);
return (BS_ERROR);
}
if (hp->status == 204) {
if (http_IsStatus(hp, 204)) {
/*
* 204 is "No Content", obviously don't expect a body.
* [RFC2616 10.2.5 p60]
......@@ -225,7 +226,7 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats)
return (BS_NONE);
}
if (hp->status == 304) {
if (http_IsStatus(hp, 304)) {
/*
* 304 is "Not Modified" it has no body.
* [RFC2616 10.3.5 p63]
......
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