Commit 8783ce18 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Implement vcl_deliver() and change variable visibility to match.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1640 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 74d77fbe
...@@ -471,6 +471,7 @@ void WSL_Flush(struct worker *w); ...@@ -471,6 +471,7 @@ void WSL_Flush(struct worker *w);
#endif #endif
/* cache_response.c */ /* cache_response.c */
void RES_BuildHttp(struct sess *sp);
void RES_Error(struct sess *sp, int code, const char *reason); void RES_Error(struct sess *sp, int code, const char *reason);
void RES_WriteObj(struct sess *sp); void RES_WriteObj(struct sess *sp);
......
...@@ -119,7 +119,7 @@ DOT label="Filter obj.->resp." ...@@ -119,7 +119,7 @@ DOT label="Filter obj.->resp."
DOT ] DOT ]
DOT vcl_deliver [ DOT vcl_deliver [
DOT shape=record DOT shape=record
DOT label="vcl_deliver()|req.\nresp." DOT label="vcl_deliver()|resp."
DOT ] DOT ]
DOT deliver2 [ DOT deliver2 [
DOT shape=ellipse DOT shape=ellipse
...@@ -131,12 +131,29 @@ DOT vcl_deliver -> errdeliver [label="error"] ...@@ -131,12 +131,29 @@ DOT vcl_deliver -> errdeliver [label="error"]
DOT errdeliver [label="ERROR",shape=plaintext] DOT errdeliver [label="ERROR",shape=plaintext]
DOT } DOT }
DOT deliver2 -> DONE [style=bold,color=green,weight=4] DOT deliver2 -> DONE [style=bold,color=green,weight=4]
*
* XXX: Ideally we should make the req. available in vcl_deliver() but for
* XXX: reasons of economy we don't, since that allows us to reuse the space
* XXX: in sp->req for the response.
*
* XXX: Rather than allocate two http's and workspaces for all sessions to
* XXX: address this deficiency, we could make the VCL compiler set a flag
* XXX: if req. is used in vcl_deliver(). When the flag is set we would
* XXX: take the memory overhead, for instance by borrowing a struct bereq
* XXX: or similar.
*
* XXX: For now, wait until somebody asks for it.
*/ */
static int static int
cnt_deliver(struct sess *sp) cnt_deliver(struct sess *sp)
{ {
RES_BuildHttp(sp);
VCL_deliver_method(sp);
if (sp->handling != VCL_RET_DELIVER)
INCOMPL();
RES_WriteObj(sp); RES_WriteObj(sp);
HSH_Deref(sp->obj); HSH_Deref(sp->obj);
sp->obj = NULL; sp->obj = NULL;
...@@ -171,6 +188,7 @@ cnt_done(struct sess *sp) ...@@ -171,6 +188,7 @@ cnt_done(struct sess *sp)
double dh, dp, da; double dh, dp, da;
AZ(sp->obj); AZ(sp->obj);
AZ(sp->bereq);
sp->backend = NULL; sp->backend = NULL;
if (sp->vcl != NULL) { if (sp->vcl != NULL) {
if (sp->wrk->vcl != NULL) if (sp->wrk->vcl != NULL)
......
...@@ -114,13 +114,9 @@ res_do_conds(struct sess *sp) ...@@ -114,13 +114,9 @@ res_do_conds(struct sess *sp)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
RES_WriteObj(struct sess *sp) RES_BuildHttp(struct sess *sp)
{ {
struct storage *st;
unsigned u = 0;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
clock_gettime(CLOCK_REALTIME, &sp->t_resp);
if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp)) if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
return; return;
...@@ -136,12 +132,26 @@ RES_WriteObj(struct sess *sp) ...@@ -136,12 +132,26 @@ RES_WriteObj(struct sess *sp)
http_PrintfHeader(sp->wrk, sp->fd, sp->http, http_PrintfHeader(sp->wrk, sp->fd, sp->http,
"X-Varnish: %u %u", sp->xid, sp->obj->xid); "X-Varnish: %u %u", sp->xid, sp->obj->xid);
else else
http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, sp->http,
"X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u", http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u",
sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered); sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered);
http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
if (sp->doclose != NULL) if (sp->doclose != NULL)
http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
}
/*--------------------------------------------------------------------*/
void
RES_WriteObj(struct sess *sp)
{
struct storage *st;
unsigned u = 0;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
clock_gettime(CLOCK_REALTIME, &sp->t_resp);
WRK_Reset(sp->wrk, &sp->fd); WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
......
...@@ -483,10 +483,12 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -483,10 +483,12 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n"); vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n");
vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n");
vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n");
vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n");
vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n");
vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n");
vsb_cat(sb, "double VRT_r_now(struct sess *);\n");
} }
...@@ -44,14 +44,14 @@ set spobj { ...@@ -44,14 +44,14 @@ set spobj {
# Connection related parameters # Connection related parameters
{ client.ip { client.ip
RO IP RO IP
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch deliver }
} }
{ client.bandwidth # Not implemented yet { client.bandwidth # Not implemented yet
NO NO
} }
{ server.ip { server.ip
RO IP RO IP
{recv pipe pass hash miss hit fetch } {recv pipe pass hash miss hit fetch deliver }
} }
# Request paramters # Request paramters
...@@ -103,7 +103,7 @@ set spobj { ...@@ -103,7 +103,7 @@ set spobj {
# The (possibly) cached object # The (possibly) cached object
{ obj.proto { obj.proto
RW STRING RW STRING
{ hit fetch deliver } { hit fetch }
} }
{ obj.status { obj.status
RW INT RW INT
...@@ -115,7 +115,7 @@ set spobj { ...@@ -115,7 +115,7 @@ set spobj {
} }
{ obj.http. { obj.http.
RW HEADER RW HEADER
{ hit fetch deliver } { hit fetch }
} }
{ obj.valid { obj.valid
...@@ -138,22 +138,24 @@ set spobj { ...@@ -138,22 +138,24 @@ set spobj {
# The response we send back # The response we send back
{ resp.proto { resp.proto
RW STRING RW STRING
{ fetch } { deliver }
} }
{ resp.status { resp.status
RW INT RW INT
{ fetch } { deliver }
} }
{ resp.response { resp.response
RW STRING RW STRING
{ fetch } { deliver }
} }
{ resp.http. { resp.http.
RW HEADER RW HEADER
{ fetch } { deliver }
} }
# Miscellaneous # Miscellaneous
# XXX: I'm not happy about this one. All times should be relative
# XXX: or delta times in VCL programs, so this shouldn't be needed /phk
{ now { now
RO TIME RO TIME
{recv pipe pass hash miss hit fetch deliver discard timeout} {recv pipe pass hash miss hit fetch deliver discard timeout}
......
...@@ -36,13 +36,13 @@ struct var vcc_vars[] = { ...@@ -36,13 +36,13 @@ struct var vcc_vars[] = {
"VRT_r_client_ip(sp)", "VRT_r_client_ip(sp)",
NULL, NULL,
V_RO, V_RO,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
}, },
{ "server.ip", IP, 9, { "server.ip", IP, 9,
"VRT_r_server_ip(sp)", "VRT_r_server_ip(sp)",
NULL, NULL,
V_RO, V_RO,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
}, },
{ "req.request", STRING, 11, { "req.request", STRING, 11,
"VRT_r_req_request(sp)", "VRT_r_req_request(sp)",
...@@ -108,7 +108,7 @@ struct var vcc_vars[] = { ...@@ -108,7 +108,7 @@ struct var vcc_vars[] = {
"VRT_r_obj_proto(sp)", "VRT_r_obj_proto(sp)",
"VRT_l_obj_proto(sp, ", "VRT_l_obj_proto(sp, ",
V_RW, V_RW,
VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER VCL_MET_HIT | VCL_MET_FETCH
}, },
{ "obj.status", INT, 10, { "obj.status", INT, 10,
"VRT_r_obj_status(sp)", "VRT_r_obj_status(sp)",
...@@ -126,7 +126,7 @@ struct var vcc_vars[] = { ...@@ -126,7 +126,7 @@ struct var vcc_vars[] = {
"VRT_r_obj_http_(sp)", "VRT_r_obj_http_(sp)",
"VRT_l_obj_http_(sp, ", "VRT_l_obj_http_(sp, ",
V_RW, V_RW,
VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER VCL_MET_HIT | VCL_MET_FETCH
}, },
{ "obj.valid", BOOL, 9, { "obj.valid", BOOL, 9,
"VRT_r_obj_valid(sp)", "VRT_r_obj_valid(sp)",
...@@ -156,25 +156,25 @@ struct var vcc_vars[] = { ...@@ -156,25 +156,25 @@ struct var vcc_vars[] = {
"VRT_r_resp_proto(sp)", "VRT_r_resp_proto(sp)",
"VRT_l_resp_proto(sp, ", "VRT_l_resp_proto(sp, ",
V_RW, V_RW,
VCL_MET_FETCH VCL_MET_DELIVER
}, },
{ "resp.status", INT, 11, { "resp.status", INT, 11,
"VRT_r_resp_status(sp)", "VRT_r_resp_status(sp)",
"VRT_l_resp_status(sp, ", "VRT_l_resp_status(sp, ",
V_RW, V_RW,
VCL_MET_FETCH VCL_MET_DELIVER
}, },
{ "resp.response", STRING, 13, { "resp.response", STRING, 13,
"VRT_r_resp_response(sp)", "VRT_r_resp_response(sp)",
"VRT_l_resp_response(sp, ", "VRT_l_resp_response(sp, ",
V_RW, V_RW,
VCL_MET_FETCH VCL_MET_DELIVER
}, },
{ "resp.http.", HEADER, 10, { "resp.http.", HEADER, 10,
"VRT_r_resp_http_(sp)", "VRT_r_resp_http_(sp)",
"VRT_l_resp_http_(sp, ", "VRT_l_resp_http_(sp, ",
V_RW, V_RW,
VCL_MET_FETCH VCL_MET_DELIVER
}, },
{ "now", TIME, 3, { "now", TIME, 3,
"VRT_r_now(sp)", "VRT_r_now(sp)",
......
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