[master] b5d0779 Make discarding the request body a dedicated function, since we may be able to orderly terminate/prevent the transmission in future protocols.
Poul-Henning Kamp
phk at varnish-cache.org
Tue Jan 15 15:44:02 CET 2013
commit b5d07794ba931d75f98f9c186040bac5db1b158c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jan 15 14:43:28 2013 +0000
Make discarding the request body a dedicated function, since
we may be able to orderly terminate/prevent the transmission
in future protocols.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ba9e482..a9af09a 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -778,6 +778,7 @@ void VBO_Free(struct busyobj **vbo);
/* cache_http1_fsm.c [HTTP1] */
ssize_t HTTP1_GetReqBody(struct req *, void *buf, ssize_t len);
+int HTTP1_DiscardReqBody(struct req *req);
void HTTP1_Session(struct worker *, struct req *);
/* cache_req_fsm.c [CNT] */
@@ -815,7 +816,6 @@ int FetchError(struct busyobj *, const char *error);
int FetchError2(struct busyobj *, const char *error, const char *more);
int FetchHdr(struct req *req, int need_host_hdr, int sendbody);
void FetchBody(struct worker *w, void *bo);
-int FetchReqBody(struct req *, int sendbody);
void Fetch_Init(void);
/* cache_gzip.c */
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 50a654c..b8ab6ca 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -44,6 +44,8 @@
static unsigned fetchfrag;
+static int fetchReqBody(struct req *req, int sendbody);
+
/*--------------------------------------------------------------------
* We want to issue the first error we encounter on fetching and
* supress the rest. This function does that.
@@ -377,8 +379,8 @@ fetch_eof(struct busyobj *bo, struct http_conn *htc)
* to contain the complexity when we start handling chunked encoding.
*/
-int
-FetchReqBody(struct req *req, int sendbody)
+static int
+fetchReqBody(struct req *req, int sendbody)
{
char buf[8192];
ssize_t l = 1234;
@@ -467,7 +469,7 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody)
(void)http_Write(wrk, hp, 0); /* XXX: stats ? */
/* Deal with any message-body the request might have */
- i = FetchReqBody(req, sendbody);
+ i = fetchReqBody(req, sendbody);
if (sendbody && req->req_body_status == REQ_BODY_DONE)
retry = -1;
if (WRW_FlushRelease(wrk) || i > 0) {
diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c
index c9b8d8f..3696081 100644
--- a/bin/varnishd/cache/cache_http1_fsm.c
+++ b/bin/varnishd/cache/cache_http1_fsm.c
@@ -375,6 +375,27 @@ HTTP1_Session(struct worker *wrk, struct req *req)
}
}
+/*
+ * XXX: DiscardReqBody() is a dedicated function, because we might
+ * XXX: be able to disuade or terminate its transmission in some protocols.
+ */
+
+int
+HTTP1_DiscardReqBody(struct req *req)
+{
+ char buf[8192];
+ ssize_t l;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ while (req->req_body_status != REQ_BODY_DONE &&
+ req->req_body_status != REQ_BODY_NONE) {
+ l = HTTP1_GetReqBody(req, buf, sizeof buf);
+ if (l < 0)
+ return (-1);
+ }
+ return (0);
+}
+
ssize_t
HTTP1_GetReqBody(struct req *req, void *buf, ssize_t len)
{
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index fe76777..3d5693d 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -727,7 +727,7 @@ cnt_hit(struct worker *wrk, struct req *req)
if (req->handling == VCL_RET_DELIVER) {
//AZ(req->busyobj->bereq->ws);
//AZ(req->busyobj->beresp->ws);
- (void)FetchReqBody(req, 0);
+ (void)HTTP1_DiscardReqBody(req); // XXX: handle err
req->req_step = R_STP_PREPRESP;
return (0);
}
More information about the varnish-commit
mailing list