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
041b4574
Commit
041b4574
authored
Jul 15, 2011
by
Tollef Fog Heen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for logging response headers in varnishncsa
parent
3e86cd8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
12 deletions
+46
-12
varnishncsa.c
bin/varnishncsa/varnishncsa.c
+43
-12
varnishncsa.rst
doc/sphinx/reference/varnishncsa.rst
+3
-0
No files found.
bin/varnishncsa/varnishncsa.c
View file @
041b4574
...
...
@@ -103,7 +103,8 @@ static struct logline {
int
active
;
/* Is log line in an active trans */
int
complete
;
/* Is log line complete */
uint64_t
bitmap
;
/* Bitmap for regex matches */
VTAILQ_HEAD
(,
hdr
)
headers
;
VTAILQ_HEAD
(,
hdr
)
req_headers
;
/* Request headers */
VTAILQ_HEAD
(,
hdr
)
resp_headers
;
/* Response headers */
}
**
ll
;
struct
VSM_data
*
vd
;
...
...
@@ -190,10 +191,23 @@ trimline(const char *str, const char *end)
}
static
char
*
get
_header
(
struct
logline
*
l
,
const
char
*
name
)
req
_header
(
struct
logline
*
l
,
const
char
*
name
)
{
struct
hdr
*
h
;
VTAILQ_FOREACH
(
h
,
&
l
->
headers
,
list
)
{
VTAILQ_FOREACH
(
h
,
&
l
->
req_headers
,
list
)
{
if
(
strcasecmp
(
h
->
key
,
name
)
==
0
)
{
return
h
->
value
;
break
;
}
}
return
NULL
;
}
static
char
*
resp_header
(
struct
logline
*
l
,
const
char
*
name
)
{
struct
hdr
*
h
;
VTAILQ_FOREACH
(
h
,
&
l
->
resp_headers
,
list
)
{
if
(
strcasecmp
(
h
->
key
,
name
)
==
0
)
{
return
h
->
value
;
break
;
...
...
@@ -216,8 +230,14 @@ clean_logline(struct logline *lp)
freez
(
lp
->
df_s
);
freez
(
lp
->
df_u
);
freez
(
lp
->
df_ttfb
);
VTAILQ_FOREACH_SAFE
(
h
,
&
lp
->
headers
,
list
,
h2
)
{
VTAILQ_REMOVE
(
&
lp
->
headers
,
h
,
list
);
VTAILQ_FOREACH_SAFE
(
h
,
&
lp
->
req_headers
,
list
,
h2
)
{
VTAILQ_REMOVE
(
&
lp
->
req_headers
,
h
,
list
);
freez
(
h
->
key
);
freez
(
h
->
value
);
freez
(
h
);
}
VTAILQ_FOREACH_SAFE
(
h
,
&
lp
->
resp_headers
,
list
,
h2
)
{
VTAILQ_REMOVE
(
&
lp
->
resp_headers
,
h
,
list
);
freez
(
h
->
key
);
freez
(
h
->
value
);
freez
(
h
);
...
...
@@ -326,7 +346,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
l
=
strlen
(
split
);
h
->
key
=
trimline
(
ptr
,
split
-
1
);
h
->
value
=
trimline
(
split
+
1
,
split
+
l
-
1
);
VTAILQ_INSERT_HEAD
(
&
lp
->
headers
,
h
,
list
);
VTAILQ_INSERT_HEAD
(
&
lp
->
req_
headers
,
h
,
list
);
}
break
;
...
...
@@ -415,10 +435,12 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
lp
->
df_s
=
trimline
(
ptr
,
end
);
break
;
case
SLT_TxHeader
:
case
SLT_RxHeader
:
if
(
!
lp
->
active
)
break
;
if
(
isprefix
(
ptr
,
"authorization:"
,
end
,
&
next
)
&&
if
(
tag
==
SLT_RxHeader
&&
isprefix
(
ptr
,
"authorization:"
,
end
,
&
next
)
&&
isprefix
(
next
,
"basic"
,
end
,
&
next
))
{
free
(
lp
->
df_u
);
lp
->
df_u
=
trimline
(
next
,
end
);
...
...
@@ -431,7 +453,10 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
AN
(
split
);
h
->
key
=
trimline
(
ptr
,
split
);
h
->
value
=
trimline
(
split
+
1
,
end
);
VTAILQ_INSERT_HEAD
(
&
lp
->
headers
,
h
,
list
);
if
(
tag
==
SLT_RxHeader
)
VTAILQ_INSERT_HEAD
(
&
lp
->
req_headers
,
h
,
list
);
else
VTAILQ_INSERT_HEAD
(
&
lp
->
resp_headers
,
h
,
list
);
}
break
;
...
...
@@ -601,10 +626,10 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
*/
VSB_cat
(
os
,
lp
->
df_m
);
VSB_putc
(
os
,
' '
);
if
(
get
_header
(
lp
,
"Host"
))
{
if
(
strncmp
(
get
_header
(
lp
,
"Host"
),
"http://"
,
7
)
!=
0
)
if
(
req
_header
(
lp
,
"Host"
))
{
if
(
strncmp
(
req
_header
(
lp
,
"Host"
),
"http://"
,
7
)
!=
0
)
VSB_cat
(
os
,
"http://"
);
VSB_cat
(
os
,
get
_header
(
lp
,
"Host"
));
VSB_cat
(
os
,
req
_header
(
lp
,
"Host"
));
}
VSB_cat
(
os
,
lp
->
df_U
);
VSB_cat
(
os
,
lp
->
df_q
?
lp
->
df_q
:
""
);
...
...
@@ -659,11 +684,17 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
tmp
++
;
type
=
*
tmp
;
memcpy
(
fname
,
p
+
1
,
tmp
-
p
-
2
);
fname
[
tmp
-
p
-
2
]
=
0
;
}
switch
(
type
)
{
case
'i'
:
h
=
get_header
(
lp
,
fname
);
h
=
req_header
(
lp
,
fname
);
VSB_cat
(
os
,
h
?
h
:
"-"
);
p
=
tmp
;
break
;
case
'o'
:
h
=
resp_header
(
lp
,
fname
);
VSB_cat
(
os
,
h
?
h
:
"-"
);
p
=
tmp
;
break
;
...
...
doc/sphinx/reference/varnishncsa.rst
View file @
041b4574
...
...
@@ -79,6 +79,9 @@ The following options are available:
%q
The query string, if no query string exists, an empty string.
%{X}o
The contents of response header line X.
%r
The first line of the request
...
...
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