Skip to content

Commit 807dbe0

Browse files
authored
Merge pull request #416 from FriendsOfSymfony/custom-ttl-no-inline-c
no inline C needed for custom TTL
2 parents 9c9afe9 + a4b5f1d commit 807dbe0

File tree

4 files changed

+14
-31
lines changed

4 files changed

+14
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
1212
* Added support for the more efficient xkey cache tag system. BAN remains the
1313
default cache tagging system, but if you can install the varnish modules in
1414
your system, it is recommended to update to xkey.
15+
* No inline C is needed for the custom TTL header with Varnish 4 or better. use
16+
`std.duration()` instead.
1517

1618
### Symfony user context
1719
* You can now also specify which headers are used for

doc/varnish-configuration.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ Custom TTL
384384
.. include:: includes/custom-ttl.rst
385385

386386
Subroutines are provided in ``resources/config/varnish-[version]/fos_custom_ttl.vcl``.
387-
The configuration needs to use inline C, which is disabled by default since
388-
Varnish 4.0. To use the custom TTL feature, you need to start your Varnish with
389-
inline C enabled: ``-p vcc_allow_inline_c=on``. Then add the following to
390-
``your_varnish.vcl``:
387+
Add the following to ``your_varnish.vcl``:
391388

392389
.. configuration-block::
393390

@@ -409,6 +406,14 @@ inline C enabled: ``-p vcc_allow_inline_c=on``. Then add the following to
409406
410407
The custom TTL header is removed before sending the response to the client.
411408

409+
.. note::
410+
411+
If you are using Varnish 3, this feature is using inline C. Inline C is
412+
enabled for Varnish 3 by default. Check for the ``vcc_allow_inline_c``
413+
setting.
414+
If you are using Varnish 4 or newer, you are using the
415+
``varnish/fos_custom_ttl.vcl`` which uses a vmod function instead of inline C.
416+
412417
.. _varnish_debugging:
413418

414419
Debugging

resources/config/varnish/fos_custom_ttl.vcl

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,16 @@
66
* For the full copyright and license information, please view the LICENSE
77
* file that was distributed with this source code.
88
*/
9-
C{
10-
#include <stdlib.h>
11-
}C
9+
10+
import std;
1211

1312
/**
1413
* Read a custom TTL header for the time to live information, to be used
1514
* instead of s-maxage.
1615
*/
1716
sub fos_custom_ttl_backend_response {
1817
if (beresp.http.X-Reverse-Proxy-TTL) {
19-
/*
20-
* Note that there is a ``beresp.ttl`` field in VCL but unfortunately
21-
* it can only be set to absolute values and not dynamically. Thus we
22-
* have to resort to an inline C code fragment.
23-
*
24-
* As of Varnish 4.0, inline C is disabled by default. To use this
25-
* feature, you need to add `-p vcc_allow_inline_c=on` to your Varnish
26-
* startup command.
27-
*/
28-
C{
29-
const char *ttl;
30-
const struct gethdr_s hdr = { HDR_BERESP, "\024X-Reverse-Proxy-TTL:" };
31-
ttl = VRT_GetHdr(ctx, &hdr);
32-
VRT_l_beresp_ttl(ctx, atoi(ttl));
33-
}C
34-
18+
set beresp.ttl = std.duration(beresp.http.X-Reverse-Proxy-TTL + "s", 0s);
3519
unset beresp.http.X-Reverse-Proxy-TTL;
3620
}
3721
}

tests/Functional/Varnish/CustomTtlTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
*/
2020
class CustomTtlTest extends VarnishTestCase
2121
{
22-
public function setUp()
23-
{
24-
if ($this->getVarnishVersion() >= 4) {
25-
$this->getProxy()->setAllowInlineC(true);
26-
}
27-
parent::setUp();
28-
}
29-
3022
protected function getConfigFile()
3123
{
3224
switch ((int) $this->getVarnishVersion()) {

0 commit comments

Comments
 (0)