Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
1f694f5f
Commit
1f694f5f
authored
Jul 31, 2013
by
Joshua Bussdieker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Word matching working and a few tests
parent
3b589fda
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
128 additions
and
2 deletions
+128
-2
cache_key.c
bin/varnishd/cache/cache_key.c
+48
-2
c10005.vtc
bin/varnishtest/tests/c10005.vtc
+36
-0
c10006.vtc
bin/varnishtest/tests/c10006.vtc
+44
-0
No files found.
bin/varnishd/cache/cache_key.c
View file @
1f694f5f
...
@@ -260,6 +260,24 @@ KEY_Validate(const uint8_t *key)
...
@@ -260,6 +260,24 @@ KEY_Validate(const uint8_t *key)
}
}
}
}
int
word_match
(
char
*
param
,
char
*
string
)
{
char
*
p
=
strstr
(
string
,
param
);
if
(
p
==
0
)
return
0
;
if
(
p
!=
string
)
if
(
p
[
-
1
]
!=
' '
&&
p
[
-
1
]
!=
','
)
return
0
;
char
*
r
=
p
+
strlen
(
param
);
if
(
r
<
string
+
strlen
(
string
))
if
(
r
[
0
]
!=
' '
&&
r
[
0
]
!=
','
)
return
0
;
return
1
;
}
int
int
KEY_Match
(
struct
req
*
req
,
const
uint8_t
*
key
)
KEY_Match
(
struct
req
*
req
,
const
uint8_t
*
key
)
{
{
...
@@ -329,12 +347,40 @@ KEY_Match(struct req *req, const uint8_t *key)
...
@@ -329,12 +347,40 @@ KEY_Match(struct req *req, const uint8_t *key)
// Matcher match
// Matcher match
}
else
if
(
key
[
2
]
==
1
)
{
}
else
if
(
key
[
2
]
==
1
)
{
DEBUG
&&
printf
(
" - Matcher: %s
\n
"
,
key
+
4
);
DEBUG
&&
printf
(
" Header (Matcher): %s
\n
"
,
key
+
4
);
char
*
e
;
unsigned
l
=
vbe16dec
(
key
);
i
=
http_GetHdr
(
req
->
http
,
(
const
char
*
)(
key
+
3
),
&
h
);
// TODO: Perhaps not matcher should allow this
if
(
i
==
0
)
return
0
;
const
char
*
matcher
=
key
+
4
+
key
[
3
]
+
1
;
while
(
*
matcher
!=
0
&&
*
matcher
!=
-
1
)
{
if
(
*
matcher
==
M_WORD
)
{
DEBUG
&&
printf
(
" - Word: %s "
,
matcher
+
1
);
if
(
word_match
(
matcher
+
1
,
h
)
!=
1
)
{
printf
(
"NG
\n
"
);
return
0
;
}
printf
(
"OK
\n
"
);
matcher
+=
strlen
(
matcher
)
+
1
;
}
else
if
(
*
matcher
==
M_CASE
)
{
DEBUG
&&
printf
(
" - Case
\n
"
);
matcher
++
;
}
else
{
DEBUG
&&
printf
(
"UNKNOWN MATCHER (%d)
\n
"
,
*
matcher
);
return
0
;
}
}
}
}
key
+=
key_len
(
key
);
key
+=
key_len
(
key
);
}
}
DEBUG
&&
printf
(
"KEY_Match(req: %p, key: %p) =
0
\n
"
,
req
,
key
);
DEBUG
&&
printf
(
"KEY_Match(req: %p, key: %p) =
1
\n
"
,
req
,
key
);
return
1
;
return
1
;
}
}
bin/varnishtest/tests/c10005.vtc
0 → 100644
View file @
1f694f5f
varnishtest "Test Key matcher functionality (WORD)"
server s1 {
rxreq
expect req.http.foobar == "Foo"
txresp -hdr "Key: Foobar;w=\"Foo\"" -hdr "Snafu: 1" -body "1111\n"
rxreq
expect req.http.foobar == "Bar"
txresp -hdr "Key: Foobar;w=\"Bar\"" -hdr "Snafu: 2" -body "2222\n"
rxreq
expect req.http.foobar == "Foo"
txresp -hdr "Key: Foobar;w=\"Foo\"" -hdr "Snafu: 3" -body "3333\n"
} -start
varnish v1 -vcl+backend {} -start
client c1 {
txreq -hdr "Foobar: Foo"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1001"
expect resp.http.snafu == "1"
txreq -hdr "Foobar: Bar"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1003"
expect resp.http.snafu == "2"
txreq -hdr "Foobar: Foo"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1005 1002"
expect resp.http.snafu == "1"
} -run
bin/varnishtest/tests/c10006.vtc
0 → 100644
View file @
1f694f5f
varnishtest "Test Key matcher functionality (WORD)"
server s1 {
rxreq
expect req.http.foobar == "A B C"
txresp -hdr "Key: Foobar;w=\"A\"" -hdr "Snafu: 1" -body "1111\n"
rxreq
expect req.http.foobar == "CAB"
txresp -hdr "Key: Foobar;w=\"CAB\"" -hdr "Snafu: 2" -body "2222\n"
} -start
varnish v1 -vcl+backend {} -start
client c1 {
txreq -hdr "Foobar: A B C"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1001"
expect resp.http.snafu == "1"
txreq -hdr "Foobar: B C A"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1003 1002"
expect resp.http.snafu == "1"
txreq -hdr "Foobar: C A B"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1004 1002"
expect resp.http.snafu == "1"
txreq -hdr "Foobar: CAB"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1005"
expect resp.http.snafu == "2"
txreq -hdr "Foobar: A CAB RIDE"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1007 1006"
expect resp.http.snafu == "2"
} -run
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