Commit 9d7b6516 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Isolate the text-representation of the HTTP response status field in

http_cache.h, and use the integer representation everywhere else.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5376 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent b6fb900c
...@@ -65,6 +65,11 @@ ...@@ -65,6 +65,11 @@
#include "vsc.h" #include "vsc.h"
#include "vsl.h" #include "vsl.h"
/*
* NB: HDR_STATUS is only used in cache_http.c, everybody else uses the
* http->status integer field.
*/
enum { enum {
/* Fields from the first line of HTTP proto */ /* Fields from the first line of HTTP proto */
HTTP_HDR_REQ, HTTP_HDR_REQ,
...@@ -551,15 +556,15 @@ unsigned http_EstimateWS(const struct http *fm, unsigned how, unsigned *nhd); ...@@ -551,15 +556,15 @@ unsigned http_EstimateWS(const struct http *fm, unsigned how, unsigned *nhd);
void HTTP_Init(void); void HTTP_Init(void);
void http_ClrHeader(struct http *to); void http_ClrHeader(struct http *to);
unsigned http_Write(struct worker *w, const struct http *hp, int resp); unsigned http_Write(struct worker *w, const struct http *hp, int resp);
void http_CopyResp(const struct http *to, const struct http *fm); void http_CopyResp(struct http *to, const struct http *fm);
void http_SetResp(const struct http *to, const char *proto, const char *status, void http_SetResp(struct http *to, const char *proto, int status,
const char *response); const char *response);
void http_FilterFields(struct worker *w, int fd, struct http *to, void http_FilterFields(struct worker *w, int fd, struct http *to,
const struct http *fm, unsigned how); const struct http *fm, unsigned how);
void http_FilterHeader(const struct sess *sp, unsigned how); void http_FilterHeader(const struct sess *sp, unsigned how);
void http_PutProtocol(struct worker *w, int fd, const struct http *to, void http_PutProtocol(struct worker *w, int fd, const struct http *to,
const char *protocol); const char *protocol);
void http_PutStatus(struct worker *w, int fd, struct http *to, int status); void http_PutStatus(struct http *to, int status);
void http_PutResponse(struct worker *w, int fd, const struct http *to, void http_PutResponse(struct worker *w, int fd, const struct http *to,
const char *response); const char *response);
void http_PrintfHeader(struct worker *w, int fd, struct http *to, void http_PrintfHeader(struct worker *w, int fd, struct http *to,
......
...@@ -354,7 +354,7 @@ cnt_error(struct sess *sp) ...@@ -354,7 +354,7 @@ cnt_error(struct sess *sp)
sp->err_code = 501; sp->err_code = 501;
http_PutProtocol(w, sp->fd, h, "HTTP/1.1"); http_PutProtocol(w, sp->fd, h, "HTTP/1.1");
http_PutStatus(w, sp->fd, h, sp->err_code); http_PutStatus(h, sp->err_code);
TIM_format(TIM_real(), date); TIM_format(TIM_real(), date);
http_PrintfHeader(w, sp->fd, h, "Date: %s", date); http_PrintfHeader(w, sp->fd, h, "Date: %s", date);
http_PrintfHeader(w, sp->fd, h, "Server: Varnish"); http_PrintfHeader(w, sp->fd, h, "Server: Varnish");
......
...@@ -337,7 +337,6 @@ int ...@@ -337,7 +337,6 @@ int
http_GetStatus(const struct http *hp) http_GetStatus(const struct http *hp)
{ {
Tcheck(hp->hd[HTTP_HDR_STATUS]);
return (hp->status); return (hp->status);
} }
...@@ -615,24 +614,24 @@ http_ForceGet(const struct http *to) ...@@ -615,24 +614,24 @@ http_ForceGet(const struct http *to)
} }
void void
http_CopyResp(const struct http *to, const struct http *fm) http_CopyResp(struct http *to, const struct http *fm)
{ {
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
http_copyh(to, fm, HTTP_HDR_STATUS); to->status = fm->status;
http_copyh(to, fm, HTTP_HDR_RESPONSE); http_copyh(to, fm, HTTP_HDR_RESPONSE);
} }
void void
http_SetResp(const struct http *to, const char *proto, const char *status, http_SetResp(struct http *to, const char *proto, int status,
const char *response) const char *response)
{ {
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
http_SetH(to, HTTP_HDR_PROTO, proto); http_SetH(to, HTTP_HDR_PROTO, proto);
http_SetH(to, HTTP_HDR_STATUS, status); to->status = status;
http_SetH(to, HTTP_HDR_RESPONSE, response); http_SetH(to, HTTP_HDR_RESPONSE, response);
} }
...@@ -828,13 +827,10 @@ http_PutProtocol(struct worker *w, int fd, const struct http *to, ...@@ -828,13 +827,10 @@ http_PutProtocol(struct worker *w, int fd, const struct http *to,
} }
void void
http_PutStatus(struct worker *w, int fd, struct http *to, int status) http_PutStatus(struct http *to, int status)
{ {
char stat[4];
assert(status >= 0 && status <= 999); assert(status >= 0 && status <= 999);
sprintf(stat, "%d", status);
http_PutField(w, fd, to, HTTP_HDR_STATUS, stat);
to->status = status; to->status = status;
} }
...@@ -915,11 +911,18 @@ http_Write(struct worker *w, const struct http *hp, int resp) ...@@ -915,11 +911,18 @@ http_Write(struct worker *w, const struct http *hp, int resp)
unsigned u, l; unsigned u, l;
if (resp) { if (resp) {
AN(hp->hd[HTTP_HDR_STATUS].b);
l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " "); l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " ");
WSLH(w, *w->wfd, hp, HTTP_HDR_PROTO); WSLH(w, *w->wfd, hp, HTTP_HDR_PROTO);
hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(w->ws, 4);
AN(hp->hd[HTTP_HDR_STATUS].b);
sprintf(hp->hd[HTTP_HDR_STATUS].b, "%3d", hp->status);
hp->hd[HTTP_HDR_STATUS].e = hp->hd[HTTP_HDR_STATUS].b + 3;
l += WRW_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " "); l += WRW_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " ");
WSLH(w, *w->wfd, hp, HTTP_HDR_STATUS); WSLH(w, *w->wfd, hp, HTTP_HDR_STATUS);
l += WRW_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n"); l += WRW_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n");
WSLH(w, *w->wfd, hp, HTTP_HDR_RESPONSE); WSLH(w, *w->wfd, hp, HTTP_HDR_RESPONSE);
} else { } else {
......
...@@ -51,7 +51,7 @@ res_do_304(struct sess *sp) ...@@ -51,7 +51,7 @@ res_do_304(struct sess *sp)
http_ClrHeader(sp->wrk->resp); http_ClrHeader(sp->wrk->resp);
sp->wrk->resp->logtag = HTTP_Tx; sp->wrk->resp->logtag = HTTP_Tx;
http_SetResp(sp->wrk->resp, "HTTP/1.1", "304", "Not Modified"); http_SetResp(sp->wrk->resp, "HTTP/1.1", 304, "Not Modified");
TIM_format(sp->t_req, lm); TIM_format(sp->t_req, lm);
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", lm); http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", lm);
http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp, "Via: 1.1 varnish"); http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp, "Via: 1.1 varnish");
...@@ -181,7 +181,7 @@ res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh) ...@@ -181,7 +181,7 @@ res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh)
http_Unset(sp->wrk->resp, H_Content_Length); http_Unset(sp->wrk->resp, H_Content_Length);
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Content-Length: %u", 1 + high - low); "Content-Length: %u", 1 + high - low);
http_SetResp(sp->wrk->resp, "HTTP/1.1", "206", "Partial Content"); http_SetResp(sp->wrk->resp, "HTTP/1.1", 206, "Partial Content");
*plow = low; *plow = low;
......
...@@ -298,15 +298,8 @@ VRT_DO_HDR(beresp, response, sp->wrk->beresp, HTTP_HDR_RESPONSE) ...@@ -298,15 +298,8 @@ VRT_DO_HDR(beresp, response, sp->wrk->beresp, HTTP_HDR_RESPONSE)
void void
VRT_l_obj_status(const struct sess *sp, int num) VRT_l_obj_status(const struct sess *sp, int num)
{ {
char *p;
assert(num >= 100 && num <= 999); assert(num >= 100 && num <= 999);
p = WS_Alloc(sp->obj->http->ws, 4);
if (p == NULL)
WSP(sp, SLT_LostHeader, "%s", "obj.status");
else
sprintf(p, "%d", num);
http_SetH(sp->obj->http, HTTP_HDR_STATUS, p);
sp->obj->http->status = num; sp->obj->http->status = num;
} }
...@@ -367,38 +360,27 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a) ...@@ -367,38 +360,27 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a)
int int
VRT_r_obj_status(const struct sess *sp) VRT_r_obj_status(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
/* XXX: use http_GetStatus() */
if (sp->obj->http->status)
return (sp->obj->http->status); return (sp->obj->http->status);
AN(sp->obj->http->hd[HTTP_HDR_STATUS].b);
return (atoi(sp->obj->http->hd[HTTP_HDR_STATUS].b));
} }
void void
VRT_l_resp_status(const struct sess *sp, int num) VRT_l_resp_status(const struct sess *sp, int num)
{ {
char *p;
assert(num >= 100 && num <= 999); assert(num >= 100 && num <= 999);
p = WS_Alloc(sp->wrk->ws, 4);
if (p == NULL)
WSP(sp, SLT_LostHeader, "%s", "resp.status");
else
sprintf(p, "%d", num);
http_SetH(sp->wrk->resp, HTTP_HDR_STATUS, p);
sp->wrk->resp->status = num; sp->wrk->resp->status = num;
} }
int int
VRT_r_resp_status(const struct sess *sp) VRT_r_resp_status(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk->resp, HTTP_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk->resp, HTTP_MAGIC);
if (sp->wrk->resp->status)
return (sp->wrk->resp->status); return (sp->wrk->resp->status);
return (atoi(sp->wrk->resp->hd[HTTP_HDR_STATUS].b));
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -484,15 +466,8 @@ VRT_r_beresp_ttl(const struct sess *sp) ...@@ -484,15 +466,8 @@ VRT_r_beresp_ttl(const struct sess *sp)
void void
VRT_l_beresp_status(const struct sess *sp, int num) VRT_l_beresp_status(const struct sess *sp, int num)
{ {
char *p;
assert(num >= 100 && num <= 999); assert(num >= 100 && num <= 999);
p = WS_Alloc(sp->wrk->beresp->ws, 4);
if (p == NULL)
WSP(sp, SLT_LostHeader, "%s", "obj.status");
else
sprintf(p, "%d", num);
http_SetH(sp->wrk->beresp, HTTP_HDR_STATUS, p);
sp->wrk->beresp->status = num; sp->wrk->beresp->status = num;
} }
...@@ -500,11 +475,7 @@ int ...@@ -500,11 +475,7 @@ int
VRT_r_beresp_status(const struct sess *sp) VRT_r_beresp_status(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
/* XXX: use http_GetStatus() */
if (sp->wrk->beresp->status)
return (sp->wrk->beresp->status); return (sp->wrk->beresp->status);
AN(sp->wrk->beresp->hd[HTTP_HDR_STATUS].b);
return (atoi(sp->wrk->beresp->hd[HTTP_HDR_STATUS].b));
} }
...@@ -780,7 +751,7 @@ VRT_l_req_hash_ignore_busy(struct sess *sp, unsigned ignore_busy) ...@@ -780,7 +751,7 @@ VRT_l_req_hash_ignore_busy(struct sess *sp, unsigned ignore_busy)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sp->hash_ignore_busy = ignore_busy; sp->hash_ignore_busy = ignore_busy ? 1 : 0;
} }
unsigned unsigned
...@@ -800,7 +771,7 @@ VRT_l_req_hash_always_miss(struct sess *sp, unsigned always_miss) ...@@ -800,7 +771,7 @@ VRT_l_req_hash_always_miss(struct sess *sp, unsigned always_miss)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sp->hash_always_miss = always_miss; sp->hash_always_miss = always_miss ? 1 : 0;
} }
unsigned unsigned
......
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