Commit bb603b3d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Introduce a dedicated http_SetStatus() function.

parent 69600783
......@@ -1001,6 +1001,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);
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);
int http_IsHdr(const txt *hh, const char *hdr);
......
......@@ -552,6 +552,27 @@ http_GetStatus(const struct http *hp)
return (hp->status);
}
/*--------------------------------------------------------------------*/
void
http_SetStatus(struct http *to, uint16_t status)
{
char buf[4];
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
/*
* We allow people to use top digits for internal VCL
* signalling, but strip them from the ASCII version.
*/
to->status = status;
status %= 1000;
assert(status >= 100);
bprintf(buf, "%03d", status);
http_PutField(to, HTTP_HDR_STATUS, buf);
}
/*--------------------------------------------------------------------*/
const char *
http_GetReq(const struct http *hp)
{
......@@ -581,19 +602,11 @@ void
http_PutResponse(struct http *to, const char *proto, uint16_t status,
const char *reason)
{
char buf[4];
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
http_SetH(to, HTTP_HDR_PROTO, proto);
/*
* We allow people to use top digits for internal VCL
* signalling, strip them here.
*/
status %= 1000;
assert(status >= 100);
to->status = status;
bprintf(buf, "%03d", status % 1000);
http_PutField(to, HTTP_HDR_STATUS, buf);
if (proto != NULL)
http_SetH(to, HTTP_HDR_PROTO, proto);
http_SetStatus(to, status);
if (reason == NULL)
reason = http_Status2Reason(status);
http_SetH(to, HTTP_HDR_REASON, reason);
......
......@@ -105,8 +105,9 @@ VRT_l_##obj##_status(const struct vrt_ctx *ctx, long num) \
VSLb(ctx->vsl, SLT_VCL_Error, "illegal %s.status (..0##)", \
#obj); \
ctx->http_##obj->failed = 1; \
} else \
ctx->http_##obj->status = (uint16_t)num; \
} else { \
http_SetStatus(ctx->http_##obj, (uint16_t)num); \
} \
}
#define VRT_STATUS_R(obj) \
......
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