Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
7f7b6d64
Commit
7f7b6d64
authored
Jul 14, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Allow log variable to be enclosed by curly braces
parent
7c301def
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
34 deletions
+93
-34
src/shrpx.cc
src/shrpx.cc
+3
-0
src/shrpx_config.cc
src/shrpx_config.cc
+49
-31
src/shrpx_config_test.cc
src/shrpx_config_test.cc
+41
-3
No files found.
src/shrpx.cc
View file @
7f7b6d64
...
@@ -1407,6 +1407,9 @@ Logging:
...
@@ -1407,6 +1407,9 @@ Logging:
* $ssl_session_reused: "r" if SSL/TLS session was
* $ssl_session_reused: "r" if SSL/TLS session was
reused. Otherwise, "."
reused. Otherwise, "."
The variable can be enclosed by "{" and "}" for
disambiguation (e.g., ${remote_addr}).
Default: )"
<<
DEFAULT_ACCESSLOG_FORMAT
<<
R"(
Default: )"
<<
DEFAULT_ACCESSLOG_FORMAT
<<
R"(
--errorlog-file=<PATH>
--errorlog-file=<PATH>
Set path to write error log. To reopen file, send USR1
Set path to write error log. To reopen file, send USR1
...
...
src/shrpx_config.cc
View file @
7f7b6d64
...
@@ -370,52 +370,69 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
...
@@ -370,52 +370,69 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
++
p
;
++
p
;
for
(;
p
!=
eop
&&
var_token
(
*
p
);
++
p
)
const
char
*
var_name
;
;
size_t
var_namelen
;
if
(
p
!=
eop
&&
*
p
==
'{'
)
{
var_name
=
++
p
;
for
(;
p
!=
eop
&&
var_token
(
*
p
);
++
p
)
;
if
(
p
==
eop
||
*
p
!=
'}'
)
{
LOG
(
WARN
)
<<
"Missing '}' after "
<<
std
::
string
(
var_start
,
p
);
continue
;
}
auto
varlen
=
p
-
var_start
;
var_namelen
=
p
-
var_name
;
++
p
;
}
else
{
var_name
=
p
;
for
(;
p
!=
eop
&&
var_token
(
*
p
);
++
p
)
;
var_namelen
=
p
-
var_name
;
}
auto
type
=
SHRPX_LOGF_NONE
;
auto
type
=
SHRPX_LOGF_NONE
;
const
char
*
value
=
nullptr
;
const
char
*
value
=
nullptr
;
size_t
valuelen
=
0
;
size_t
valuelen
=
0
;
if
(
util
::
strieq_l
(
"
$remote_addr"
,
var_start
,
var
len
))
{
if
(
util
::
strieq_l
(
"
remote_addr"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_REMOTE_ADDR
;
type
=
SHRPX_LOGF_REMOTE_ADDR
;
}
else
if
(
util
::
strieq_l
(
"
$time_local"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
time_local"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_TIME_LOCAL
;
type
=
SHRPX_LOGF_TIME_LOCAL
;
}
else
if
(
util
::
strieq_l
(
"
$time_iso8601"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
time_iso8601"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_TIME_ISO8601
;
type
=
SHRPX_LOGF_TIME_ISO8601
;
}
else
if
(
util
::
strieq_l
(
"
$request"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
request"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_REQUEST
;
type
=
SHRPX_LOGF_REQUEST
;
}
else
if
(
util
::
strieq_l
(
"
$status"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
status"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_STATUS
;
type
=
SHRPX_LOGF_STATUS
;
}
else
if
(
util
::
strieq_l
(
"
$body_bytes_sent"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
body_bytes_sent"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_BODY_BYTES_SENT
;
type
=
SHRPX_LOGF_BODY_BYTES_SENT
;
}
else
if
(
util
::
istartsWith
(
var_
start
,
varlen
,
"$
http_"
))
{
}
else
if
(
util
::
istartsWith
(
var_
name
,
var_namelen
,
"
http_"
))
{
type
=
SHRPX_LOGF_HTTP
;
type
=
SHRPX_LOGF_HTTP
;
value
=
var_
start
+
sizeof
(
"$
http_"
)
-
1
;
value
=
var_
name
+
sizeof
(
"
http_"
)
-
1
;
valuelen
=
var
len
-
(
sizeof
(
"$
http_"
)
-
1
);
valuelen
=
var
_namelen
-
(
sizeof
(
"
http_"
)
-
1
);
}
else
if
(
util
::
strieq_l
(
"
$remote_port"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
remote_port"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_REMOTE_PORT
;
type
=
SHRPX_LOGF_REMOTE_PORT
;
}
else
if
(
util
::
strieq_l
(
"
$server_port"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
server_port"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_SERVER_PORT
;
type
=
SHRPX_LOGF_SERVER_PORT
;
}
else
if
(
util
::
strieq_l
(
"
$request_time"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
request_time"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_REQUEST_TIME
;
type
=
SHRPX_LOGF_REQUEST_TIME
;
}
else
if
(
util
::
strieq_l
(
"
$pid"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
pid"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_PID
;
type
=
SHRPX_LOGF_PID
;
}
else
if
(
util
::
strieq_l
(
"
$alpn"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
alpn"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_ALPN
;
type
=
SHRPX_LOGF_ALPN
;
}
else
if
(
util
::
strieq_l
(
"
$ssl_cipher"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
ssl_cipher"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_SSL_CIPHER
;
type
=
SHRPX_LOGF_SSL_CIPHER
;
}
else
if
(
util
::
strieq_l
(
"
$ssl_protocol"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
ssl_protocol"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_SSL_PROTOCOL
;
type
=
SHRPX_LOGF_SSL_PROTOCOL
;
}
else
if
(
util
::
strieq_l
(
"
$ssl_session_id"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
ssl_session_id"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_SSL_SESSION_ID
;
type
=
SHRPX_LOGF_SSL_SESSION_ID
;
}
else
if
(
util
::
strieq_l
(
"
$ssl_session_reused"
,
var_start
,
var
len
))
{
}
else
if
(
util
::
strieq_l
(
"
ssl_session_reused"
,
var_name
,
var_name
len
))
{
type
=
SHRPX_LOGF_SSL_SESSION_REUSED
;
type
=
SHRPX_LOGF_SSL_SESSION_REUSED
;
}
else
{
}
else
{
LOG
(
WARN
)
<<
"Unrecognized log format variable: "
LOG
(
WARN
)
<<
"Unrecognized log format variable: "
<<
std
::
string
(
var_
start
,
var
len
);
<<
std
::
string
(
var_
name
,
var_name
len
);
continue
;
continue
;
}
}
...
@@ -425,19 +442,20 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
...
@@ -425,19 +442,20 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
strcopy
(
literal_start
,
var_start
-
literal_start
)));
strcopy
(
literal_start
,
var_start
-
literal_start
)));
}
}
literal_start
=
p
;
if
(
value
==
nullptr
)
{
if
(
value
==
nullptr
)
{
res
.
push_back
(
make_log_fragment
(
type
));
res
.
push_back
(
make_log_fragment
(
type
));
}
else
{
continue
;
res
.
push_back
(
make_log_fragment
(
type
,
strcopy
(
value
,
valuelen
)));
auto
&
v
=
res
.
back
().
value
;
for
(
size_t
i
=
0
;
v
[
i
];
++
i
)
{
if
(
v
[
i
]
==
'_'
)
{
v
[
i
]
=
'-'
;
}
}
}
}
literal_start
=
var_start
+
varlen
;
res
.
push_back
(
make_log_fragment
(
type
,
strcopy
(
value
,
valuelen
)));
auto
&
v
=
res
.
back
().
value
;
for
(
size_t
i
=
0
;
v
[
i
];
++
i
)
{
if
(
v
[
i
]
==
'_'
)
{
v
[
i
]
=
'-'
;
}
}
}
}
if
(
literal_start
!=
eop
)
{
if
(
literal_start
!=
eop
)
{
...
...
src/shrpx_config_test.cc
View file @
7f7b6d64
...
@@ -95,9 +95,9 @@ void test_shrpx_config_parse_header(void) {
...
@@ -95,9 +95,9 @@ void test_shrpx_config_parse_header(void) {
}
}
void
test_shrpx_config_parse_log_format
(
void
)
{
void
test_shrpx_config_parse_log_format
(
void
)
{
auto
res
=
parse_log_format
(
"$remote_addr - $remote_user [$time_local]
"
auto
res
=
parse_log_format
(
R"($remote_addr - $remote_user [$time_local] )
"
"
\"
$request
\"
$status $body_bytes_sent
"
R"("$request" $status $body_bytes_sent )
"
"
\"
$http_referer
\"
\"
$http_user_agent
\"
"
);
R"("${http_referer}" "$http_user_agent")
"
);
CU_ASSERT
(
14
==
res
.
size
());
CU_ASSERT
(
14
==
res
.
size
());
CU_ASSERT
(
SHRPX_LOGF_REMOTE_ADDR
==
res
[
0
].
type
);
CU_ASSERT
(
SHRPX_LOGF_REMOTE_ADDR
==
res
[
0
].
type
);
...
@@ -136,6 +136,44 @@ void test_shrpx_config_parse_log_format(void) {
...
@@ -136,6 +136,44 @@ void test_shrpx_config_parse_log_format(void) {
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
13
].
type
);
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
13
].
type
);
CU_ASSERT
(
0
==
strcmp
(
"
\"
"
,
res
[
13
].
value
.
get
()));
CU_ASSERT
(
0
==
strcmp
(
"
\"
"
,
res
[
13
].
value
.
get
()));
res
=
parse_log_format
(
"$"
);
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
0
].
type
);
CU_ASSERT
(
0
==
strcmp
(
"$"
,
res
[
0
].
value
.
get
()));
res
=
parse_log_format
(
"${"
);
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
0
].
type
);
CU_ASSERT
(
0
==
strcmp
(
"${"
,
res
[
0
].
value
.
get
()));
res
=
parse_log_format
(
"${a"
);
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
0
].
type
);
CU_ASSERT
(
0
==
strcmp
(
"${a"
,
res
[
0
].
value
.
get
()));
res
=
parse_log_format
(
"${a "
);
CU_ASSERT
(
1
==
res
.
size
());
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
0
].
type
);
CU_ASSERT
(
0
==
strcmp
(
"${a "
,
res
[
0
].
value
.
get
()));
res
=
parse_log_format
(
"$$remote_addr"
);
CU_ASSERT
(
2
==
res
.
size
());
CU_ASSERT
(
SHRPX_LOGF_LITERAL
==
res
[
0
].
type
);
CU_ASSERT
(
0
==
strcmp
(
"$"
,
res
[
0
].
value
.
get
()));
CU_ASSERT
(
SHRPX_LOGF_REMOTE_ADDR
==
res
[
1
].
type
);
CU_ASSERT
(
nullptr
==
res
[
1
].
value
.
get
());
}
}
void
test_shrpx_config_read_tls_ticket_key_file
(
void
)
{
void
test_shrpx_config_read_tls_ticket_key_file
(
void
)
{
...
...
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