Skip to content

Commit

Permalink
Merge pull request #55 from nigoroll/master
Browse files Browse the repository at this point in the history
Update for current varnish-cache and polish
  • Loading branch information
gquintard authored Nov 20, 2023
2 parents 5a90cd0 + 8cf0345 commit 0f91123
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 72 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Makefile.in
/stamp-h1
/m4/
!/m4/curl.m4
test-driver
src/test-suite.log
src/tests/*.log
src/tests/*.trs

/src/vcc_if.c
/src/vcc_if.h
/src/vcc_curl_if.*
/src/*.rst
/src/*.3
6 changes: 2 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 -I @VARNISHAPI_DATAROOTDIR@/aclocal

ACLOCAL_AMFLAGS = -I m4 -I ${LIBVARNISHAPI_DATAROOTDIR}/aclocal
DISTCHECK_CONFIGURE_FLAGS = RST2MAN=:

SUBDIRS = src

DISTCHECK_CONFIGURE_FLAGS = \
VMOD_DIR='$${libdir}/varnish/vmods'

EXTRA_DIST = README.rst LICENSE CHANGES.rst

doc_DATA = README.rst LICENSE CHANGES.rst
24 changes: 16 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ if test "x$PYTHON" = "xno"; then
AC_MSG_ERROR([Python is needed to build this vmod, please install python.])
fi

# Varnish include files tree
VARNISH_VMOD_INCLUDES
VARNISH_VMOD_DIR
VARNISH_VMODTOOL

AC_PATH_PROG([VARNISHTEST], [varnishtest])
AC_PATH_PROG([VARNISHD], [varnishd], [],
[$PATH:$PATH:`pkg-config varnishapi --variable=sbindir`])
VARNISH_PREREQ([7.3.0])
VARNISH_VMODS([curl])

AX_CURLOPT_CHECK([CURLOPT_TIMEOUT_MS])
AX_CURLOPT_CHECK([CURLOPT_CONNECTTIMEOUT_MS])
Expand All @@ -64,3 +58,17 @@ AC_CONFIG_FILES([
src/Makefile
])
AC_OUTPUT

AS_ECHO("
==== $PACKAGE_STRING ====

varnish: $VARNISH_VERSION
prefix: $prefix
vmoddir: $vmoddir
vcldir: $vcldir
pkgvcldir: $pkgvcldir

compiler: $CC
cflags: $CFLAGS
ldflags: $LDFLAGS
")
60 changes: 28 additions & 32 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
AM_CPPFLAGS = @VMOD_INCLUDES@
AM_CFLAGS = $(VARNISHAPI_CFLAGS)

vmoddir = @VMOD_DIR@
# Modules

vmod_LTLIBRARIES = libvmod_curl.la
libvmod_curl_la_CFLAGS = $(VMOD_INCLUDES) $(CURL_CFLAGS)
libvmod_curl_la_LDFLAGS = -module -export-dynamic -avoid-version -shared \
$(CURL_LIBS)
vmod_LTLIBRARIES = \
libvmod_curl.la

libvmod_curl_la_CFLAGS = $(AM_CFLAGS) $(CURL_CFLAGS)
libvmod_curl_la_LDFLAGS = $(VMOD_LDFLAGS) $(CURL_LIBS)
libvmod_curl_la_SOURCES = \
vcc_if.c \
vcc_if.h \
vmod_curl.c \
debug_flags.h
nodist_libvmod_curl_la_SOURCES = \
vcc_curl_if.c \
vcc_curl_if.h

dist_man_MANS = vmod_curl.3
MAINTAINERCLEANFILES = $(dist_man_MANS)
@BUILD_VMOD_CURL@

vcc_if.c vcc_if.h vmod_curl.man.rst: @VMODTOOL@ $(top_srcdir)/src/vmod_curl.vcc
@VMODTOOL@ $(top_srcdir)/src/vmod_curl.vcc
# Test suite

vmod_curl.3: vmod_curl.man.rst

%.1 %.2 %.3 %.4 %.5 %.6 %.7 %.8 %.9:
if HAVE_RST2MAN
${RST2MAN} $< $@
else
@echo "========================================"
@echo "You need rst2man installed to make dist"
@echo "========================================"
@false
endif

VTC_LOG_COMPILER = $(VARNISHTEST) -v -Dvmod_topbuild=$(abs_top_builddir)
AM_TESTS_ENVIRONMENT = \
PATH="$(abs_builddir):$(VARNISH_TEST_PATH):$(PATH)" \
LD_LIBRARY_PATH="$(VARNISH_LIBRARY_PATH)"
TEST_EXTENSIONS = .vtc
VTC_LOG_COMPILER = varnishtest -lv
AM_VTC_LOG_FLAGS = \
-p vcl_path="$(abs_top_srcdir)/vcl:$(VARNISHAPI_VCLDIR)" \
-p vmod_path="$(abs_builddir)/.libs:$(vmoddir):$(VARNISHAPI_VMODDIR)"
TESTS = @VMOD_TESTS@

EXTRA_DIST = \
# Documentation

dist_doc_DATA = \
vmod_curl.vcc \
$(VMOD_TESTS)
$(TESTS)

dist_man_MANS = \
vmod_curl.3


CLEANFILES = $(builddir)/vcc_if.c \
$(builddir)/vcc_if.h \
$(builddir)/vmod_curl.man.rst \
$(builddir)/vmod_curl.rst \
$(dist_man_MANS)
.rst.1:
$(AM_V_GEN) $(RST2MAN) $< $@
2 changes: 1 addition & 1 deletion src/tests/test01.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_recv {
if (req.http.func == "GET") {
curl.get("http://${s1_addr}:${s1_port}");
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test02.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
import std;

sub vcl_recv {
Expand All @@ -32,7 +32,7 @@ varnish v1 -vcl+backend {

logexpect l1 -v v1 -g request {
expect * 1001 Timestamp {curl:start: \S+ 0\.\d+ 0\.\d+}
expect * = Timestamp {curl:end: \S+ 1\.0\d+ 0\.\d+}
expect * = Timestamp {curl:end: \S+ 1\.0\d+ 1\.0\d+}
} -start

client c1 {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test03.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_deliver {
curl.get("http://localhost:65500");
if (req.restarts < 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test04.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_recv {
curl.get("http://${s1_addr}:${s1_port}");
return (synth(200));
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test05.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_deliver {
set resp.http.x-escaped = curl.escape({"abcd%#=/[]"});
set resp.http.x-unescaped = curl.unescape(resp.http.x-escaped);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test06.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_recv {
if (req.http.extra) {
curl.header_add("extra: 1");
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test07.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_recv {
curl.header_add("foobar: bar");
curl.header_add("foo: bar");
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test08.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_recv {
curl.set_method("PURGE");
curl.head("http://${s1_addr}:${s1_port}");
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test09.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ server s2 -repeat 6 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;

sub vcl_recv {
return (pass);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test10.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
sub vcl_recv {
if (req.http.be == "0") {
curl.header_add_all();
Expand Down
10 changes: 5 additions & 5 deletions src/tests/test11.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ server s1 -repeat 2 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;
import std;

sub vcl_recv {
if (req.url == "/") {
curl.set_timeout(200);
curl.set_connect_timeout(200);
} else {
curl.set_timeout(1300);
curl.set_connect_timeout(1300);
curl.set_timeout(1310);
curl.set_connect_timeout(1310);
}
std.timestamp("curl:start");
curl.get("http://${s1_addr}:${s1_port}");
Expand All @@ -37,10 +37,10 @@ varnish v1 -vcl+backend {

logexpect l1 -v v1 -g request {
expect * 1001 Timestamp {curl:start: \S+ 0\.0\d+ 0\.\d+}
expect * = Timestamp {curl:end: \S+ 0\.2\d+ 0\.\d+}
expect * = Timestamp {curl:end: \S+ 0\.2\d+ 0\.2\d+}

expect * 1002 Timestamp {curl:start: \S+ 0\.\d+ 0\.\d+}
expect * = Timestamp {curl:end: \S+ 1\.3\d+ 0\.\d+}
expect * = Timestamp {curl:end: \S+ 1\.3\d+ 1\.3\d+}
} -start

client c1 {
Expand Down
6 changes: 4 additions & 2 deletions src/tests/test12.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ server s1 {
txresp -body "Te\r\nst"
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
# validate_headers: this test deliberately tests returning line breaks
# in a header. Do not use in production.
varnish v1 -arg "-p feature=-validate_headers" -vcl+backend {
import curl;

sub vcl_recv {
if (req.http.func == "GET") {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test13.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;

sub vcl_recv {
curl.header_add_all();
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test14.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ server s1 {
} -start

varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
import curl;

sub vcl_recv {
curl.set_debug(text);
Expand Down
14 changes: 10 additions & 4 deletions src/vmod_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#endif

#include "vsb.h"
#include "vcc_if.h"
#include "vcc_curl_if.h"

#ifndef VRT_CTX
#define VRT_CTX const struct vrt_ctx *ctx
Expand Down Expand Up @@ -193,19 +193,25 @@ cm_debug(CURL *handle, curl_infotype type, char *data, size_t size,
}

void
free_func(void *p)
free_func(VRT_CTX, void *p)
{
struct vmod_curl *c;

CAST_OBJ_NOTNULL(c, p, VMOD_CURL_MAGIC);

cm_clear_req_headers(c);
cm_clear(c);
VSB_delete(c->body);
VSB_destroy(&c->body);

FREE_OBJ(c);
}

static const struct vmod_priv_methods priv_curl_methods[1] = {{
.magic = VMOD_PRIV_METHODS_MAGIC,
.type = "cURL",
.fini = free_func
}};

static struct vmod_curl *
cm_get(struct vmod_priv *priv)
{
Expand All @@ -215,7 +221,7 @@ cm_get(struct vmod_priv *priv)
ALLOC_OBJ(cm, VMOD_CURL_MAGIC);
cm_init(cm);
priv->priv = cm;
priv->free = free_func;
priv->methods = priv_curl_methods;
} else
CAST_OBJ_NOTNULL(cm, priv->priv, VMOD_CURL_MAGIC);

Expand Down
4 changes: 2 additions & 2 deletions src/vmod_curl.vcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$Module curl 3 cURL bindings for Varnish
$ABI vrt
$Module curl 3 "cURL bindings for Varnish"
$Event event_function
$ABI vrt

# GET the URL in the first parameter
$Function VOID get(PRIV_TASK, STRING)
Expand Down

0 comments on commit 0f91123

Please sign in to comment.