diff --git a/.gitignore b/.gitignore index 460224a..39eb92f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile.am b/Makefile.am index 442800f..bc97005 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index eb01902..f6519c0 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) @@ -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 +") diff --git a/src/Makefile.am b/src/Makefile.am index 20a7a6e..754f586 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) $< $@ diff --git a/src/tests/test01.vtc b/src/tests/test01.vtc index b565e94..d95d24b 100644 --- a/src/tests/test01.vtc +++ b/src/tests/test01.vtc @@ -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}"); diff --git a/src/tests/test02.vtc b/src/tests/test02.vtc index 3d6d4c7..825a768 100644 --- a/src/tests/test02.vtc +++ b/src/tests/test02.vtc @@ -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 { @@ -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 { diff --git a/src/tests/test03.vtc b/src/tests/test03.vtc index d084f86..3667de1 100644 --- a/src/tests/test03.vtc +++ b/src/tests/test03.vtc @@ -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) { diff --git a/src/tests/test04.vtc b/src/tests/test04.vtc index fbc7f94..038a11d 100644 --- a/src/tests/test04.vtc +++ b/src/tests/test04.vtc @@ -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)); diff --git a/src/tests/test05.vtc b/src/tests/test05.vtc index faab153..312d0e0 100644 --- a/src/tests/test05.vtc +++ b/src/tests/test05.vtc @@ -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); diff --git a/src/tests/test06.vtc b/src/tests/test06.vtc index 24fa0c9..5398fec 100644 --- a/src/tests/test06.vtc +++ b/src/tests/test06.vtc @@ -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"); diff --git a/src/tests/test07.vtc b/src/tests/test07.vtc index 2cb5a88..f77ecf5 100644 --- a/src/tests/test07.vtc +++ b/src/tests/test07.vtc @@ -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"); diff --git a/src/tests/test08.vtc b/src/tests/test08.vtc index 1776992..c258302 100644 --- a/src/tests/test08.vtc +++ b/src/tests/test08.vtc @@ -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}"); diff --git a/src/tests/test09.vtc b/src/tests/test09.vtc index cd6c54e..234ff9a 100644 --- a/src/tests/test09.vtc +++ b/src/tests/test09.vtc @@ -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); diff --git a/src/tests/test10.vtc b/src/tests/test10.vtc index 15796a2..d94dfa5 100644 --- a/src/tests/test10.vtc +++ b/src/tests/test10.vtc @@ -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(); diff --git a/src/tests/test11.vtc b/src/tests/test11.vtc index 4b37543..53bc17d 100644 --- a/src/tests/test11.vtc +++ b/src/tests/test11.vtc @@ -7,7 +7,7 @@ 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 { @@ -15,8 +15,8 @@ varnish v1 -vcl+backend { 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}"); @@ -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 { diff --git a/src/tests/test12.vtc b/src/tests/test12.vtc index 7549f4d..3c2e8a5 100644 --- a/src/tests/test12.vtc +++ b/src/tests/test12.vtc @@ -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") { diff --git a/src/tests/test13.vtc b/src/tests/test13.vtc index e1e175b..f25f1bd 100644 --- a/src/tests/test13.vtc +++ b/src/tests/test13.vtc @@ -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(); diff --git a/src/tests/test14.vtc b/src/tests/test14.vtc index b484e44..b763677 100644 --- a/src/tests/test14.vtc +++ b/src/tests/test14.vtc @@ -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); diff --git a/src/vmod_curl.c b/src/vmod_curl.c index 946df32..3f33d41 100644 --- a/src/vmod_curl.c +++ b/src/vmod_curl.c @@ -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 @@ -193,7 +193,7 @@ 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; @@ -201,11 +201,17 @@ free_func(void *p) 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) { @@ -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); diff --git a/src/vmod_curl.vcc b/src/vmod_curl.vcc index 062fcdf..3180d7b 100644 --- a/src/vmod_curl.vcc +++ b/src/vmod_curl.vcc @@ -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)