Commit cbd7675a authored by Nils Goroll's avatar Nils Goroll

Avoid setting the http response twice via http_PutResponse()

parent 084cd13e
......@@ -628,7 +628,7 @@ double http_GetHdrQ(const struct http *hp, const char *hdr, const char *field);
ssize_t http_GetContentLength(const struct http *hp);
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);
void http_SetStatus(struct http *to, uint16_t status, const char *reason);
const char *http_GetMethod(const struct http *hp);
int http_HdrIs(const struct http *hp, const char *hdr, const char *val);
void http_CopyHome(const struct http *hp);
......
......@@ -798,10 +798,9 @@ http_IsStatus(const struct http *hp, int val)
*/
void
http_SetStatus(struct http *to, uint16_t status)
http_SetStatus(struct http *to, uint16_t status, const char *reason)
{
char buf[4];
const char *reason;
const char *sstr = NULL;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
......@@ -813,7 +812,11 @@ http_SetStatus(struct http *to, uint16_t status)
status %= 1000;
assert(status >= 100);
reason = http_Status2Reason(status, &sstr);
if (reason == NULL)
reason = http_Status2Reason(status, &sstr);
else
(void)http_Status2Reason(status, &sstr);
if (sstr) {
http_SetH(to, HTTP_HDR_STATUS, sstr);
} else {
......@@ -865,9 +868,7 @@ http_PutResponse(struct http *to, const char *proto, uint16_t status,
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
if (proto != NULL)
http_SetH(to, HTTP_HDR_PROTO, proto);
http_SetStatus(to, status);
if (reason != NULL)
http_SetH(to, HTTP_HDR_REASON, reason);
http_SetStatus(to, status, reason);
}
/*--------------------------------------------------------------------
......
......@@ -108,7 +108,7 @@ VRT_l_##obj##_status(VRT_CTX, VCL_INT num) \
VRT_fail(ctx, "illegal %s.status (%jd) (..0##)", \
#obj, (intmax_t)num); \
else \
http_SetStatus(ctx->http_##obj, (uint16_t)num); \
http_SetStatus(ctx->http_##obj, (uint16_t)num, NULL); \
}
#define VRT_STATUS_R(obj) \
......
......@@ -453,7 +453,7 @@ HTTP1_DissectResponse(struct http_conn *htc, struct http *hp,
(int)(htc->rxbuf_e - htc->rxbuf_b), htc->rxbuf_b);
assert(retval >= 100 && retval <= 999);
assert(retval == 503);
http_SetStatus(hp, 503);
http_SetStatus(hp, 503, NULL);
}
if (hp->hd[HTTP_HDR_REASON].b == NULL ||
......
......@@ -125,8 +125,7 @@ logexpect l1 -v v1 -g raw {
expect 0 1011 RespProtocol {^HTTP/1.1$}
expect 0 1011 RespStatus {^405$}
expect 0 1011 RespReason {^Method Not Allowed$}
# XXX dup RespReason
expect 1 1011 RespHeader {^Date:}
expect 0 1011 RespHeader {^Date:}
expect 0 1011 RespHeader {^Server: Varnish$}
expect 0 1011 RespHeader {^X-Varnish: 1011$}
expect * 1011 Timestamp {^Process:}
......
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