comparison perl.t @ 297:389cee4c78aa

Tests: perl tests for $r->header_in().
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 10 Jun 2013 14:25:07 +0400
parents 484b713f57b0
children e491290fe83a
comparison
equal deleted inserted replaced
296:a113f4d55b12 297:389cee4c78aa
21 ############################################################################### 21 ###############################################################################
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(7) 26 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(13)
27 ->write_file_expand('nginx.conf', <<'EOF'); 27 ->write_file_expand('nginx.conf', <<'EOF');
28 28
29 %%TEST_GLOBALS%% 29 %%TEST_GLOBALS%%
30 30
31 daemon off; 31 daemon off;
52 52
53 return OK if $r->header_only; 53 return OK if $r->header_only;
54 54
55 my $v = $r->variable("testvar"); 55 my $v = $r->variable("testvar");
56 56
57 $r->print("$v"); 57 $r->print("testvar: $v\n");
58
59 $r->print("host: ", $r->header_in("Host"), "\n");
60 $r->print("xfoo: ", $r->header_in("X-Foo"), "\n");
61 $r->print("cookie: ", $r->header_in("Cookie"), "\n");
62 $r->print("xff: ", $r->header_in("X-Forwarded-For"), "\n");
58 63
59 return OK; 64 return OK;
60 }'; 65 }';
61 } 66 }
62 67
90 95
91 ############################################################################### 96 ###############################################################################
92 97
93 like(http_get('/'), qr/TEST/, 'perl response'); 98 like(http_get('/'), qr/TEST/, 'perl response');
94 99
100 # various $r->header_in() cases
101
102 like(http(
103 'GET / HTTP/1.0' . CRLF
104 . 'Host: localhost' . CRLF . CRLF
105 ), qr/host: localhost/, 'perl header_in known');
106
107 like(http(
108 'GET / HTTP/1.0' . CRLF
109 . 'X-Foo: foo' . CRLF
110 . 'Host: localhost' . CRLF . CRLF
111 ), qr/xfoo: foo/, 'perl header_in unknown');
112
113 TODO: {
114 local $TODO = 'broken in 1.3.14';
115
116 like(http(
117 'GET / HTTP/1.0' . CRLF
118 . 'Cookie: foo' . CRLF
119 . 'Host: localhost' . CRLF . CRLF
120 ), qr/cookie: foo/, 'perl header_in cookie');
121
122 like(http(
123 'GET / HTTP/1.0' . CRLF
124 . 'Cookie: foo1' . CRLF
125 . 'Cookie: foo2' . CRLF
126 . 'Host: localhost' . CRLF . CRLF
127 ), qr/cookie: foo1; foo2/, 'perl header_in cookie2');
128
129 like(http(
130 'GET / HTTP/1.0' . CRLF
131 . 'X-Forwarded-For: foo' . CRLF
132 . 'Host: localhost' . CRLF . CRLF
133 ), qr/xff: foo/, 'perl header_in xff');
134
135 like(http(
136 'GET / HTTP/1.0' . CRLF
137 . 'X-Forwarded-For: foo1' . CRLF
138 . 'X-Forwarded-For: foo2' . CRLF
139 . 'Host: localhost' . CRLF . CRLF
140 ), qr/xff: foo1, foo2/, 'perl header_in xff2');
141
142 }
143
144 # various request body tests
145
95 like(http( 146 like(http(
96 'GET /body HTTP/1.0' . CRLF 147 'GET /body HTTP/1.0' . CRLF
97 . 'Host: localhost' . CRLF 148 . 'Host: localhost' . CRLF
98 . 'Content-Length: 10' . CRLF . CRLF 149 . 'Content-Length: 10' . CRLF . CRLF
99 . '1234567890' 150 . '1234567890'