Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-selector
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-selector
Commits
aef01728
Commit
aef01728
authored
Oct 04, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the element enum to .backend().
parent
a3c8b99b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
10 deletions
+68
-10
README.rst
README.rst
+3
-2
backend.vtc
src/tests/backend.vtc
+50
-0
vmod_selector.c
src/vmod_selector.c
+14
-7
vmod_selector.vcc
src/vmod_selector.vcc
+1
-1
No files found.
README.rst
View file @
aef01728
...
...
@@ -720,13 +720,14 @@ Example::
.. _xset.backend():
BACKEND xset.backend(INT n, ENUM select)
----------------------------------------
BACKEND xset.backend(INT n,
STRING element,
ENUM select)
----------------------------------------
----------------
::
BACKEND xset.backend(
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
...
...
src/tests/backend.vtc
View file @
aef01728
...
...
@@ -48,6 +48,17 @@ varnish v1 -vcl {
set resp.http.Backend-Longest
= s.backend(select=LONGEST);
}
set resp.http.Foo = s.backend(element="foo");
set resp.http.Bar = s.backend(element="bar");
set resp.http.Baz = s.backend(element="baz");
set resp.http.Quux = s.backend(element="quux");
set resp.http.Foobar = s.backend(element="foobar");
if (req.http.Element) {
set resp.http.Element
= s.backend(element=req.http.Element);
}
return (deliver);
}
} -start
...
...
@@ -62,6 +73,12 @@ client c1 {
expect resp.http.N-4 == "b4"
expect resp.http.N-5 == "b5"
expect resp.http.Foo == "b1"
expect resp.http.Bar == "b2"
expect resp.http.Baz == "b3"
expect resp.http.Quux == "b4"
expect resp.http.Foobar == "b5"
txreq -hdr "Word: foo"
rxresp
expect resp.status == 200
...
...
@@ -128,6 +145,11 @@ client c1 {
expect_close
} -run
client c1 {
txreq -hdr "Element: oof"
expect_close
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.backend\(\) called without prior match$}
...
...
@@ -138,6 +160,11 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect * = VCL_Error {^vmod selector failure: s\.backend\(6\): set has 5 elements$}
expect * = VCL_return fail
expect * = End
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.backend\(element="oof"\): no such element$}
expect * = VCL_return fail
expect * = End
} -run
varnish v1 -vcl {
...
...
@@ -185,6 +212,18 @@ varnish v1 -vcl {
set resp.http.Backend-Longest
= s.backend(select=LONGEST);
}
if (req.http.Element) {
set resp.http.Element
= s.backend(element=req.http.Element);
set resp.http.Element-Unique = s.backend(select=UNIQUE);
set resp.http.Element-Exact = s.backend(select=EXACT);
set resp.http.Element-First = s.backend(select=FIRST);
set resp.http.Element-Last = s.backend(select=LAST);
set resp.http.Element-Shortest
= s.backend(select=SHORTEST);
set resp.http.Element-Longest
= s.backend(select=LONGEST);
}
return (deliver);
}
}
...
...
@@ -244,6 +283,17 @@ client c1 {
expect resp.http.Backend-Last == "b4"
expect resp.http.Backend-Shortest == "b4"
expect resp.http.Backend-Longest == "b3"
txreq -hdr "Element: foo"
rxresp
expect resp.status == 200
expect resp.http.Element == "b4"
expect resp.http.Element-Unique == "b4"
expect resp.http.Element-Exact == "b4"
expect resp.http.Element-First == "b4"
expect resp.http.Element-Last == "b4"
expect resp.http.Element-Shortest == "b4"
expect resp.http.Element-Longest == "b4"
} -run
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
...
...
src/vmod_selector.c
View file @
aef01728
...
...
@@ -696,7 +696,8 @@ vmod_set_which(VRT_CTX, struct vmod_selector_set *set, VCL_ENUM selects)
static
unsigned
get_idx
(
VRT_CTX
,
VCL_INT
n
,
const
struct
vmod_selector_set
*
const
restrict
set
,
const
char
*
const
restrict
method
,
VCL_ENUM
const
restrict
selects
)
const
char
*
const
restrict
method
,
VCL_STRING
const
restrict
element
,
VCL_ENUM
const
restrict
selects
)
{
struct
match_data
*
match
;
...
...
@@ -708,6 +709,12 @@ get_idx(VRT_CTX, VCL_INT n, const struct vmod_selector_set * const restrict set,
}
return
(
n
-
1
);
}
if
(
element
!=
NULL
)
if
(
!
vmod_set_match
(
ctx
,
TRUST_ME
(
set
),
element
))
{
VFAIL
(
ctx
,
"%s.%s(element=
\"
%s
\"
): no such element"
,
set
->
vcl_name
,
method
,
element
);
return
(
UINT_MAX
);
}
match
=
get_existing_match_data
(
ctx
,
set
,
method
);
if
(
match
==
NULL
||
match
->
n
==
0
)
...
...
@@ -724,7 +731,7 @@ vmod_set_element(VRT_CTX, struct vmod_selector_set *set, VCL_INT n,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"element"
,
selects
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"element"
,
NULL
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
NULL
);
return
(
set
->
members
[
idx
]);
...
...
@@ -746,7 +753,7 @@ check_added(VRT_CTX, const struct vmod_selector_set * const restrict set,
VCL_BACKEND
vmod_set_backend
(
VRT_CTX
,
struct
vmod_selector_set
*
set
,
VCL_INT
n
,
VCL_ENUM
selects
)
VCL_
STRING
element
,
VCL_
ENUM
selects
)
{
unsigned
idx
;
VCL_BACKEND
b
;
...
...
@@ -754,7 +761,7 @@ vmod_set_backend(VRT_CTX, struct vmod_selector_set *set, VCL_INT n,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"backend"
,
selects
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"backend"
,
element
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
NULL
);
if
(
!
check_added
(
ctx
,
set
,
idx
,
BACKEND
,
"backend"
,
"backend"
))
...
...
@@ -775,7 +782,7 @@ vmod_set_string(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"string"
,
selects
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"string"
,
NULL
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
NULL
);
if
(
!
check_added
(
ctx
,
set
,
idx
,
STRING
,
"string"
,
"string"
))
...
...
@@ -795,7 +802,7 @@ vmod_set_integer(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"integer"
,
selects
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"integer"
,
NULL
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
0
);
if
(
!
check_added
(
ctx
,
set
,
idx
,
INTEGER
,
"integer"
,
"integer"
))
...
...
@@ -815,7 +822,7 @@ get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
method
,
selects
);
idx
=
get_idx
(
ctx
,
n
,
set
,
method
,
NULL
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
NULL
);
if
(
!
check_added
(
ctx
,
set
,
idx
,
REGEX
,
method
,
"regex"
))
...
...
src/vmod_selector.vcc
View file @
aef01728
...
...
@@ -653,7 +653,7 @@ Example::
set resp.http.Location = "http://other.com" + myset.element();
}
$Method BACKEND .backend(INT n=0,
$Method BACKEND .backend(INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment