--- /dev/null
+varnishtest "End of a cached response sent using the zero-copy forwarding"
+
+# The H2 origin sends a response without content-length. The end of the
+# message is carried by the last DATA frame (END_STREAM flag). So the cached
+# object ends on a DATA block. The response is large enough to be sent using
+# the zero-copy forwarding when it is served from the cache. HTTP/1.1 clients
+# receive it chunked. The last chunk must be emitted at the end of the
+# message, on a cache miss and on a cache hit.
+
+feature ignore_unknown_macro
+
+barrier b1 cond 2
+
+server s1 {
+ rxpri
+ stream 0 {
+ txsettings
+ rxsettings
+ txsettings -ack
+ } -run
+
+ stream 1 {
+ rxreq
+ txresp -noadd -status 200 -nostrend -hdr "cache-control" "max-age=60"
+ txdata -nostrend -datalen 10000
+ txdata -nostrend -datalen 10000
+ txdata -nostrend -datalen 10000
+ txdata -datalen 10000
+ } -run
+
+ # keep the connection open until the response is received
+ barrier b1 sync
+} -start
+
+haproxy h1 -conf {
+ global
+ .if feature(THREAD)
+ thread-groups 1
+ .endif
+
+ defaults
+ mode http
+ timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
+ timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
+
+ cache my_cache
+ total-max-size 3
+ max-age 60
+ max-object-size 100000
+
+ frontend fe
+ bind "fd@${fe}"
+ http-after-response set-header x-cache-hit %[res.cache_hit]
+ default_backend be
+
+ backend be
+ http-request cache-use my_cache
+ http-response cache-store my_cache
+ server s1 ${s1_addr}:${s1_port} proto h2
+} -start
+
+# cache miss
+client c1 -connect ${h1_fe_sock} {
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-cache-hit == 0
+ expect resp.http.content-length == "<undef>"
+ expect resp.http.transfer-encoding == "chunked"
+ expect resp.bodylen == 40000
+ barrier b1 sync
+} -run
+
+# cache hit
+client c2 -connect ${h1_fe_sock} {
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.http.x-cache-hit == 1
+ expect resp.http.content-length == "<undef>"
+ expect resp.http.transfer-encoding == "chunked"
+ expect resp.bodylen == 40000
+} -run
static size_t http_cache_fastfwd(struct appctx *appctx, struct buffer *buf, size_t count, unsigned int flags)
{
- struct cache_appctx *ctx = appctx->svcctx;
- struct cache_entry *cache_ptr = ctx->entry;
- struct shared_block *first = block_ptr(cache_ptr);
size_t ret;
BUG_ON(!appctx->to_forward || count > appctx->to_forward);
ret = ff_cache_dump_msg(appctx, buf, count);
if (!appctx->to_forward) {
+ /* All the payload was forwarded. The end of the message is
+ * not reported here but by the I/O handler, via the HTX
+ * message, for the consumer to finish the message properly
+ * (for instance the H1 mux must emit the last chunk).
+ */
se_fl_clr(appctx->sedesc, SE_FL_MAY_FASTFWD_PROD);
applet_fl_clr(appctx, APPCTX_FL_FASTFWD);
- if (ctx->sent == first->len - sizeof(*cache_ptr)) {
- applet_set_eoi(appctx);
- applet_set_eos(appctx);
- appctx->st0 = HTX_CACHE_END;
- }
}
return ret;
}