Skip to content

Commit

Permalink
Simplify the trickery to find the right SLT for http header operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Jan 8, 2014
1 parent 18876a3 commit a8e79f6
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 54 deletions.
16 changes: 2 additions & 14 deletions bin/varnishd/cache/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,6 @@ struct ws {
char *e; /* (E)nd of buffer */
};

/*--------------------------------------------------------------------
* HTTP Request/Response/Header handling structure.
*/

enum httpwhence {
HTTP_Method = 1,
HTTP_Resp,
HTTP_Bereq,
HTTP_Beresp,
HTTP_Obj
};

/*--------------------------------------------------------------------
* Ban info event types
*/
Expand All @@ -197,7 +185,7 @@ struct http {
unsigned magic;
#define HTTP_MAGIC 0x6428b5c9

enum httpwhence logtag;
enum VSL_tag_e logtag; /* Must be SLT_*Method */
struct vsl_log *vsl;

struct ws *ws;
Expand Down Expand Up @@ -998,7 +986,7 @@ void http_PrintfHeader(struct http *to, const char *fmt, ...)
void http_SetHeader(struct http *to, const char *hdr);
void http_SetH(const struct http *to, unsigned n, const char *fm);
void http_ForceGet(const struct http *to);
void HTTP_Setup(struct http *, struct ws *, struct vsl_log *, enum httpwhence);
void HTTP_Setup(struct http *, struct ws *, struct vsl_log *, enum VSL_tag_e);
void http_Teardown(struct http *ht);
int http_GetHdr(const struct http *hp, const char *hdr, char **ptr);
int http_GetHdrData(const struct http *hp, const char *hdr,
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_esi_deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ved_include(struct req *preq, const char *src, const char *host)

req->http0->conds = 0;

HTTP_Setup(req->http, req->ws, req->vsl, HTTP_Method);
HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);

http_SetH(req->http0, HTTP_HDR_URL, src);
if (host != NULL && *host != '\0') {
Expand Down
12 changes: 6 additions & 6 deletions bin/varnishd/cache/cache_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
AZ(bo->should_close);
AZ(bo->storage_hint);

HTTP_Setup(bo->bereq0, bo->ws, bo->vsl, HTTP_Bereq);
HTTP_Setup(bo->bereq0, bo->ws, bo->vsl, SLT_BereqMethod);
http_FilterReq(bo->bereq0, bo->req->http,
bo->do_pass ? HTTPH_R_PASS : HTTPH_R_FETCH);
if (!bo->do_pass) {
Expand Down Expand Up @@ -118,7 +118,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
AZ(bo->should_close);
AZ(bo->storage_hint);

HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
HTTP_Setup(bo->bereq, bo->ws, bo->vsl, SLT_BereqMethod);
HTTP_Copy(bo->bereq, bo->bereq0);

VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws);
Expand All @@ -144,7 +144,7 @@ static void
make_it_503(struct busyobj *bo)
{

HTTP_Setup(bo->beresp, bo->ws, bo->vsl, HTTP_Beresp);
HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
http_SetH(bo->beresp, HTTP_HDR_PROTO, "HTTP/1.1");
http_SetResp(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
http_SetHeader(bo->beresp, "Content-Length: 0");
Expand All @@ -164,7 +164,7 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)

xxxassert (wrk->handling == VCL_RET_FETCH);

HTTP_Setup(bo->beresp, bo->ws, bo->vsl, HTTP_Beresp);
HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);

if (!bo->do_pass && bo->req != NULL)
vbf_release_req(bo); /* XXX: retry ?? */
Expand Down Expand Up @@ -433,7 +433,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
hp = bo->beresp;
hp2 = obj->http;

hp2->logtag = HTTP_Obj;
hp2->logtag = SLT_ObjMethod;
http_FilterResp(hp, hp2, bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS);
http_CopyHome(hp2);

Expand Down Expand Up @@ -594,7 +594,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)

obj->vxid = bo->vsl->wid;

obj->http->logtag = HTTP_Obj;
obj->http->logtag = SLT_ObjMethod;
/* XXX: we should have our own HTTP_A_CONDFETCH */
http_FilterResp(bo->ims_obj->http, obj->http, HTTPH_A_INS);
http_CopyHome(obj->http);
Expand Down
47 changes: 22 additions & 25 deletions bin/varnishd/cache/cache_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,46 @@
#include "tbl/http_headers.h"
#undef HTTPH

/*--------------------------------------------------------------------*/

static const enum VSL_tag_e foo[] = {
[HTTP_Method] = SLT_ReqMethod,
[HTTP_Resp] = SLT_RespMethod,
[HTTP_Bereq] = SLT_BereqMethod,
[HTTP_Beresp] = SLT_BerespMethod,
[HTTP_Obj] = SLT_ObjMethod,
};

static enum VSL_tag_e
http2shmlog(const struct http *hp, int t)
{

CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
if (t > HTTP_HDR_FIRST)
t = HTTP_HDR_FIRST;
assert(hp->logtag >= HTTP_Method && hp->logtag <= HTTP_Obj); /*lint !e685*/
assert(t >= HTTP_HDR_METHOD && t <= HTTP_HDR_FIRST);
return ((enum VSL_tag_e)(foo[hp->logtag] + t));
}
/*--------------------------------------------------------------------
* These two functions are in an incestous relationship with the
* order of macros in include/tbl/vsl_tags_http.h
*
* The http->logtag is the SLT_*Method enum, and we add to that, to
* get the SLT_ to use.
*/

static void
http_VSLH(const struct http *hp, unsigned hdr)
{
int i;

if (hp->vsl != NULL) {
AN(hp->vsl->wid & (VSL_CLIENTMARKER|VSL_BACKENDMARKER));
VSLbt(hp->vsl, http2shmlog(hp, hdr), hp->hd[hdr]);
i = hdr;
if (i > HTTP_HDR_FIRST)
i = HTTP_HDR_FIRST;
i += hp->logtag;
VSLbt(hp->vsl, (enum VSL_tag_e)i, hp->hd[hdr]);
}
}

static void
http_VSLH_del(const struct http *hp, unsigned hdr)
{
int i;

if (hp->vsl != NULL) {
/* We don't support unsetting stuff in the first line */
assert (hdr >= HTTP_HDR_FIRST);
AN(hp->vsl->wid & (VSL_CLIENTMARKER|VSL_BACKENDMARKER));
VSLbt(hp->vsl, ((enum VSL_tag_e)(http2shmlog(hp, hdr) + 1)),
hp->hd[hdr]);
i = (HTTP_HDR_UNSET - HTTP_HDR_METHOD);
i += hp->logtag;
VSLbt(hp->vsl, (enum VSL_tag_e)i, hp->hd[hdr]);
}
}

/*--------------------------------------------------------------------*/

void
http_VSL_log(const struct http *hp)
{
Expand Down Expand Up @@ -145,7 +142,7 @@ HTTP_create(void *p, uint16_t nhttp)

void
HTTP_Setup(struct http *hp, struct ws *ws, struct vsl_log *vsl,
enum httpwhence whence)
enum VSL_tag_e whence)
{
http_Teardown(hp);
hp->logtag = whence;
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_http1_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ http1_dissect(struct worker *wrk, struct req *req)
req->vcl = wrk->vcl;
wrk->vcl = NULL;

HTTP_Setup(req->http, req->ws, req->vsl, HTTP_Method);
HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
req->err_code = HTTP1_DissectRequest(req);

/* If we could not even parse the request, just close */
Expand Down
4 changes: 2 additions & 2 deletions bin/varnishd/cache/cache_req_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
if (!(req->obj->objcore->flags & OC_F_PRIVATE))
EXP_Touch(req->obj->objcore, req->t_resp);

HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp);
HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);

http_ClrHeader(req->resp);
http_FilterResp(req->obj->http, req->resp, 0);
Expand Down Expand Up @@ -594,7 +594,7 @@ cnt_pipe(struct worker *wrk, struct req *req)

req->acct_req.pipe++;
bo = VBO_GetBusyObj(wrk, req);
HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
HTTP_Setup(bo->bereq, bo->ws, bo->vsl, SLT_BereqMethod);
http_FilterReq(bo->bereq, req->http, 0); // XXX: 0 ?
http_PrintfHeader(bo->bereq,
"X-Varnish: %u", req->vsl->wid & VSL_IDENTMASK);
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/storage/stevedore.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo,
WS_Assert(bo->ws_o);
assert(bo->ws_o->e <= (char*)ptr + ltot);

HTTP_Setup(o->http, bo->ws_o, bo->vsl, HTTP_Obj);
HTTP_Setup(o->http, bo->ws_o, bo->vsl, SLT_ObjMethod);
o->http->magic = HTTP_MAGIC;
o->exp = bo->exp;
o->last_use = bo->t_fetch;
Expand Down
4 changes: 2 additions & 2 deletions bin/varnishtest/tests/r01029.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ varnish v1 -vcl+backend {
} -start

client c1 {
txreq -url "/bar" -hdr "Accept-Encoding: gzip"
txreq -url "/bar" -hdr "Accept-Encoding: gzip,foo"
rxresp
gunzip
expect resp.bodylen == 5

txreq -url "/foo" -hdr "Accept-Encoding: gzip"
txreq -url "/foo" -hdr "Accept-Encoding: gzip,foo"
rxresp
expect resp.bodylen == 21
} -run
16 changes: 14 additions & 2 deletions include/tbl/vsl_tags_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
*
* Define the VSL tags for HTTP protocol messages
*
* The order of this table is not random, do not resort.
* In particular, the FIRST and LOST entries must be last, in that order.
* NB: The order of this table is not random, DO NOT RESORT.
*
* Specifically FIRST, UNSET and LOST entries must be last, in that order.
*
* See bin/varnishd/cache/cache_http.c::http_VSLH() for the other side.
*
* Arguments:
* Tag-Name
Expand Down Expand Up @@ -64,6 +67,15 @@ SLTH(Header, HTTP_HDR_FIRST, 1, 1, "header",
"\t+----- Header name\n"
"\n"
)
SLTH(Unset, HTTP_HDR_UNSET, 0, 0, "unset header",
"HTTP header contents.\n\n"
"The format is::\n\n"
"\t%s: %s\n"
"\t| |\n"
"\t| +- Header value\n"
"\t+----- Header name\n"
"\n"
)
SLTH(Lost, HTTP_HDR_LOST, 0, 0, "lost header",
""
)

0 comments on commit a8e79f6

Please sign in to comment.