-
Notifications
You must be signed in to change notification settings - Fork 75
/
access_log_variables.t
127 lines (89 loc) · 2.68 KB
/
access_log_variables.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl
# (C) Andrey Zelenkov
# (C) Nginx, Inc.
# Tests for log module variables.
###############################################################################
use warnings;
use strict;
use Test::More;
BEGIN { use FindBin; chdir($FindBin::Bin); }
use lib 'lib';
use Test::Nginx;
###############################################################################
select STDERR; $| = 1;
select STDOUT; $| = 1;
my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(6)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
daemon off;
events {
}
http {
%%TEST_GLOBALS_HTTP%%
log_format time_iso8601 '$uri $time_iso8601';
log_format time_local '$uri $time_local';
log_format msec '$uri $msec';
log_format request '$uri $status $request_length $request_time';
log_format bytes '$uri $bytes_sent $body_bytes_sent';
log_format pipe '$uri $pipe';
server {
listen 127.0.0.1:8080;
server_name localhost;
location /iso8601 {
access_log %%TESTDIR%%/iso8601.log time_iso8601;
return 200;
}
location /local {
access_log %%TESTDIR%%/local.log time_local;
return 200;
}
location /msec {
access_log %%TESTDIR%%/msec.log msec;
return 200;
}
location /request {
access_log %%TESTDIR%%/request.log request;
return 200;
}
location /bytes {
access_log %%TESTDIR%%/bytes.log bytes;
return 200 OK;
}
location /pipe {
access_log %%TESTDIR%%/pipe.log pipe;
return 200;
}
}
}
EOF
$t->run();
###############################################################################
http_get('/iso8601');
http_get('/local');
http_get('/msec');
http_get('/request');
my $bytes_sent = length http_get('/bytes');
# pipelined requests
http(<<EOF);
GET /pipe HTTP/1.1
Host: localhost
GET /pipe HTTP/1.1
Host: localhost
Connection: close
EOF
$t->stop();
my $log = $t->read_file('iso8601.log');
like($log, qr!/iso8601 \d{4}-\d\d-\d\dT\d\d:\d\d:\d\d[+-]\d\d:\d\d!,
'time_iso8601');
$log = $t->read_file('local.log');
like($log, qr!/local \d\d/[A-Z][a-z]{2}/\d{4}:\d\d:\d\d:\d\d [+-]\d{4}!,
'time_local');
$log = $t->read_file('msec.log');
like($log, qr!/msec [\d\.]+!, 'msec');
$log = $t->read_file('request.log');
like($log, qr!/request 200 39 [\d\.]+!, 'request');
$log = $t->read_file('bytes.log');
is($log, "/bytes $bytes_sent 2\n", 'bytes sent');
$log = $t->read_file('pipe.log');
is($log, "/pipe .\n/pipe p\n", 'pipe');
###############################################################################