Commit 0cc155eb authored by Nils Goroll's avatar Nils Goroll

initial

parents
Makefile
Makefile.in
.deps/
.libs/
*.o
*.lo
*.la
*~
vmod_esicookies.3
/aclocal.m4
/autom4te.cache/
/compile
/config.guess
/config.h
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/missing
/stamp-h1
/m4/
/src/vcc_if.c
/src/vcc_if.h
/vmod_urlcode.3
/nbproject/private/
Copyright (c) 2011 Varnish Software AS
...
See LICENSE for details.
You're free to use and distribute this under terms in the
LICENSE. Please add your relevant copyright statements.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src
EXTRA_DIST = README.rst
dist_man_MANS = vmod_esicookies.3
MAINTAINERCLEANFILES = $(dist_man_MANS)
vmod_esicookies.3: README.rst
if HAVE_RST2MAN
${RST2MAN} README.rst $@
else
@echo "========================================"
@echo "You need rst2man installed to make dist"
@echo "========================================"
@false
endif
===============
vmod_esicookies
===============
-------------------------------------------
Varnish Module for cookie handling with ESI
-------------------------------------------
:Author: Nils Goroll
:Date: 2013-04-21
:Version: 1.0
:Manual section: 3
.. _synopsis:
SYNOPSIS
========
::
import esicookies;
sub vcl_fetch {
esicookies.to_http0(beresp.http.Set-Cookie);
}
# OR
sub vcl_fetch {
set req.http.X-Err = esicookies.to_http0_e(beresp.http.Set-Cookie);
if (req.http.X-Err != "") {
error 503 "Error in to_http0";
}
unset req.http.X-Err;
}
sub vcl_error {
if (req.http.X-Err) {
set obj.http.X-Err = req.http.X-Err;
}
}
DESCRIPTION
===========
This module's special purpose is to add HTTP cookies from ``Set-Cookie``
headers of backend responses to the ``http0`` context which is used as
a template for subsequent ESI requests and rollbacks.
The net effect is that backends can set cookies which will be seen by
other backends for subsequent ESI requests as if the individual ESI
responses' ``Set-Cookie`` headers had reached the browser.
FUNCTIONS
=========
See see synopsis_ for a typical (and the only tested) usage example.
.. _tohttp0:
to_http0
--------
Prototype
::
esicookies.to_http0(HEADER);
The ``http0`` context contains a copy of the original request headers
as requested by the client.
When the ``to_http0`` function is called, all instances of the named
``Set-Cookie`` reponse header and the original request's ``Cookie``
headers are parsed and a new ``Cookie`` header is generated in the
``http0`` context, which will be used for subsequent ESI requests and
after a rollback.
Later ``Set-Cookie`` reponse headers overwrite Cookies present in the
initial ``http0`` context ``Cookie`` headers or earlier ``Set-Cookie``
reponse headers.
to_http0_e
----------
Prototype
::
set ... = esicookies.to_http0_e(HEADER);
if (esicookies.to_http0_e(HEADER) ...)
This form is semantically equivalent to tohttp0_ except that is
returns a non-empty string when an error is encountered.
Possible return strings are:
* "Value too large for defined data type" or your current locale's
translation for ``EOVERFLOW``: too many cookies in use (see
limitations_)
* "new cookies: not even the header name fits"
* "new cookies dont fit": Cookies don't fit into the workspace of size
``HTTP0_WS_SIZE`` (see limitations_)
.. _limitations:
LIMITATIONS
===========
Two compile-time defines limit the number and total size of all
cookies:
* ``HTTP0_WS_SIZE``: workspace for new Cookie Headers, defaults to 4
KB
* ``max_cookies``: Maximum number of cookies, defaults to 180
* Attributes in ``Set-Cookie`` response headers like ``Expires``,
``Domain`` or ``Path`` are currently ignored.
* The Name of the ``Cookie`` header cannot currently be changed.
INSTALLATION
============
The source tree is based on autotools to configure the building, and
does also have the necessary bits in place to do functional unit tests
using the varnishtest tool.
Usage::
./configure VARNISHSRC=DIR [VMODDIR=DIR]
`VARNISHSRC` is the directory of the Varnish source tree for which to
compile your vmod.
Optionally you can also set the vmod install directory by adding
`VMODDIR=DIR` (defaults to the pkg-config discovered directory from your
Varnish installation).
Make targets:
* make - builds the vmod
* make install - installs your vmod in `VMODDIR`
* make check - runs the unit tests in ``src/tests/*.vtc``
HISTORY
=======
Version 1.0: Initial version.
COPYRIGHT
=========
This document is licensed under the same license as the
libvmod-esicookies project. See LICENSE for details.
Copyright (c) 2013 UPLEX Nils Goroll Systemoptimierung. All rights
reserved.
#!/bin/sh
#
# $Id$
#
warn() {
echo "WARNING: $@" 1>&2
}
case `uname -s` in
Darwin)
LIBTOOLIZE=glibtoolize
;;
FreeBSD)
LIBTOOLIZE=libtoolize
;;
Linux)
LIBTOOLIZE=libtoolize
;;
SunOS)
LIBTOOLIZE=libtoolize
;;
*)
warn "unrecognized platform:" `uname -s`
LIBTOOLIZE=libtoolize
esac
automake_version=`automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+'`
if [ -z "$automake_version" ] ; then
warn "unable to determine automake version"
else
case $automake_version in
0.*|1.[0-8]|1.[0-8][.-]*)
warn "automake ($automake_version) detected; 1.9 or newer recommended"
;;
*)
;;
esac
fi
set -ex
aclocal
$LIBTOOLIZE --copy --force
autoheader
automake --add-missing --copy --foreign
autoconf
AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2013 UPLEX - Nils Goroll Systemoptimierung, 2011 Varnish Software AS])
AC_INIT([libvmod-esicookies], [master])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/vmod_esicookies.vcc)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_SYSTEM
AC_LANG(C)
AM_INIT_AUTOMAKE([foreign])
AC_GNU_SOURCE
AC_PROG_CC
AC_PROG_CC_STDC
if test "x$ac_cv_prog_cc_c99" = xno; then
AC_MSG_ERROR([Could not find a C99 compatible compiler])
fi
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
# Check for rst utilities
AC_CHECK_PROGS(RST2MAN, [rst2man rst2man.py], "no")
if test "x$RST2MAN" = "xno"; then
AC_MSG_WARN([rst2man not found - not building man pages])
fi
AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"])
# Check for pkg-config
PKG_PROG_PKG_CONFIG
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([sys/stdlib.h])
# Check for python
AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])])
# Varnish source tree
AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)])
if test "x$VARNISHSRC" = x; then
AC_MSG_ERROR([No Varnish source tree specified])
fi
VARNISHSRC=`cd $VARNISHSRC && pwd`
AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
[],
[AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]
)
# Check that varnishtest is built in the varnish source directory
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
[],
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
)
# vmod installation dir
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
if test "x$VMODDIR" = x; then
VMODDIR=`pkg-config --variable=vmoddir varnishapi`
if test "x$VMODDIR" = x; then
AC_MSG_FAILURE([Can't determine vmod installation directory])
fi
fi
# This corresponds to FreeBSD's WARNS level 6
DEVELOPER_CFLAGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wformat"
# Additional flags for GCC 4
EXTRA_DEVELOPER_CFLAGS="-Wextra -Wno-missing-field-initializers -Wno-sign-compare"
# --enable-developer-warnings
AC_ARG_ENABLE(developer-warnings,
AS_HELP_STRING([--enable-developer-warnings],[enable strict warnings (default is NO)]),
CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}")
# --enable-debugging-symbols
AC_ARG_ENABLE(debugging-symbols,
AS_HELP_STRING([--enable-debugging-symbols],[enable debugging symbols (default is NO)]),
CFLAGS="${CFLAGS} -O0 -g -fno-inline")
# --enable-diagnostics
AC_ARG_ENABLE(diagnostics,
AS_HELP_STRING([--enable-diagnostics],[enable run-time diagnostics (default is NO)]),
CFLAGS="${CFLAGS} -DDIAGNOSTICS")
# --enable-extra-developer-warnings
AC_ARG_ENABLE(extra-developer-warnings,
AS_HELP_STRING([--enable-extra-developer-warnings],[enable even stricter warnings (default is NO)]),
[],
[enable_extra_developer_warnings=no])
if test "x$enable_stack_protector" != "xno"; then
save_CFLAGS="$CFLAGS"
CFLAGS="${CFLAGS} ${EXTRA_DEVELOPER_CFLAGS}"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([],[],[])],
[],
[AC_MSG_WARN([All of ${EXTRA_DEVELOPER_CFLAGS} not supported, disabling])
CFLAGS="$save_CFLAGS"])
fi
# --enable-stack-protector
AC_ARG_ENABLE(stack-protector,
AS_HELP_STRING([--enable-stack-protector],[enable stack protector (default is NO)]),
[],
[enable_stack_protector=no])
if test "x$enable_stack_protector" != "xno"; then
save_CFLAGS="$CFLAGS"
CFLAGS="${CFLAGS} -fstack-protector-all"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([],[],[])],
[],
[AC_MSG_WARN([-fstack-protector not supported, disabling])
CFLAGS="$save_CFLAGS"])
fi
# --enable-tests
AC_ARG_ENABLE(tests,
AS_HELP_STRING([--enable-tests],[build test programs (default is NO)]))
AM_CONDITIONAL([ENABLE_TESTS], [test x$enable_tests = xyes])
# --enable-werror
AC_ARG_ENABLE(werror,
AS_HELP_STRING([--enable-werror],[use -Werror (default is NO)]),
CFLAGS="${CFLAGS} -Werror")
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT
AM_CPPFLAGS = \
-I$(VARNISHSRC)/include \
-I$(VARNISHSRC)/bin/varnishd
AM_LDFLAGS = $(AM_LT_LDFLAGS)
vmoddir = $(VMODDIR)
vmod_LTLIBRARIES = libvmod_esicookies.la
vmod_srcdir = $(top_srcdir)/src
vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
libvmod_esicookies_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared
libvmod_esicookies_la_SOURCES = \
vmod_esicookies.c
nodist_libvmod_esicookies_la_SOURCES = \
vcc_if.c \
vcc_if.h
# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
vmod_esicookies.lo: vcc_if.h
vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod_esicookies.vcc
@PYTHON@ $(vmodtool) $(vmod_srcdir)/vmod_esicookies.vcc
VMOD_TESTS = tests/*.vtc
check: $(VARNISHSRC)/bin/varnishtest/varnishtest
$(VARNISHSRC)/bin/varnishtest/varnishtest \
-Dvarnishd=$(VARNISHSRC)/bin/varnishd/varnishd \
-Dvmod_topbuild=$(abs_top_builddir) \
tests/*.vtc
EXTRA_DIST = \
vmod_esicookies.vcc \
$(VMOD_TESTS)
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
varnishtest "test vmod_esicookies"
server s1 {
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
<esi:include src="/body2"/>
After include 2
<esi:include src="/body3"/>
After include 3
<esi:include src="/body4"/>
After include 4
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
-hdr "Set-Cookie: fromserver1=2; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly" \
-body {
Included file
}
rxreq
expect req.url == "/body2"
expect req.http.Cookie == "fromclient=1; frombody1=1; fromserver1=2"
txresp -hdr "Set-Cookie: a=1" \
-hdr "Set-Cookie: b =2" \
-hdr "Set-Cookie: c= 3" \
-hdr "Set-Cookie: d=4 " \
-hdr "Set-Cookie: e=5 ; foobar" \
-hdr "Set-Cookie: f= 3; foobar" \
-body {
Included file
}
rxreq
expect req.url == "/body3"
expect req.http.Cookie == "fromclient=1; frombody1=1; fromserver1=2; a=1; b=2; c=3; d=4; e=5; f=3"
txresp -body {
Included file
}
rxreq
expect req.url == "/body4"
txresp -body {
Included file
}
} -start
varnish v1 -vcl+backend {
import esicookies from "${vmod_topbuild}/src/.libs/libvmod_esicookies.so" ;
sub vcl_fetch {
if (req.url == "/body2") {
esicookies.to_http0(beresp.http.Set-Cookie);
} else {
set req.http.X-Err = esicookies.to_http0_e(beresp.http.Set-Cookie);
if (req.http.X-Err != "") {
error 503 "Error in to_http0";
}
unset req.http.X-Err;
}
set beresp.do_esi = true;
}
sub vcl_error {
if (req.http.X-Err) {
set obj.http.X-Err = req.http.X-Err;
}
}
} -start
client c1 {
txreq -url "/" -hdr "Cookie: fromclient=1"
rxresp
} -run
This diff is collapsed.
#-
# Copyright (c) 2010-2011 Varnish Software AS
# All rights reserved.
#
# Author: Poul-Henning Kamp <phk@FreeBSD.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
Module esicookies
Init init_function
Function STRING to_http0_e(PRIV_VCL, HEADER)
Function VOID to_http0(PRIV_VCL, HEADER)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment