summaryrefslogtreecommitdiff
path: root/echo-nginx-module-0.63/t/echo-after-body.t
blob: 44c4c72571c24d007514cf16b53116498ace1e83 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# vi:filetype=

use lib 'lib';
use Test::Nginx::Socket;

repeat_each(2);

plan tests => repeat_each() * (2 * blocks() + 1);

no_long_string();
log_level('warn');

#master_on();
#workers(1);

run_tests();

__DATA__

=== TEST 1: sanity
--- http_config
    postpone_output 1;
--- config
    location /echo {
        echo_after_body hello;
        echo world;
    }
--- request
    GET /echo
--- response_body
world
hello



=== TEST 2: echo after proxy
--- config
    location /echo {
        echo_after_body hello;
        proxy_pass http://127.0.0.1:$server_port$request_uri/more;
    }
    location /echo/more {
        echo world;
    }
--- request
    GET /echo
--- response_body
world
hello



=== TEST 3: with variables
--- config
    location /echo {
        echo_after_body $request_method;
        echo world;
    }
--- request
    GET /echo
--- response_body
world
GET



=== TEST 4: w/o args
--- config
    location /echo {
        echo_after_body;
        echo world;
    }
--- request
    GET /echo
--- response_body eval
"world\n\n"



=== TEST 5: order is not important
--- config
    location /reversed {
        echo world;
        echo_after_body hello;
    }
--- request
    GET /reversed
--- response_body
world
hello



=== TEST 6: multiple echo_after_body instances
--- config
    location /echo {
        echo_after_body hello;
        echo_after_body world;
        echo !;
    }
--- request
    GET /echo
--- response_body
!
hello
world



=== TEST 7: multiple echo_after_body instances with multiple echo cmds
--- config
    location /echo {
        echo_after_body hello;
        echo_after_body world;
        echo i;
        echo say;
    }
--- request
    GET /echo
--- response_body
i
say
hello
world



=== TEST 8: echo-after-body & echo-before-body
--- config
    location /mixed {
        echo_before_body hello;
        echo_after_body world;
        echo_before_body hiya;
        echo_after_body igor;
        echo ////////;
    }
--- request
    GET /mixed
--- response_body
hello
hiya
////////
world
igor



=== TEST 9: echo around proxy
--- config
    location /echo {
        echo_before_body hello;
        echo_before_body world;
        #echo $scheme://$host:$server_port$request_uri/more;
        proxy_pass $scheme://127.0.0.1:$server_port$request_uri/more;
        echo_after_body hiya;
        echo_after_body igor;
    }
    location /echo/more {
        echo blah;
    }
--- request
    GET /echo
--- response_body
hello
world
blah
hiya
igor



=== TEST 10: with $echo_response_status
--- config
    location /status {
        echo_after_body "status: $echo_response_status";
        return 404;
    }
--- request
    GET /status
--- response_body_like
.*404 Not Found.*
status: 404$
--- error_code: 404



=== TEST 11: in subrequests
--- config
    location /main {
        echo_location_async /hello;
    }
    location /hello {
        echo_after_body 'world!';
        echo 'hello';
    }
--- request
    GET /main
--- response_body
hello
world!



=== TEST 12: echo_after_body + gzip
--- config
    gzip             on;
    gzip_min_length  1;
    location /main {
        echo_after_body 'world!';
        echo_duplicate 1024 'hello';
    }
--- request
    GET /main
--- response_body_like
hello
--- SKIP



=== TEST 13: echo_after_body + proxy output
--- config
    #gzip             on;
    #gzip_min_length  1;
    location /main {
        echo_after_body 'world';
        proxy_pass http://127.0.0.1:$server_port/foo;
    }
    location /foo {
        echo_duplicate 10 hello;
    }
--- request
    GET /main
--- response_body_like
^(?:hello){10}world$



=== TEST 14: in subrequests (we get last_in_chain set properly)
--- config
    location /main {
        echo_location_async /hello;
    }
    location /hello {
        echo 'hello';
        echo_after_body 'world!';
        body_filter_by_lua '
            local eof = ngx.arg[2]
            if eof then
                print("lua: eof found in body")
            end
        ';
    }
--- request
    GET /main
--- response_body
hello
world!
--- log_level: notice
--- error_log
lua: eof found in body