Skip to content

Commit df320e3

Browse files
committed
Initial vmod_urlcode commit
1 parent b7de64f commit df320e3

11 files changed

+249
-95
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ Makefile.in
2727

2828
/src/vcc_if.c
2929
/src/vcc_if.h
30+
/vmod_urlcode.3

Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ SUBDIRS = src
44

55
EXTRA_DIST = README.rst
66

7-
dist_man_MANS = vmod_example.3
7+
dist_man_MANS = vmod_urlcode.3
88
MAINTAINERCLEANFILES = $(dist_man_MANS)
99

10-
vmod_example.3: README.rst
10+
vmod_urlcode.3: README.rst
1111
if HAVE_RST2MAN
1212
${RST2MAN} README.rst $@
1313
else

README.rst

+48-27
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,80 @@ vmod_example
66
Varnish Example Module
77
----------------------
88

9-
:Author: Martin Blix Grydeland
10-
:Date: 2011-05-26
9+
:Author: Rogier "DocWilco" Mulhuijzen
10+
:Date: 2012-02-15
1111
:Version: 1.0
1212
:Manual section: 3
1313

1414
SYNOPSIS
1515
========
1616

17-
import example;
17+
::
18+
19+
import urlcode;
20+
urlcode.encode(<string>);
21+
urlcode.decode(<string>);
1822

1923
DESCRIPTION
2024
===========
2125

22-
Example Varnish vmod demonstrating how to write an out-of-tree Varnish vmod.
26+
Varnish Module (vmod) for encoding or decoding to/from "percent encoding" as
27+
per RFC3986.
2328

24-
Implements the traditional Hello World as a vmod.
29+
For backward compatibility, a + will be decoded to a space.
2530

2631
FUNCTIONS
2732
=========
2833

29-
hello
30-
-----
34+
Example VCL::
35+
36+
backend foo { ... };
37+
38+
import urlcode;
39+
40+
sub vcl_recv {
41+
set req.url = "/example?url=" + urlcode.encode("http://" +
42+
req.http.host + req.url);
43+
}
44+
45+
encode
46+
------
3147

3248
Prototype
3349
::
3450

35-
hello(STRING S)
51+
urlcode.encode(STRING input)
52+
3653
Return value
3754
STRING
3855
Description
39-
Returns "Hello, " prepended to S
56+
Returns a percent encoded version of input.
4057
Example
58+
::
59+
60+
set resp.http.foo = urlcode.encode("hello world!");
61+
62+
decode
63+
------
64+
65+
Prototype
4166
::
4267

43-
set resp.http.hello = example.hello("World");
68+
urlcode.decode(STRING input)
69+
70+
Return value
71+
STRING
72+
Description
73+
Returns a percent decoded version of input.
74+
Example
75+
::
76+
77+
set resp.http.foo = urlcode.decode("hello%20world%21");
78+
4479

4580
INSTALLATION
4681
============
4782

48-
This is an example skeleton for developing out-of-tree Varnish
49-
vmods. It implements the "Hello, World!" as a vmod callback. Not
50-
particularly useful in good hello world tradition, but demonstrates how
51-
to get the glue around a vmod working.
52-
5383
The source tree is based on autotools to configure the building, and
5484
does also have the necessary bits in place to do functional unit tests
5585
using the varnishtest tool.
@@ -72,25 +102,16 @@ Make targets:
72102
* make install - installs your vmod in `VMODDIR`
73103
* make check - runs the unit tests in ``src/tests/*.vtc``
74104

75-
In your VCL you could then use this vmod along the following lines::
76-
77-
import example;
78-
79-
sub vcl_deliver {
80-
# This sets resp.http.hello to "Hello, World"
81-
set resp.http.hello = example.hello("World");
82-
}
83105

84106
HISTORY
85107
=======
86108

87-
This manual page was released as part of the libvmod-example package,
88-
demonstrating how to create an out-of-tree Varnish vmod.
109+
Version 0.1: Initial version.
89110

90111
COPYRIGHT
91112
=========
92113

93114
This document is licensed under the same license as the
94-
libvmod-example project. See LICENSE for details.
115+
libvmod-urlcode project. See LICENSE for details.
95116

96-
* Copyright (c) 2011 Varnish Software
117+
* Copyright (c) 2012 Fastly Inc.

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
AC_PREREQ(2.59)
22
AC_COPYRIGHT([Copyright (c) 2011 Varnish Software AS])
3-
AC_INIT([libvmod-example], [trunk])
3+
AC_INIT([libvmod-urlcode], [master])
44
AC_CONFIG_MACRO_DIR([m4])
5-
AC_CONFIG_SRCDIR(src/vmod_example.vcc)
5+
AC_CONFIG_SRCDIR(src/vmod_urlcode.vcc)
66
AM_CONFIG_HEADER(config.h)
77

88
AC_CANONICAL_SYSTEM

src/Makefile.am

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
22

33
vmoddir = $(VMODDIR)
4-
vmod_LTLIBRARIES = libvmod_example.la
4+
vmod_LTLIBRARIES = libvmod_urlcode.la
55

6-
libvmod_example_la_LDFLAGS = -module -export-dynamic -avoid-version
6+
libvmod_urlcode_la_LDFLAGS = -module -export-dynamic -avoid-version
77

8-
libvmod_example_la_SOURCES = \
8+
libvmod_urlcode_la_SOURCES = \
99
vcc_if.c \
1010
vcc_if.h \
11-
vmod_example.c
11+
vmod_urlcode.c
1212

13-
vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_example.vcc
14-
@PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_example.vcc
13+
vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_urlcode.vcc
14+
@PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_urlcode.vcc
1515

1616
VMOD_TESTS = tests/*.vtc
1717
.PHONY: $(VMOD_TESTS)
@@ -22,7 +22,7 @@ tests/*.vtc:
2222
check: $(VMOD_TESTS)
2323

2424
EXTRA_DIST = \
25-
vmod_example.vcc \
25+
vmod_urlcode.vcc \
2626
$(VMOD_TESTS)
2727

2828
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h

src/tests/test01.vtc

-22
This file was deleted.

src/tests/urlcode01.vtc

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
varnishtest "Test urlcode vmod"
2+
3+
server s1 {
4+
rxreq
5+
txresp -hdr "Foo1: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_~" \
6+
-hdr "Foo2: `!@#$%^&*()+={}[]:;'\\|<>,?/ \"" \
7+
-hdr "Foo3: hello" \
8+
-hdr "Foo4: world" \
9+
-hdr "Foo5: %2" \
10+
-hdr "Foo6: %" \
11+
-hdr "Foo7: +" \
12+
-hdr "Connection: close" \
13+
-body "Hi!\n"
14+
} -start
15+
16+
varnish v1 -vcl+backend {
17+
import urlcode from "${vmod_topbuild}/src/.libs/libvmod_urlcode.so";
18+
19+
sub vcl_fetch {
20+
set beresp.http.Bar1 = urlcode.encode(beresp.http.Foo1);
21+
set beresp.http.Baz1 = urlcode.decode(beresp.http.Bar1);
22+
set beresp.http.Bar2 = urlcode.encode(beresp.http.Foo2);
23+
set beresp.http.Baz2 = urlcode.decode(beresp.http.Bar2);
24+
set beresp.http.Bar3 = urlcode.encode(beresp.http.Foo3 + " "
25+
+ beresp.http.Foo4) + "!";
26+
set beresp.http.Baz3 = urlcode.decode("hello" + beresp.http.Foo5
27+
+ "0world") + "!";
28+
set beresp.http.Baz4 = urlcode.decode("hello" + beresp.http.Foo6
29+
+ "20world") + "!";
30+
set beresp.http.Baz5 = urlcode.decode("hello" + beresp.http.Foo7
31+
+ "world") + "!";
32+
set beresp.http.Bar6 = urlcode.encode("hello"
33+
+ beresp.http.nonexistant + "world") + "!";
34+
set beresp.http.Baz6 = urlcode.decode("hello"
35+
+ beresp.http.nonexistant + "world") + "!";
36+
}
37+
} -start
38+
39+
client c1 {
40+
txreq -url "/"
41+
rxresp
42+
expect resp.status == 200
43+
expect resp.http.X-Varnish == "1001"
44+
expect resp.http.foo1 == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_~"
45+
expect resp.http.bar1 == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_~"
46+
expect resp.http.baz1 == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_~"
47+
expect resp.http.foo2 == "`!@#$%^&*()+={}[]:;'\\|<>,?/ \""
48+
expect resp.http.bar2 == "%60%21%40%23%24%25%5E%26%2A%28%29%2B%3D%7B%7D%5B%5D%3A%3B%27%5C%7C%3C%3E%2C%3F%2F%20%22"
49+
expect resp.http.baz2 == "`!@#$%^&*()+={}[]:;'\\|<>,?/ \""
50+
expect resp.http.bar3 == "hello%20world!"
51+
expect resp.http.baz3 == "hello world!"
52+
expect resp.http.baz4 == "hello world!"
53+
expect resp.http.baz5 == "hello world!"
54+
expect resp.http.baz6 == "helloworld!"
55+
} -run

src/vmod_example.c

-32
This file was deleted.

src/vmod_example.vcc

-3
This file was deleted.

0 commit comments

Comments
 (0)